creatingSituations.vue 9.1 KB

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