creatingSituations.vue 8.0 KB

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