TemplateMaintenanceWrap.vue 6.0 KB

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