creatingSituations.vue 7.5 KB

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