TemplateMaintenanceWrap.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div class="NoiseTemplateWrapper TemplateWrapper">
  3. <div class="groupTitle"><i
  4. class="el-icon-back"
  5. @click="back"
  6. ></i> {{txt}}</div>
  7. <PubTemplateGroup
  8. :editData="editData"
  9. @changeVal="changeVal"
  10. @validatePass="validatePass"
  11. ref="submitForm"
  12. ></PubTemplateGroup>
  13. <div class="main">
  14. <CommonTemplate
  15. v-if="dataPub.region1"
  16. :pool="dataPub.tagPool"
  17. :type="dataPub.region1"
  18. :sign="dataPub.region3"
  19. :options="editData"
  20. @changeActionData="changeActionData"
  21. >
  22. </CommonTemplate>
  23. <div class="btn">
  24. <el-button
  25. type="primary"
  26. @click="submitForm"
  27. >确 定</el-button>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. /**
  34. * dataPub.region2 判断底部显示哪些
  35. */
  36. import PubTemplateGroup from './PubTemplateGroup';
  37. import CommonTemplate from './CommonTemplate';
  38. import api from '@api/icss.js';
  39. import utils from '@api/utils.js';
  40. export default {
  41. name: 'TemplateMaintenanceWrap',
  42. data() {
  43. return {
  44. txt:'模板维护--添加模板',
  45. dataPub: {}, //公用组件传的值都在这
  46. editData:{}, //编辑数据
  47. sendIds: [], //标签明细右侧操作数据
  48. }
  49. },
  50. beforeMount:function(){
  51. const {isEdit,data} = this.$route.params;
  52. if(isEdit){
  53. this.txt = '模板维护--修改模板';
  54. this.editData = data;
  55. // console.log('回读数据', this.editData)
  56. }
  57. },
  58. methods: {
  59. back() { this.$router.go(-1) },
  60. changeVal(val) { //子组件数据改变传递到父组件
  61. this.dataPub = val // console.log('公用组件传的值都在这', val)
  62. },
  63. changeActionData(arr) { //标签明细右侧数据id
  64. this.sendIds = arr
  65. },
  66. submitForm() { // 调用子组件的方法验证公用部分
  67. this.$refs.submitForm.submitForm('groups');
  68. },
  69. validatePass() { //验证成功回调,调取接口
  70. //仍需验证标签明细是否选择
  71. let type = this.dataPub.region1,name=this.dataPub.region2;
  72. let detailLis = utils.orderTemplateData(this.sendIds)
  73. // console.log(detailLis.text == '' , detailLis.questionId == '')
  74. if (JSON.stringify(this.sendIds) == '[]' || !detailLis) {
  75. this.$message({
  76. message: '模板至少包含一个标签池标签',
  77. type: 'warning'
  78. });
  79. return;
  80. }else if(detailLis[0].text == '' && detailLis[0].questionId == ''){
  81. this.$message({
  82. message: '保存模版时,无法保存单独的输入栏',
  83. type: 'warning'
  84. });
  85. return;
  86. }
  87. let param = {
  88. "modelDetils": detailLis,
  89. "name": name,
  90. "type": type,
  91. "flag": type == 5?3:'',
  92. "textType": type,
  93. "id":this.editData.id || ''
  94. }
  95. // console.log(param,'保存模板的参数')
  96. this.showDelDialog(param)
  97. },
  98. showDelDialog(param) {
  99. this.showConfirmDialog('是否保存该模板?', () => {
  100. if(this.editData.id){
  101. api.updateModuleInfo(param).then((res) => {
  102. if (res.data.code === '0') {
  103. this.warning(res.data.msg || '修改成功', 'success','1000')
  104. setTimeout(() => {
  105. this.$router.push({
  106. path:'/admin/LT-YXSJWH-MBWH'
  107. })
  108. }, 1000);
  109. } else {
  110. this.warning(res.data.msg)
  111. }
  112. }).catch((err) => {
  113. this.warning(err);
  114. })
  115. }else{
  116. api.saveModuleInfo(param).then((res) => {
  117. if (res.data.code === '0') {
  118. this.warning(res.data.msg || '保存成功', 'success','1000')
  119. setTimeout(() => {
  120. this.$router.push({
  121. path:'/admin/LT-YXSJWH-MBWH'
  122. })
  123. }, 1000);
  124. } else {
  125. this.warning(res.data.msg)
  126. }
  127. }).catch((err) => {
  128. this.warning(err);
  129. })
  130. }
  131. });
  132. },
  133. showConfirmDialog(msg, resolve) {
  134. this.$alert(msg, '提示', {
  135. confirmButtonText: '确定',
  136. type: 'warning'
  137. }).then(() => {
  138. resolve();
  139. }).catch(() => {});
  140. },
  141. warning(msg, type,time) {
  142. this.$message({
  143. showClose: true,
  144. message: msg,
  145. type: type || 'warning',
  146. duration:time || '3000'
  147. })
  148. },
  149. },
  150. components: {
  151. PubTemplateGroup,
  152. CommonTemplate,
  153. }
  154. }
  155. </script>
  156. <style lang="less">
  157. @import "../../less/common.less";
  158. .NoiseTemplateWrapper {
  159. .groupTitle {
  160. background-color: #fff;
  161. height: 40px;
  162. line-height: 40px;
  163. padding-left: 20px;
  164. }
  165. .main {
  166. background-color: #fff;
  167. margin: 0 20px 20px;
  168. padding: 20px;
  169. border-top: 1px solid @icssBorder;
  170. box-sizing: border-box;
  171. font-size: 14px;
  172. color: #606266;
  173. .title {
  174. margin-bottom: 20px;
  175. i {
  176. color: #f56c6c;
  177. }
  178. }
  179. }
  180. .btn {
  181. text-align: right;
  182. }
  183. .order {
  184. margin-bottom: 20px;
  185. .el-input__inner {
  186. line-height: 30px;
  187. height: 30px;
  188. }
  189. }
  190. }
  191. </style>