TemplateMaintenanceWrap.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div class="NoiseTemplateWrapper TemplateWrapper">
  3. <crumbs
  4. :title="txt"
  5. class="topBack"
  6. :param="$route.params"
  7. linkTo="TemplateMaintenance"
  8. ></crumbs>
  9. <PubTemplateGroup
  10. :editData="editData"
  11. @changeVal="changeVal"
  12. @validatePass="validatePass"
  13. @staticOwn="staticOwn"
  14. ref="submitForm"
  15. ></PubTemplateGroup>
  16. <div class="main">
  17. <CommonTemplate
  18. v-if="dataPub.region1"
  19. :pool="dataPub.tagPool"
  20. :type="dataPub.region1"
  21. :signe="dataPub.region3"
  22. :copyed="dataPub.isCopy"
  23. :rela="dataPub.region4"
  24. :options="editData"
  25. @changeActionData="changeActionData"
  26. >
  27. </CommonTemplate>
  28. <div class="btn">
  29. <el-button
  30. type="primary"
  31. :disabled="(dataPub.isCopy && staticOwnTo == dataPub.region4) || saveDisable"
  32. :plain="dataPub.isCopy && staticOwnTo == dataPub.region4"
  33. @click="submitForm"
  34. >确 定</el-button>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. /**
  41. * dataPub.region2 判断底部显示哪些
  42. */
  43. import PubTemplateGroup from './PubTemplateGroup';
  44. import CommonTemplate from './CommonTemplate';
  45. import api from '@api/icss.js';
  46. import utils from '@api/utils.js';
  47. export default {
  48. name: 'TemplateMaintenanceWrap',
  49. data() {
  50. return {
  51. txt:'模板维护-添加模板',
  52. dataPub: {}, //公用组件传的值都在这
  53. editData:{}, //编辑数据
  54. sendIds: [], //标签明细右侧操作数据
  55. staticOwnTo:'',
  56. saveDisable: false //保存按钮禁止点击
  57. }
  58. },
  59. beforeMount:function(){
  60. const {isEdit,data} = this.$route.params;
  61. if(isEdit){
  62. this.txt = '模板维护-修改模板';
  63. this.editData = data;
  64. // console.log('回读数据', this.editData)
  65. }
  66. },
  67. methods: {
  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. //返回带搜索条件的首页
  154. setTimeout(() => {
  155. this.$router.push({
  156. name: 'TemplateMaintenance',
  157. params: Object.assign({}, this.$route.params, {currentPage: 1})
  158. })
  159. }, 1000);
  160. } else {
  161. this.warning(res.data.msg)
  162. }
  163. this.saveDisable = true
  164. }).catch((err) => {
  165. this.warning(err);
  166. })
  167. }else{
  168. api.saveModuleInfo(param).then((res) => {
  169. if (res.data.code === '0') {
  170. this.warning(res.data.msg || '保存成功', 'success','1000')
  171. setTimeout(() => {
  172. this.$router.push({
  173. path:'/admin/LT-YXSJWH-MBWH'
  174. })
  175. }, 1000);
  176. } else {
  177. this.warning(res.data.msg)
  178. }
  179. }).catch((err) => {
  180. this.warning(err);
  181. })
  182. }
  183. });
  184. },
  185. showConfirmDialog(msg, resolve) {
  186. this.$alert(msg, '提示', {
  187. confirmButtonText: '确定',
  188. type: 'warning'
  189. }).then(() => {
  190. resolve();
  191. }).catch(() => {});
  192. },
  193. warning(msg, type,time) {
  194. this.$message({
  195. showClose: true,
  196. message: msg,
  197. type: type || 'warning',
  198. duration:time || '3000'
  199. })
  200. },
  201. },
  202. components: {
  203. PubTemplateGroup,
  204. CommonTemplate,
  205. }
  206. }
  207. </script>
  208. <style lang="less">
  209. @import "../../less/common.less";
  210. .NoiseTemplateWrapper {
  211. .groupTitle {
  212. background-color: #fff;
  213. height: 40px;
  214. line-height: 40px;
  215. padding-left: 20px;
  216. }
  217. .main {
  218. background-color: #fff;
  219. margin: 0 20px 20px;
  220. padding: 20px;
  221. border-top: 1px solid @icssBorder;
  222. box-sizing: border-box;
  223. font-size: 14px;
  224. color: #606266;
  225. .title {
  226. margin-bottom: 20px;
  227. i {
  228. color: #f56c6c;
  229. }
  230. }
  231. }
  232. .btn {
  233. text-align: right;
  234. }
  235. .order {
  236. margin-bottom: 20px;
  237. .el-input__inner {
  238. line-height: 30px;
  239. height: 30px;
  240. }
  241. }
  242. }
  243. </style>