creatingSituations.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. const normalBtnGroup = [
  25. {id: 'pre', label: '上一步'},
  26. {id: 'next', label: '下一步'}
  27. ];
  28. const btnGroupPlan1 = [
  29. {id: 'pre', label: '上一步'},
  30. {id: 'checkPlanCreate', label: '生成查核计划'}
  31. ];
  32. const btnGroupPlan2 = [
  33. {id: 'checkPlanCallback', label: '返回'},
  34. {id: 'next', label: '下一步'}
  35. ];
  36. const btnGroupSituationPreview = [
  37. {id: 'pre', label: '上一步'},
  38. {id: 'situationPreviewOK', label: '完成'}
  39. ];
  40. export default {
  41. data() {
  42. return {
  43. options: [
  44. {id: 'theme', title: '主题', component: theme},
  45. {id: 'condition', title: '条件', component: condition, hint: '追踪条件'},
  46. {id: 'checkRent', title: '查核组', component: checkRent, hint: '查核组'},
  47. {id: 'checkMap', title: '地图', component: checkMap, hint: '地图'},
  48. {id: 'checkPlan', title: '计划', component: checkPlan, hint: '制定计划'},
  49. {id: 'situationPreview', title: '预览', component: situationPreview},
  50. ]
  51. }
  52. },
  53. computed: {
  54. ...mapState({
  55. showCheckMapDetail: state => state.creatingSituations.showCheckMapDetail,
  56. showCheckMapAdd: state => state.creatingSituations.showCheckMapAdd,
  57. showCheckPlan1: state => state.creatingSituations.showCheckPlan1,
  58. stepActive: state => state.creatingSituations.stepActive,
  59. theme: state => state.creatingSituations.theme,
  60. condition: state => state.creatingSituations.condition,
  61. checkRent: state => state.creatingSituations.checkRent,
  62. checkMap: state => state.creatingSituations.checkMap,
  63. checkPlan: state => state.creatingSituations.checkPlan,
  64. situationPreview: state => state.creatingSituations.situationPreview,
  65. }),
  66. botmBtnGroup: function() {
  67. if(this.stepActive === 4) {
  68. if(this.showCheckPlan1) {
  69. return btnGroupPlan1;
  70. } else {
  71. return btnGroupPlan2;
  72. }
  73. } else if(this.stepActive === 5) {
  74. return btnGroupSituationPreview;
  75. } else {
  76. return normalBtnGroup;
  77. }
  78. }
  79. },
  80. methods: {
  81. save: function() {
  82. const {sitName,preDay,preH,startDay} = this.situationPreview;
  83. const {dateObj,checkedItem,checkList} = this.checkPlan;
  84. const {depType, options} = this.condition;
  85. if(!sitName) {
  86. uni.showModal({
  87. title: '温馨提示',
  88. content: `情境名称不能为空!`,
  89. showCancel: false
  90. });
  91. return;
  92. }
  93. this.dispatch('save', {
  94. name: sitName,
  95. topic: this.theme.id,
  96. checkPlanStartDate: dateObj.start,
  97. checkPlanEndDate: dateObj.end,
  98. remindPlanDay: preDay,
  99. remindPlanHour: preH,
  100. remindCheckDay: startDay,
  101. depType,
  102. filterCondition: this.optionsHandle(options),
  103. checkGroup: this.checkGroup(),
  104. checkDep: this.checkDep(),
  105. planConfig: {
  106. frequency: checkedItem.value,
  107. day: checkedItem.model,
  108. startDate: dateObj.start,
  109. endDate: dateObj.end,
  110. num: checkList.length
  111. },
  112. planList: [...checkList].map((date, i)=>{
  113. return {
  114. startDate: date,
  115. endDate: i === checkList.length - 1 ? dateObj.end : checkList[i+1]
  116. }
  117. })
  118. }).then((data)=>{
  119. console.log(data);
  120. if(data) {
  121. uni.navigateTo({
  122. url: '/pages/situationsCenter/situationsCenter'
  123. });
  124. }
  125. });
  126. },
  127. changeStep: function(id) {
  128. switch(id) {
  129. case 'pre': // 上一步
  130. if(this.stepActive > 0)
  131. this.myCommit('needReload', false);
  132. this.myCommit('stepActive', this.stepActive - 1);
  133. break;
  134. case 'next': // 下一步
  135. if(this.stepActive < this.options.length)
  136. this.nextHandle(this.stepActive);
  137. break;
  138. case 'checkPlanCreate': // 生成查核计划
  139. this.myCommit('showCheckPlan1', false);
  140. break;
  141. case 'checkPlanCallback': // 生成查核计划-返回
  142. this.myCommit('showCheckPlan1', true);
  143. break;
  144. case 'situationPreviewOK': // 完成
  145. this.save();
  146. break;
  147. }
  148. },
  149. /**
  150. * 处理【下一步】逻辑
  151. */
  152. nextHandle: function(stepActive) {
  153. let flage = false;
  154. switch(stepActive) {
  155. case 1:
  156. flage = this.errorHandle(this.condition.conditionIds.length > 0, 1);
  157. break;
  158. case 2:
  159. const {points} = this.checkRent.checkedItem;
  160. let condition = this.checkRent.checkedItem.id !== null && points;
  161. flage = this.errorHandle(condition, 2);
  162. break;
  163. case 4:
  164. const {checkList} = this.checkPlan;
  165. flage = this.errorHandle(checkList.length > 0, 4);
  166. break;
  167. default:
  168. flage = true;
  169. break;
  170. }
  171. if(flage) {
  172. this.myCommit('needReload', true);
  173. this.myCommit('stepActive', stepActive + 1);
  174. }
  175. },
  176. /**
  177. * 错误处理,满足条件返回true
  178. * @param {Object} condition 条件
  179. * @param {Object} index 当前下标
  180. */
  181. errorHandle: function(condition, index) {
  182. if(condition) {
  183. return true;
  184. } else {
  185. uni.showModal({
  186. title: '温馨提示',
  187. content: `请先选择${this.options[index].hint}!`,
  188. showCancel: false
  189. });
  190. return false;
  191. }
  192. },
  193. /**
  194. * 构造条件提交结果
  195. */
  196. optionsHandle: function(arr) {
  197. let options = [...arr].map((item)=>{
  198. return {
  199. ...item,
  200. selectFlag: this.condition.conditionIds.includes(item.id),
  201. child: this.optionsHandle(item.child)
  202. }
  203. });
  204. return options;
  205. },
  206. checkDep: function() {
  207. const {list} = this.checkMap;
  208. return list.map((item, i)=>{
  209. return {
  210. ...item,
  211. sort: i+1,
  212. enableFlag: item.status === 'disable' ? false : true,
  213. }
  214. });
  215. },
  216. checkGroup: function() {
  217. const {list, checkedItem} = this.checkRent;
  218. let _list = [...list].map((ntem)=>{
  219. return {
  220. ...ntem,
  221. selectFlag: ntem.id === checkedItem.id ? true : false
  222. }
  223. });
  224. return _list;
  225. },
  226. myCommit: function(key, data) {
  227. this.$store.commit({type: 'creatingSituations/comChangeState',key,data});
  228. },
  229. dispatch: function(key, data) {
  230. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  231. },
  232. },
  233. components: {
  234. checkMapDetail,
  235. checkMapAdd
  236. }
  237. }
  238. </script>
  239. <style lang="less">
  240. .creatingSituations {
  241. width: 100%;
  242. height: 100%;
  243. background-color: #F5F6FA;
  244. .page-wrap {
  245. padding-bottom: 75rpx;
  246. width: 100%;
  247. height: 100%;
  248. }
  249. }
  250. </style>