modelForm.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. <style lang="scss" scoped>
  2. .content {
  3. display: flex;
  4. padding: 0;
  5. .content-item {
  6. flex: 1;
  7. padding: 20px;
  8. &.middle {
  9. border-left: 2px solid #d8d8d8;
  10. border-right: 2px solid #d8d8d8;
  11. }
  12. &.right,
  13. &.middle {
  14. flex: 2;
  15. }
  16. .item-title {
  17. font-size: 14px;
  18. font-weight: bold;
  19. color: #666666;
  20. margin-bottom: 20px;
  21. }
  22. .el-row {
  23. margin-top: 20px;
  24. }
  25. .model {
  26. width: 80px;
  27. height: 80px;
  28. display: flex;
  29. flex-direction: column;
  30. align-items: center;
  31. justify-content: space-evenly;
  32. &:hover {
  33. cursor: pointer;
  34. background: #f5faff;
  35. }
  36. img {
  37. height: 28px;
  38. width: 28px;
  39. }
  40. span {
  41. font-size: 14px;
  42. color: #666666;
  43. // margin-top:19px;
  44. }
  45. }
  46. .el-form {
  47. margin-bottom: 20px;
  48. .el-form-item {
  49. background: #f5faff;
  50. padding: 10px 20px;
  51. margin-bottom: 5px;
  52. /deep/.el-form-item__label {
  53. font-size: 16px;
  54. color: #666666;
  55. display: block;
  56. line-height: 20px;
  57. margin-bottom: 10px;
  58. text-align: left;
  59. }
  60. /deep/.el-form-item__content {
  61. margin-right: 160px;
  62. position: relative;
  63. font,
  64. .drag {
  65. position: absolute;
  66. right: -145px;
  67. }
  68. font {
  69. top: 0px;
  70. color: #3895fe;
  71. font-size: 12px;
  72. span {
  73. margin-left: 5px;
  74. cursor: pointer;
  75. }
  76. }
  77. .drag {
  78. right: -160px;
  79. bottom: -3px;
  80. }
  81. div {
  82. font-size: 16px;
  83. color: #333333;
  84. }
  85. .el-radio,
  86. .el-checkbox {
  87. margin-right: 32px;
  88. // height: 32px;
  89. line-height: 20px;
  90. }
  91. .el-radio-group,
  92. .el-checkbox-group {
  93. display: flex;
  94. flex-direction: column;
  95. }
  96. .cus_select .el-radio,
  97. .el-radio__input {
  98. white-space: normal;
  99. }
  100. .cus_select .el-checkbox,
  101. .el-checkbox__input {
  102. white-space: normal;
  103. }
  104. .cus_select .el-checkbox__label {
  105. display: inline;
  106. }
  107. .el-radio__label,
  108. .el-checkbox__label {
  109. display: inline-block !important;
  110. width: 93%;
  111. vertical-align: top;
  112. }
  113. .el-radio,
  114. .el-checkbox {
  115. margin-bottom: 10px;
  116. }
  117. }
  118. /deep/.el-form-item__label {
  119. float: none;
  120. font-weight: bold;
  121. }
  122. &.text {
  123. /deep/.el-form-item__content {
  124. // margin-left:60px;
  125. }
  126. }
  127. }
  128. }
  129. // 右边
  130. .phone {
  131. width: 350px;
  132. height: 713px;
  133. background: url("../../assets/survey_bg.png") no-repeat;
  134. background-size: 100% auto;
  135. margin: auto;
  136. }
  137. .item-main {
  138. height: 551px;
  139. width: 315px;
  140. background: #ffffff;
  141. border: 1px solid #ddd;
  142. overflow: auto;
  143. position: relative;
  144. top: 80px;
  145. left: 21px;
  146. // display: none;
  147. // border: 1px solid #DDDDDD;
  148. // box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.13);
  149. border-radius: 5px;
  150. overflow: auto;
  151. .el-form.over_y {
  152. border: none;
  153. overflow: visible;
  154. }
  155. }
  156. // label样式
  157. .edit_label {
  158. /deep/.el-input__inner {
  159. background: #f5faff;
  160. border: 0px;
  161. padding: 0px;
  162. }
  163. }
  164. /deep/.opicon {
  165. font-weight: bold;
  166. padding: 5px;
  167. color: #3895fe;
  168. }
  169. .tpl_title {
  170. font-size: 18px;
  171. // margin-bottom:20px;
  172. }
  173. .tpl_form {
  174. margin: 0px;
  175. border: 1px solid #ccc;
  176. border-radius: 20px;
  177. /deep/.el-form-item {
  178. background: none;
  179. }
  180. /deep/.el-form-item__content {
  181. width: 100%;
  182. }
  183. }
  184. .survey_logo {
  185. width: 145px;
  186. position: relative;
  187. top: 5px;
  188. left: 20px;
  189. }
  190. .item_require {
  191. position: absolute;
  192. top: 0px;
  193. right: 35px !important;
  194. /deep/.el-checkbox__label {
  195. padding-left: 5px;
  196. // color:red;
  197. }
  198. }
  199. .require::before {
  200. content: "*";
  201. color: #f56c6c;
  202. margin-right: 4px;
  203. position: absolute;
  204. left: -10px;
  205. }
  206. }
  207. /deep/.radio .el-input {
  208. width: 85%;
  209. }
  210. /deep/.checkbox .el-input {
  211. width: 85%;
  212. }
  213. // 操作按钮
  214. .ctl_btn{
  215. display: inline-block;
  216. width: 28px;
  217. position: absolute;
  218. top:13px;
  219. }
  220. .ctl_btn_note{
  221. right: 55px;
  222. color:#ffb800;
  223. }
  224. .ctl_btn_edit{
  225. right: 20px;
  226. color: green;
  227. }
  228. .ctl_btn_del{
  229. right: -15px;
  230. color:red;
  231. }
  232. // 批注弹窗
  233. /deep/.noteDialog .el-form-item__content{
  234. margin-right: 0px!important;
  235. margin-left:0px!important;
  236. }
  237. // /deep/.noteDialog .el-dialog{
  238. // margin-top:20vh!important;
  239. // }
  240. /deep/.noteDialog .el-dialog__body {
  241. padding:10px 20px!important;
  242. }
  243. }
  244. </style>
  245. <template>
  246. <section>
  247. <p><span>信息管理></span>新增模板</p>
  248. <div class="content">
  249. <div class="content-item">
  250. <div class='item-title'>模板组件</div>
  251. <el-row>
  252. <el-col :span='12'>
  253. <div class='model' @click="addWidget(0)">
  254. <img src="../../assets/slt_small.png" alt="">
  255. <span>单行文本</span>
  256. </div>
  257. </el-col>
  258. <el-col :span='12'>
  259. <div class='model' @click="addWidget(1)">
  260. <img src="../../assets/mlt_small.png" alt="">
  261. <span>多行文本</span>
  262. </div>
  263. </el-col>
  264. </el-row>
  265. <el-row>
  266. <el-col :span='12'>
  267. <div class='model' @click="addWidget(2)">
  268. <img src="../../assets/radio_small.png" alt="">
  269. <span>单选统计</span>
  270. </div>
  271. </el-col>
  272. <el-col :span='12'>
  273. <div class='model' @click="addWidget(3)">
  274. <img src="../../assets/checked_small.png" alt="">
  275. <span>多选统计</span>
  276. </div>
  277. </el-col>
  278. </el-row>
  279. <el-row>
  280. <el-col :span='12'>
  281. <div class='model' @click="addWidget(4)">
  282. <img src="../../assets/upload_small.png" alt="">
  283. <span>图片上传</span>
  284. </div>
  285. </el-col>
  286. <!-- <el-col :span='12'>
  287. <div class='model' @click="addWidget(5)">
  288. <img src="../../assets/file_small.png" alt="">
  289. <span>文件上传</span>
  290. </div>
  291. </el-col> -->
  292. <el-col :span='12'>
  293. <div class='model' @click="addWidget(6)">
  294. <img src="../../assets/slt_small.png" alt="">
  295. <span>域组件</span>
  296. </div>
  297. </el-col>
  298. </el-row>
  299. </div>
  300. <div class="content-item middle">
  301. <div class='item-title'>编辑模板-{{title}}</div>
  302. <el-form size="small" label-width="" label-position="top" class='over_y'>
  303. <!-- handle=".dargBtn" 触发拖拽事件的按钮类名 filter=".undraggable" 不可拖拽的元素的类名 -->
  304. <vuedraggable class="wrapper" v-model="widgetList" handle=".dargBtn">
  305. <transition-group>
  306. <el-form-item v-for="(item,index) in widgetList" :key="index" :prop="item.label">
  307. <section v-if="item.type=='input'">
  308. <el-input :readonly="item.edit" v-model="item.label" :class="[item.edit?'edit_label':'',item.require?'require':'']"></el-input>
  309. <el-input placeholder='请输入' v-model="item.placeholder"></el-input>
  310. <font>
  311. <el-checkbox class="item_require" v-model="item.require">必填</el-checkbox>
  312. <span class="ctl_btn ctl_btn_note" @click="addNote(item)">批注</span>
  313. <span class="ctl_btn ctl_btn_edit" @click="item.edit=!item.edit">{{item.edit?'编辑':'保存'}}</span>
  314. <span class="ctl_btn ctl_btn_del" @click="widgetList.splice(index,1)">删除</span>
  315. </font>
  316. <el-button type='primary' class='dargBtn drag' size="mini">拖拽移动顺序</el-button>
  317. </section>
  318. <section v-if="item.type=='textarea'">
  319. <el-input :readonly="item.edit" v-model="item.label" :class="[item.edit?'edit_label':'',item.require?'require':'']"></el-input>
  320. <el-input type="textarea" placeholder='请输入' v-model="item.placeholder"></el-input>
  321. <font>
  322. <el-checkbox class="item_require" v-model="item.require">必填</el-checkbox>
  323. <span @click="item.edit=!item.edit">{{item.edit?'编辑':'保存'}}</span>
  324. <span @click="widgetList.splice(index,1)">删除</span>
  325. </font>
  326. <el-button type='primary' class='dargBtn drag' size="mini">拖拽移动顺序</el-button>
  327. </section>
  328. <section v-if="item.type=='radio'" class="radio">
  329. <el-input :readonly="item.edit" v-model="item.label" :class="[item.edit?'edit_label':'',item.require?'require':'']"></el-input>(单选)
  330. <el-radio-group>
  331. <el-radio :label="iitem.label" v-for="(iitem,index) in item.items" :key="index">
  332. <el-input :readonly="item.edit" v-model="iitem.label" :class="item.edit?'edit_label':''"></el-input>
  333. <template v-if="!item.edit">
  334. <i class="el-icon-minus opicon" @click="minusOption(item.items,index)"></i><i class="el-icon-plus opicon" @click="plusOption(item.items,index)"></i>
  335. </template>
  336. </el-radio>
  337. </el-radio-group>
  338. <font>
  339. <el-checkbox class="item_require" v-model="item.require">必填</el-checkbox>
  340. <span @click="item.edit=!item.edit">{{item.edit?'编辑':'保存'}}</span>
  341. <span @click="widgetList.splice(index,1)">删除</span>
  342. </font>
  343. <el-button type='primary' class='dargBtn drag' size="mini">拖拽移动顺序</el-button>
  344. </section>
  345. <section v-if="item.type=='checkbox'" class="checkbox">
  346. <el-input :readonly="item.edit" v-model="item.label" :class="[item.edit?'edit_label':'',item.require?'require':'']"></el-input>(多选)
  347. <el-radio-group>
  348. <el-checkbox :label="iitem.label" v-for="(iitem,index) in item.items" :key="index">
  349. <el-input :readonly="item.edit" v-model="iitem.label" :class="item.edit?'edit_label':''"></el-input>
  350. <template v-if="!item.edit">
  351. <i class="el-icon-minus opicon" @click="minusOption(item.items,index)"></i><i class="el-icon-plus opicon" @click="plusOption(item.items,index)"></i>
  352. </template>
  353. </el-checkbox>
  354. </el-radio-group>
  355. <font>
  356. <el-checkbox class="item_require" v-model="item.require">必填</el-checkbox>
  357. <span @click="item.edit=!item.edit">{{item.edit?'编辑':'保存'}}</span>
  358. <span @click="widgetList.splice(index,1)">删除</span>
  359. </font>
  360. <el-button type='primary' class='dargBtn drag' size="mini">拖拽移动顺序</el-button>
  361. </section>
  362. <section v-if="item.type=='image'">
  363. <!-- <el-input :readonly="item.edit" v-model="item.label" :class="item.edit?'edit_label':''"></el-input> -->
  364. <el-input :readonly="item.edit" v-model="item.label" :class="[item.edit?'edit_label':'',item.require?'require':'']"></el-input>
  365. <el-upload
  366. action="/api/admin/uploadfile"
  367. list-type="picture-card"
  368. :on-preview="handlePreview"
  369. :on-remove="handleRemove">
  370. <i class="el-icon-plus"></i>
  371. </el-upload>
  372. <font>
  373. <el-checkbox class="item_require" v-model="item.require">必填</el-checkbox>
  374. <span @click="item.edit=!item.edit">{{item.edit?'编辑':'保存'}}</span>
  375. <span @click="widgetList.splice(index,1)">删除</span>
  376. </font>
  377. <el-button type='primary' class='dargBtn drag' size="mini">拖拽移动顺序</el-button>
  378. </section>
  379. <section v-if="item.type=='file'">
  380. <el-input :readonly="item.edit" v-model="item.label" :class="item.edit?'edit_label':''"></el-input>
  381. <el-upload
  382. class="upload-demo"
  383. ref="upload"
  384. action="/api/admin/uploadfile"
  385. :on-preview="handlePreview"
  386. :on-remove="handleRemove"
  387. :file-list="fileList"
  388. :auto-upload="false">
  389. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  390. <el-button style="margin-left: 10px;" size="small" type="primary" plain @click="submitUpload">添加文件</el-button>
  391. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  392. </el-upload>
  393. <font>
  394. <span @click="item.edit=!item.edit">{{item.edit?'编辑':'保存'}}</span>
  395. <span @click="widgetList.splice(index,1)">删除</span>
  396. </font>
  397. <el-button type='primary' class='dargBtn drag' size="mini">拖拽移动顺序</el-button>
  398. </section>
  399. </el-form-item>
  400. </transition-group>
  401. </vuedraggable>
  402. <div v-if="this.widgetList.length">
  403. <el-button size="medium" type="primary" @click="save">保存</el-button>
  404. </div>
  405. </el-form>
  406. <!-- 添加批注 -->
  407. <el-dialog
  408. class="noteDialog"
  409. :title="dialogTitle"
  410. :close-on-click-modal="false"
  411. :visible.sync="dialogVisible"
  412. >
  413. <fuEditor :value="curNote" ref="editor"></fuEditor>
  414. <span slot="footer" class="dialog-footer">
  415. <el-button size="small" type="normal" @click="dialogVisible=false,noteForm={},curNote='<p></p>'">取消</el-button>
  416. <el-button size="small" type="primary" @click="saveNote(curItem)">确 定</el-button>
  417. </span>
  418. </el-dialog>
  419. </div>
  420. <div class="content-item right">
  421. <div class='item-title'>效果预览</div>
  422. <div class="phone">
  423. <div class='item-main'>
  424. <!-- <img src="../../assets/survey_logo.png" alt="" class="survey_logo"> -->
  425. <h5 align='center' class="tpl_title">{{title}}</h5>
  426. <el-form ref="form" :model="form" class="tpl_form over_y">
  427. <template v-for="(item,index) in widgetList">
  428. <el-form-item :key="index" :label="item.label+item.cntype">
  429. <el-input :class="item.require?'require':''" v-if="item.type=='input'" v-model="form.label" :placeholder="item.placeholder"></el-input>
  430. <el-input :class="item.require?'require':''" v-if="item.type=='textarea'" type="textarea" v-model="form.label" :placeholder="item.placeholder"></el-input>
  431. <el-radio-group class="cus_select" v-if="item.type=='radio'" :class="item.require?'require':''">
  432. <el-radio :label="iitem.label" v-for="(iitem,index) in item.items" :key="index">{{iitem.label}}</el-radio>
  433. </el-radio-group>
  434. <el-radio-group class="cus_select" v-if="item.type=='checkbox'" :class="item.require?'require':''">
  435. <el-checkbox :label="iitem.label" v-for="(iitem,index) in item.items" :key="index">{{iitem.label}}</el-checkbox>
  436. </el-radio-group>
  437. <el-upload
  438. :class="item.require?'require':''"
  439. v-if="item.type=='image'"
  440. action="/api/admin/uploadfile"
  441. list-type="picture-card"
  442. :on-preview="handlePreview"
  443. :on-remove="handleRemove">
  444. <i class="el-icon-plus"></i>
  445. </el-upload>
  446. <el-upload
  447. v-if="item.type=='file'"
  448. class="upload-demo"
  449. ref="upload"
  450. action="/api/admin/uploadfile"
  451. :on-preview="handlePreview"
  452. :on-remove="handleRemove"
  453. :file-list="fileList"
  454. :auto-upload="false">
  455. <!-- <el-button slot="trigger" size="small" type="primary">选取文件</el-button> -->
  456. <el-button style="margin-left: 10px;" size="small" type="primary" plain @click="submitUpload">添加文件</el-button>
  457. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  458. </el-upload>
  459. </el-form-item>
  460. </template>
  461. <el-form-item v-if="this.widgetList.length">
  462. <el-button size="medium" type="primary" @click="dialogVisible = false" style="width:100%;margin-top:20px;">提交</el-button>
  463. </el-form-item>
  464. </el-form>
  465. </div>
  466. </div>
  467. </div>
  468. </div>
  469. </section>
  470. </template>
  471. <script>
  472. import vuedraggable from "vuedraggable";
  473. import fuEditor from "../../components/fuEditor";
  474. export default {
  475. components: { vuedraggable,fuEditor },
  476. data() {
  477. return {
  478. curItem:{},
  479. dialogTitle:"",
  480. noteForm:{},
  481. curNote:"",
  482. dialogVisible:false,
  483. rules: {
  484. 姓名: [{ required: true, message: "请输入标题", trigger: "blur" }],
  485. },
  486. title: this.$route.query.title,
  487. edit: 0,
  488. form: { name: "", page: 1, page_size: 20 },
  489. total: 1,
  490. list: [{ name: "2333" }],
  491. loading: false,
  492. checkList: [],
  493. input: "",
  494. dialogVisible: false,
  495. defaultProps: {},
  496. data: [
  497. {
  498. id: 1,
  499. label: "一级 1",
  500. },
  501. {
  502. id: 2,
  503. label: "一级 2",
  504. children: [
  505. {
  506. id: 5,
  507. label: "二级 2-1",
  508. },
  509. {
  510. id: 6,
  511. label: "二级 2-2",
  512. },
  513. ],
  514. },
  515. ],
  516. stdWidgetList: [
  517. {
  518. type: "input",
  519. cntype:"",
  520. label: "请输入标题",
  521. placeholder: "请输入",
  522. edit: false,
  523. require:true
  524. },
  525. {
  526. type: "textarea",
  527. cntype:"",
  528. label: "请输入标题",
  529. placeholder: "请输入",
  530. edit: false,
  531. require:true
  532. },
  533. {
  534. type: "radio",
  535. cntype:"(单选)",
  536. label: "请输入标题",
  537. placeholder: "请输入",
  538. edit: false,
  539. require:true,
  540. items: [
  541. { label: "选项", value: "选项值" },
  542. { label: "选项1", value: "选项值" },
  543. ],
  544. },
  545. {
  546. type: "checkbox",
  547. cntype:"(多选)",
  548. label: "请输入标题",
  549. placeholder: "请输入",
  550. edit: false,
  551. require:true,
  552. items: [
  553. { label: "选项", value: "选项值" },
  554. { label: "选项1", value: "选项值" },
  555. ],
  556. },
  557. {
  558. type: "image",
  559. cntype:"",
  560. label: "请输入标题",
  561. placeholder: "请输入",
  562. edit: true,
  563. },
  564. {
  565. type: "file",
  566. label: "请输入标题",
  567. placeholder: "请输入",
  568. edit: true,
  569. },
  570. ],
  571. widgetList: [],
  572. };
  573. },
  574. methods: {
  575. upload(){
  576. },
  577. addNote(item){
  578. this.curItem = item;
  579. this.curNote = item.note?item.note:'';
  580. // this.$refs.editor.html(this.curNote)
  581. this.dialogTitle = "为"+'"'+item.label+'"添加批注信息'
  582. this.dialogVisible = true;
  583. },
  584. saveNote(item){
  585. this.curNote=this.$refs.editor.getEditor()
  586. item.note = this.curNote;
  587. this.dialogVisible = false;
  588. },
  589. handlePreview(){
  590. },
  591. handleRemove(){
  592. },
  593. unique(arr) {
  594. var x = new Set(arr);
  595. return [...x];
  596. },
  597. save() {
  598. let id = this.$route.query.id;
  599. let copyid = this.$route.query.copyid;
  600. let widgets = Array.from(this.widgetList);
  601. let flag = 0;
  602. let labels = [];
  603. widgets.forEach((item, index) => {
  604. labels.push(item.label);
  605. });
  606. if (labels.length != this.unique(labels).length) {
  607. flag = 1;
  608. this.$alert("题干不能相同请仔细检查数据!", "数据错误", {
  609. confirmButtonText: "确定",
  610. type: "error",
  611. });
  612. return false;
  613. }
  614. widgets.forEach((item, index) => {
  615. if (item.label == "") {
  616. flag = 2;
  617. }
  618. if (item.type == "radio" || item.type == "checkbox") {
  619. let item_labels = [];
  620. item.items.forEach((obj, index) => {
  621. item_labels.push(obj.label);
  622. });
  623. if (item_labels.length != this.unique(item_labels).length) {
  624. flag = 3;
  625. }
  626. }
  627. });
  628. if (flag == 2) {
  629. this.$alert("题干不能为空请仔细检查数据!", "数据错误", {
  630. confirmButtonText: "确定",
  631. type: "error",
  632. });
  633. return false;
  634. }
  635. if (flag == 3) {
  636. this.$alert("选择题选项不能相同请仔细检查数据!", "数据错误", {
  637. confirmButtonText: "确定",
  638. type: "error",
  639. });
  640. return false;
  641. }
  642. let params = {
  643. name: this.title,
  644. widget: JSON.stringify(widgets),
  645. };
  646. console.log(widgets, 22222222222);
  647. if (id && !copyid) {
  648. params.id = id;
  649. this.$api.editTemplate(params).then((res) => {
  650. if (res.data.code == 0) {
  651. this.$message({
  652. type: "success",
  653. message: "成功!",
  654. });
  655. } else {
  656. this.$message.error("失败!");
  657. }
  658. this.$router.push("/message/template");
  659. });
  660. } else {
  661. this.$api.addTemplate(params).then((res) => {
  662. if (res.data.code == 0) {
  663. this.$message({
  664. type: "success",
  665. message: "成功!",
  666. });
  667. } else {
  668. this.$message.error("失败!");
  669. }
  670. this.$router.push("/message/template");
  671. });
  672. }
  673. },
  674. addWidget(i) {
  675. console.log(i);
  676. this.widgetList.push(JSON.parse(JSON.stringify(this.stdWidgetList[i])));
  677. console.log(this.widgetList);
  678. },
  679. minusOption(options, index) {
  680. if (options.length <= 1) {
  681. this.$message.error("选项不能少于1个!");
  682. } else {
  683. options.splice(index, 1);
  684. }
  685. },
  686. plusOption(options, index) {
  687. if (options.length >= 100) {
  688. this.$message.error("选项不能超过100个!");
  689. } else {
  690. options.splice(index + 1, 0, {
  691. label: "选项" + (index + 1),
  692. value: "选项值",
  693. });
  694. }
  695. },
  696. gopage(size) {
  697. if (size) {
  698. this.form.page_size = size;
  699. }
  700. this.form.page = this.$refs.pageButton.page;
  701. this.getData();
  702. },
  703. handleSelectionChange(val) {
  704. this.multipleSelection = val;
  705. },
  706. gopage1(size) {
  707. if (size) {
  708. this.form1.page_size = size;
  709. }
  710. this.form1.page = this.$refs.pageButton1.page;
  711. this.getJl();
  712. },
  713. open(data) {
  714. this.dialogFormVisible = true;
  715. this.message = { ...data };
  716. },
  717. download() {
  718. let array = this.multipleSelection,
  719. ids = [];
  720. for (let i = 0; i < array.length; i++) {
  721. ids.push(array[i].id);
  722. }
  723. ids = ids.join(",");
  724. this.$api.downloadMon({ ids: ids }).then((res) => {
  725. var elink = document.createElement("a");
  726. let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
  727. let objUrl = URL.createObjectURL(blob);
  728. console.log(res.headers["content-disposition"]);
  729. let file_name = res.headers["content-disposition"].split("=")[1];
  730. elink.download = file_name;
  731. elink.style.display = "none";
  732. elink.href = objUrl;
  733. document.body.appendChild(elink);
  734. elink.click();
  735. document.body.removeChild(elink);
  736. });
  737. },
  738. prview(id) {
  739. this.form1.enterprise_id = id;
  740. this.getJl();
  741. this.dialogFormVisible1 = true;
  742. },
  743. getJl() {
  744. var parm = this.form1;
  745. this.$api.getMonitjobList(parm).then((res) => {
  746. this.data = res.data.data.list;
  747. this.total1 = res.data.data.total;
  748. });
  749. },
  750. detail(id) {
  751. this.$router.push({
  752. path: "/company/detail",
  753. query: { id: id, page: this.form.page, page_size: this.form.page_size },
  754. });
  755. },
  756. getData() {
  757. let id = this.$route.query.id;
  758. if (id) {
  759. this.$api.getTemplate({ id: id }).then((res) => {
  760. if (res.data.code == 0) {
  761. this.widgetList = res.data.data.widget;
  762. }
  763. });
  764. }
  765. },
  766. del(id) {
  767. this.$confirm("确定删除吗?", "提示", {
  768. type: "warning",
  769. }).then(() => {
  770. this.$api.deleteEnterprise({ id: id }).then((res) => {
  771. this.$message({
  772. message: "删除成功",
  773. type: "success",
  774. });
  775. this.getData();
  776. });
  777. });
  778. },
  779. permission(name) {
  780. let permissions = this.info.permissions || [];
  781. let list = [];
  782. for (let i = 0; i < permissions.length; i++) {
  783. list.push(permissions[i].name);
  784. }
  785. if (list.indexOf(name) < 0) {
  786. return false;
  787. } else {
  788. return true;
  789. }
  790. },
  791. },
  792. created() {
  793. this.getData();
  794. },
  795. };
  796. </script>