TemplateMaintenanceWrap.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div class="NoiseTemplateWrapper TemplateWrapper">
  3. <crumbs
  4. :title="txt"
  5. class="topBack"
  6. linkTo="TemplateMaintenance"
  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) || saveDisable"
  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. saveDisable: false //保存按钮禁止点击
  56. }
  57. },
  58. beforeMount:function(){
  59. const {isEdit,data} = this.$route.params;
  60. if(isEdit){
  61. this.txt = '模板维护-修改模板';
  62. this.editData = data;
  63. // console.log('回读数据', this.editData)
  64. }
  65. },
  66. methods: {
  67. back() { this.$router.go(-1) },
  68. staticOwn(val){
  69. this.staticOwnTo = val
  70. },
  71. changeVal(val) { //子组件数据改变传递到父组件
  72. this.dataPub = val // console.log('公用组件传的值都在这', val)
  73. if(val.isCopy){
  74. this.txt = '模板维护-复制模板'
  75. }
  76. },
  77. changeActionData(arr) { //标签明细右侧数据id
  78. this.sendIds = arr
  79. },
  80. submitForm() { // 调用子组件的方法验证公用部分
  81. this.$refs.submitForm.submitForm('groups');
  82. },
  83. validatePass() { //验证成功回调,调取接口
  84. //仍需验证标签明细是否选择
  85. let type = this.dataPub.region1,name=this.dataPub.region2;
  86. let detailLis = utils.orderTemplateData(this.sendIds)
  87. if (JSON.stringify(this.sendIds) == '[]' || !detailLis) {
  88. this.$message({
  89. message: '模板至少包含一个标签池标签',
  90. type: 'warning'
  91. });
  92. return;
  93. }else if(detailLis[0].questionId == '' && detailLis.length == 1){
  94. let msg = ''
  95. if(detailLis[0].flag == 3){
  96. msg = '保存模版时,无法保存单独的子模板'
  97. }else{
  98. msg = '保存模版时,无法保存单独的输入栏'
  99. }
  100. this.$message({
  101. message: msg,
  102. type: 'warning'
  103. });
  104. return;
  105. }else if(detailLis.length == 2 && ((detailLis[0].questionId == '' && detailLis[1].flag == 3) || (detailLis[1].questionId == '' && detailLis[0].flag == 3))){
  106. this.$message({
  107. message: '保存模版时,只有输入栏和子模板无法保存',
  108. type: 'warning'
  109. });
  110. return;
  111. }
  112. // let numplus = 0;
  113. // for(let k = 0;k < detailLis.length;k++){
  114. // if((detailLis[k].flag && detailLis[k].flag != 3) || (type == 322 || type == 32 || type == 31)){
  115. // ++numplus
  116. // }
  117. // }
  118. // if(numplus == 0){
  119. // this.$message({
  120. // message: '除子模板外,其他模板内容中至少给一个标签打上标记',
  121. // type: 'warning'
  122. // });
  123. // return;
  124. // }
  125. function getTextType(){
  126. if(type == 322 || type == 22 || type == 32){
  127. return 2
  128. }else if(type == 31){
  129. return 1
  130. }
  131. return type
  132. }
  133. let param = {
  134. "modelDetils": detailLis,
  135. "name": name,
  136. "type": type,
  137. "flag": (type == 322 || type == 32 || type == 31)?3:'',
  138. "textType": getTextType(),
  139. "id":this.editData.id || '',
  140. "moduleType": this.dataPub.region3,
  141. "relationId": this.dataPub.region4
  142. }
  143. // console.log(param,'保存模板的参数')
  144. this.showDelDialog(param)
  145. },
  146. showDelDialog(param) {
  147. this.showConfirmDialog('是否保存该模板?', () => {
  148. if(this.editData.id){
  149. this.saveDisable = false //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  150. api.updateModuleInfo(param).then((res) => {
  151. if (res.data.code === '0') {
  152. this.warning(res.data.msg || '修改成功', 'success','1000')
  153. setTimeout(() => {
  154. this.$router.push({
  155. path:'/admin/LT-YXSJWH-MBWH'
  156. })
  157. }, 1000);
  158. } else {
  159. this.warning(res.data.msg)
  160. }
  161. this.saveDisable = true
  162. }).catch((err) => {
  163. this.warning(err);
  164. })
  165. }else{
  166. api.saveModuleInfo(param).then((res) => {
  167. if (res.data.code === '0') {
  168. this.warning(res.data.msg || '保存成功', 'success','1000')
  169. setTimeout(() => {
  170. this.$router.push({
  171. path:'/admin/LT-YXSJWH-MBWH'
  172. })
  173. }, 1000);
  174. } else {
  175. this.warning(res.data.msg)
  176. }
  177. }).catch((err) => {
  178. this.warning(err);
  179. })
  180. }
  181. });
  182. },
  183. showConfirmDialog(msg, resolve) {
  184. this.$alert(msg, '提示', {
  185. confirmButtonText: '确定',
  186. type: 'warning'
  187. }).then(() => {
  188. resolve();
  189. }).catch(() => {});
  190. },
  191. warning(msg, type,time) {
  192. this.$message({
  193. showClose: true,
  194. message: msg,
  195. type: type || 'warning',
  196. duration:time || '3000'
  197. })
  198. },
  199. },
  200. components: {
  201. PubTemplateGroup,
  202. CommonTemplate,
  203. }
  204. }
  205. </script>
  206. <style lang="less">
  207. @import "../../less/common.less";
  208. .NoiseTemplateWrapper {
  209. .groupTitle {
  210. background-color: #fff;
  211. height: 40px;
  212. line-height: 40px;
  213. padding-left: 20px;
  214. }
  215. .main {
  216. background-color: #fff;
  217. margin: 0 20px 20px;
  218. padding: 20px;
  219. border-top: 1px solid @icssBorder;
  220. box-sizing: border-box;
  221. font-size: 14px;
  222. color: #606266;
  223. .title {
  224. margin-bottom: 20px;
  225. i {
  226. color: #f56c6c;
  227. }
  228. }
  229. }
  230. .btn {
  231. text-align: right;
  232. }
  233. .order {
  234. margin-bottom: 20px;
  235. .el-input__inner {
  236. line-height: 30px;
  237. height: 30px;
  238. }
  239. }
  240. }
  241. </style>