creatingSituations.vue 10 KB

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