creatingSituations.vue 8.3 KB

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