creatingSituations.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.myCommit('stepActive', 0);
  173. this.myCommit('theme', {id: null, title: null, des: null});
  174. this.myCommit('editConfig', null);
  175. uni.navigateTo({
  176. url: '/pages/situationsCenter/situationsCenter'
  177. });
  178. }
  179. });
  180. },
  181. changeStep: function(id) {
  182. switch(id) {
  183. case 'pre': // 上一步
  184. if(this.stepActive > 0)
  185. this.myCommit('needReload', false);
  186. this.myCommit('stepActive', this.stepActive - 1);
  187. break;
  188. case 'next': // 下一步
  189. if(this.stepActive < this.options.length)
  190. this.nextHandle(this.stepActive);
  191. break;
  192. case 'checkPlanCreate': // 生成查核计划
  193. if(this.checkPlan.checkList.length === 0) {
  194. uni.showModal({
  195. title: '错误提示',
  196. content: '查核频次必须大于或等于1!',
  197. showCancel: false
  198. });
  199. } else {
  200. this.myCommit('showCheckPlan1', false);
  201. }
  202. break;
  203. case 'checkPlanCallback': // 生成查核计划-返回
  204. this.myCommit('showCheckPlan1', true);
  205. break;
  206. case 'situationPreviewOK': // 完成
  207. this.save();
  208. break;
  209. }
  210. },
  211. /**
  212. * 处理【下一步】逻辑
  213. */
  214. nextHandle: function(stepActive) {
  215. let flage = false;
  216. switch(stepActive) {
  217. case 1:
  218. flage = this.errorHandle(this.condition.conditionIds.length > 0, 1);
  219. break;
  220. case 2:
  221. const {points} = this.checkRent.checkedItem;
  222. let condition = this.checkRent.checkedItem.id !== null && points;
  223. flage = this.errorHandle(condition, 2);
  224. break;
  225. case 3: flage = this.errorHandle(!this.dataIsNull, 3);
  226. break;
  227. case 4:
  228. const {checkList} = this.checkPlan;
  229. flage = this.errorHandle(checkList.length > 0, 4);
  230. break;
  231. default:
  232. flage = true;
  233. break;
  234. }
  235. if(flage) {
  236. this.myCommit('needReload', true);
  237. this.myCommit('stepActive', stepActive + 1);
  238. }
  239. },
  240. /**
  241. * 错误处理,满足条件返回true
  242. * @param {Object} condition 条件
  243. * @param {Object} index 当前下标
  244. */
  245. errorHandle: function(condition, index) {
  246. if(condition) {
  247. return true;
  248. } else {
  249. uni.showModal({
  250. title: '温馨提示',
  251. content: index === 3 ? '查核地图不能为空' :`请先选择${this.options[index].hint}!`,
  252. showCancel: false
  253. });
  254. return false;
  255. }
  256. },
  257. myCommit: function(key, data) {
  258. this.$store.commit({type: 'creatingSituations/comChangeState',key,data});
  259. },
  260. dispatch: function(key, data) {
  261. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  262. },
  263. },
  264. components: {
  265. checkMapDetail,
  266. checkMapAdd
  267. }
  268. }
  269. </script>
  270. <style lang="less">
  271. .creatingSituations {
  272. width: 100%;
  273. height: 100%;
  274. background-color: #F5F6FA;
  275. .page-wrap {
  276. padding-bottom: 75rpx;
  277. width: 100%;
  278. height: 100%;
  279. }
  280. }
  281. </style>