creatingSituations.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. const {list} = this.checkMap;
  86. if(!sitName) {
  87. uni.showModal({
  88. title: '温馨提示',
  89. content: `情境名称不能为空!`,
  90. showCancel: false
  91. });
  92. return;
  93. }
  94. this.dispatch('save', {
  95. name: sitName,
  96. topic: this.theme.id,
  97. checkPlanStartDate: dateObj.start,
  98. checkPlanEndDate: dateObj.end,
  99. remindPlanDay: preDay,
  100. remindPlanHour: preH,
  101. remindCheckDay: startDay,
  102. depType,
  103. filterCondition: options,
  104. checkGroup: this.checkRent.list,
  105. checkDep: [...list].map((item,i)=>{
  106. return {
  107. ...item,
  108. sort: i+1,
  109. enableFlag: item.status === 'disable' ? false : true
  110. }
  111. }),
  112. planConfig: {
  113. frequency: checkedItem.value,
  114. day: checkedItem.model,
  115. startDate: dateObj.start,
  116. endDate: dateObj.end,
  117. num: checkList.length
  118. },
  119. planList: [...checkList].map((date, i)=>{
  120. return {
  121. startDate: date,
  122. endDate: i === checkList.length - 1 ? dateObj.end : checkList[i+1]
  123. }
  124. })
  125. }).then((data)=>{
  126. if(data) {
  127. }
  128. });
  129. },
  130. changeStep: function(id) {
  131. switch(id) {
  132. case 'pre': // 上一步
  133. if(this.stepActive > 0)
  134. this.myCommit('needReload', false);
  135. this.myCommit('stepActive', this.stepActive - 1);
  136. break;
  137. case 'next': // 下一步
  138. if(this.stepActive < this.options.length)
  139. this.nextHandle(this.stepActive);
  140. break;
  141. case 'checkPlanCreate': // 生成查核计划
  142. this.myCommit('showCheckPlan1', false);
  143. break;
  144. case 'checkPlanCallback': // 生成查核计划-返回
  145. this.myCommit('showCheckPlan1', true);
  146. break;
  147. case 'situationPreviewOK': // 完成
  148. this.save();
  149. break;
  150. }
  151. },
  152. /**
  153. * 处理【下一步】逻辑
  154. */
  155. nextHandle: function(stepActive) {
  156. let flage = false;
  157. switch(stepActive) {
  158. case 1:
  159. flage = this.errorHandle(this.condition.conditionIds.length > 0, 1);
  160. break;
  161. case 2:
  162. const {points} = this.checkRent.checkedItem;
  163. let condition = this.checkRent.checkedItem.id !== null && points;
  164. flage = this.errorHandle(condition, 2);
  165. break;
  166. case 4:
  167. const {checkList} = this.checkPlan;
  168. flage = this.errorHandle(checkList.length > 0, 4);
  169. break;
  170. default:
  171. flage = true;
  172. break;
  173. }
  174. if(flage) {
  175. this.myCommit('needReload', true);
  176. this.myCommit('stepActive', stepActive + 1);
  177. }
  178. },
  179. /**
  180. * 错误处理,满足条件返回true
  181. * @param {Object} condition 条件
  182. * @param {Object} index 当前下标
  183. */
  184. errorHandle: function(condition, index) {
  185. if(condition) {
  186. return true;
  187. } else {
  188. uni.showModal({
  189. title: '温馨提示',
  190. content: `请先选择${this.options[index].hint}!`,
  191. showCancel: false
  192. });
  193. return false;
  194. }
  195. },
  196. myCommit: function(key, data) {
  197. this.$store.commit({type: 'creatingSituations/comChangeState',key,data});
  198. },
  199. dispatch: function(key, data) {
  200. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  201. },
  202. },
  203. components: {
  204. checkMapDetail,
  205. checkMapAdd
  206. }
  207. }
  208. </script>
  209. <style lang="less">
  210. .creatingSituations {
  211. width: 100%;
  212. height: 100%;
  213. background-color: #F5F6FA;
  214. .page-wrap {
  215. padding-bottom: 75rpx;
  216. width: 100%;
  217. height: 100%;
  218. }
  219. }
  220. </style>