creatingSituations.vue 9.0 KB

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