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