creatingSituations.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="creatingSituations">
  3. <check-map-detail v-if="showCheckMapDetail"></check-map-detail>
  4. <view v-else class="page-wrap"
  5. :style="{paddingBottom: stepActive !== 0 ? '75rpx' : 0}">
  6. <tm-steps :options="options" :active="stepActive"></tm-steps>
  7. <tm-simple-btn-group v-if="stepActive !== 0"
  8. :options="botmBtnGroup"
  9. v-on:callback="changeStep"></tm-simple-btn-group>
  10. </view>
  11. <check-map-add v-if="showCheckMapAdd"></check-map-add>
  12. </view>
  13. </template>
  14. <script>
  15. import { mapState } from "vuex";
  16. import theme from "./components/theme.vue";
  17. import condition from "./components/condition.vue";
  18. import checkRent from "./components/checkRent.vue";
  19. import checkMap from "./components/checkMap.vue";
  20. import checkMapDetail from "./components/checkMapDetail.vue";
  21. import checkMapAdd from "./components/checkMapAdd.vue";
  22. import checkPlan from "./components/checkPlan.vue";
  23. import situationPreview from "./components/situationPreview.vue";
  24. import {
  25. themeList,
  26. normalBtnGroup,
  27. btnGroupPlan1,
  28. btnGroupPlan2,
  29. btnGroupSituationPreview,
  30. optionsHandle,
  31. checkDep,
  32. checkGroup,
  33. editCondition,
  34. editCheckRent,
  35. editCheckMap,
  36. editCheckPlan,
  37. editSituationPreview
  38. } from "./components/utils.js";
  39. export default {
  40. data() {
  41. return {
  42. saveType: 'POST',
  43. editID: '',
  44. options: [
  45. {id: 'theme', title: '主题', component: theme},
  46. {id: 'condition', title: '条件', component: condition, hint: '追踪条件'},
  47. {id: 'checkRent', title: '查核组', component: checkRent, hint: '查核组'},
  48. {id: 'checkMap', title: '地图', component: checkMap, hint: '地图'},
  49. {id: 'checkPlan', title: '计划', component: checkPlan, hint: '制定计划'},
  50. {id: 'situationPreview', title: '预览', component: situationPreview},
  51. ]
  52. }
  53. },
  54. computed: {
  55. ...mapState({
  56. showCheckMapDetail: state => state.creatingSituations.showCheckMapDetail,
  57. showCheckMapAdd: state => state.creatingSituations.showCheckMapAdd,
  58. showCheckPlan1: state => state.creatingSituations.showCheckPlan1,
  59. stepActive: state => state.creatingSituations.stepActive,
  60. theme: state => state.creatingSituations.theme,
  61. condition: state => state.creatingSituations.condition,
  62. checkRent: state => state.creatingSituations.checkRent,
  63. checkMap: state => state.creatingSituations.checkMap,
  64. checkPlan: state => state.creatingSituations.checkPlan,
  65. situationPreview: state => state.creatingSituations.situationPreview,
  66. }),
  67. botmBtnGroup: function() {
  68. if(this.stepActive === 4) {
  69. if(this.showCheckPlan1) {
  70. return btnGroupPlan1;
  71. } else {
  72. return btnGroupPlan2;
  73. }
  74. } else if(this.stepActive === 5) {
  75. return btnGroupSituationPreview;
  76. } else {
  77. return normalBtnGroup;
  78. }
  79. }
  80. },
  81. onLoad:function({id,type}){
  82. this.saveType = type ? type : 'POST';
  83. if(id) {
  84. this.editID = id;
  85. this.dispatch('detialConfig',{id}).then((data)=>{
  86. if(data) {
  87. const {topic} = data;
  88. let theme = themeList[Number(topic)],
  89. condition = editCondition(data),
  90. editConfig = {};
  91. this.myCommit('theme', theme); // 主题
  92. if(type === 'PUT') { // 编辑
  93. let checkRent = editCheckRent(data),
  94. checkMap = editCheckMap(data),
  95. checkPlan = editCheckPlan(data),
  96. situationPreview = editSituationPreview(data);
  97. this.myCommit('checkPlan', checkPlan); // 查核计划
  98. this.myCommit('situationPreview', situationPreview); // 预览
  99. editConfig = {
  100. theme,
  101. condition,
  102. checkRent,
  103. checkMap,
  104. checkPlan,
  105. situationPreview
  106. };
  107. } else { // 复制创建
  108. this.myCommit('condition', condition); // 条件
  109. editConfig = {
  110. theme,
  111. condition,
  112. };
  113. }
  114. this.myCommit('editConfig', editConfig);
  115. // 回到第一步或者第三步
  116. this.myCommit('stepActive', type === 'PUT' ? 0 : 2);
  117. }
  118. });
  119. }
  120. },
  121. methods: {
  122. save: function() {
  123. const {sitName,preDay,preH,startDay} = this.situationPreview;
  124. const {dateObj,checkedItem,checkList} = this.checkPlan;
  125. const {depType, options, conditionIds} = this.condition;
  126. if(!sitName || sitName.length < 2) {
  127. uni.showModal({
  128. title: '温馨提示',
  129. content: `情境名称不能为空也不能少于2个字!`,
  130. showCancel: false
  131. });
  132. return;
  133. }
  134. let data = {
  135. name: sitName,
  136. topic: this.theme.id,
  137. checkPlanStartDate: dateObj.start,
  138. checkPlanEndDate: dateObj.end,
  139. remindPlanDay: preDay,
  140. remindPlanHour: preH,
  141. remindCheckDay: startDay,
  142. depType,
  143. filterCondition: optionsHandle(options, conditionIds),
  144. checkGroup: checkGroup(this.checkRent),
  145. checkDep: checkDep(this.checkMap.list),
  146. planConfig: {
  147. frequency: checkedItem.value,
  148. day: checkedItem.model,
  149. startDate: dateObj.start,
  150. endDate: dateObj.end,
  151. num: checkList.length
  152. },
  153. planList: [...checkList].map((date, i)=>{
  154. return {
  155. startDate: date,
  156. endDate: i === checkList.length - 1 ? dateObj.end : checkList[i+1]
  157. }
  158. })
  159. };
  160. if(this.saveType === 'PUT') {
  161. data.id = this.editID;
  162. }
  163. this.dispatch(`save${this.saveType}`, data).then((data)=>{
  164. if(data) {
  165. // 保存成功先清空数据
  166. this.myCommit('stepActive', 0);
  167. this.myCommit('theme', {id: null, title: null, des: null});
  168. this.myCommit('editConfig', null);
  169. uni.navigateTo({
  170. url: '/pages/situationsCenter/situationsCenter'
  171. });
  172. }
  173. });
  174. },
  175. changeStep: function(id) {
  176. switch(id) {
  177. case 'pre': // 上一步
  178. if(this.stepActive > 0)
  179. this.myCommit('needReload', false);
  180. this.myCommit('stepActive', this.stepActive - 1);
  181. break;
  182. case 'next': // 下一步
  183. if(this.stepActive < this.options.length)
  184. this.nextHandle(this.stepActive);
  185. break;
  186. case 'checkPlanCreate': // 生成查核计划
  187. if(this.checkPlan.checkList.length === 0) {
  188. uni.showModal({
  189. title: '错误提示',
  190. content: '查核频次必须大于或等于1!',
  191. showCancel: false
  192. });
  193. } else {
  194. this.myCommit('showCheckPlan1', false);
  195. }
  196. break;
  197. case 'checkPlanCallback': // 生成查核计划-返回
  198. this.myCommit('showCheckPlan1', true);
  199. break;
  200. case 'situationPreviewOK': // 完成
  201. this.save();
  202. break;
  203. }
  204. },
  205. /**
  206. * 处理【下一步】逻辑
  207. */
  208. nextHandle: function(stepActive) {
  209. let flage = false;
  210. switch(stepActive) {
  211. case 1:
  212. flage = this.errorHandle(this.condition.conditionIds.length > 0, 1);
  213. break;
  214. case 2:
  215. const {points} = this.checkRent.checkedItem;
  216. let condition = this.checkRent.checkedItem.id !== null && points;
  217. flage = this.errorHandle(condition, 2);
  218. break;
  219. case 4:
  220. const {checkList} = this.checkPlan;
  221. flage = this.errorHandle(checkList.length > 0, 4);
  222. break;
  223. default:
  224. flage = true;
  225. break;
  226. }
  227. if(flage) {
  228. this.myCommit('needReload', true);
  229. this.myCommit('stepActive', stepActive + 1);
  230. }
  231. },
  232. /**
  233. * 错误处理,满足条件返回true
  234. * @param {Object} condition 条件
  235. * @param {Object} index 当前下标
  236. */
  237. errorHandle: function(condition, index) {
  238. if(condition) {
  239. return true;
  240. } else {
  241. uni.showModal({
  242. title: '温馨提示',
  243. content: `请先选择${this.options[index].hint}!`,
  244. showCancel: false
  245. });
  246. return false;
  247. }
  248. },
  249. myCommit: function(key, data) {
  250. this.$store.commit({type: 'creatingSituations/comChangeState',key,data});
  251. },
  252. dispatch: function(key, data) {
  253. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  254. },
  255. },
  256. components: {
  257. checkMapDetail,
  258. checkMapAdd
  259. }
  260. }
  261. </script>
  262. <style lang="less">
  263. .creatingSituations {
  264. width: 100%;
  265. height: 100%;
  266. background-color: #F5F6FA;
  267. .page-wrap {
  268. padding-bottom: 75rpx;
  269. width: 100%;
  270. height: 100%;
  271. }
  272. }
  273. </style>