creatingSituations.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. condition: state => state.creatingSituations.condition,
  60. checkRent: state => state.creatingSituations.checkRent,
  61. }),
  62. botmBtnGroup: function() {
  63. if(this.stepActive === 4) {
  64. if(this.showCheckPlan1) {
  65. return btnGroupPlan1;
  66. } else {
  67. return btnGroupPlan2;
  68. }
  69. } else if(this.stepActive === 5) {
  70. return btnGroupSituationPreview;
  71. } else {
  72. return normalBtnGroup;
  73. }
  74. }
  75. },
  76. methods: {
  77. changeStep: function(id) {
  78. switch(id) {
  79. case 'pre': // 上一步
  80. if(this.stepActive > 0)
  81. this.myCommit('stepActive', this.stepActive - 1);
  82. break;
  83. case 'next': // 下一步
  84. if(this.stepActive < this.options.length)
  85. this.nextHandle(this.stepActive);
  86. break;
  87. case 'checkPlanCreate': // 生成查核计划
  88. this.myCommit('showCheckPlan1', false);
  89. break;
  90. case 'checkPlanCallback': // 生成查核计划-返回
  91. this.myCommit('showCheckPlan1', true);
  92. break;
  93. }
  94. },
  95. /**
  96. * 处理【下一步】逻辑
  97. */
  98. nextHandle: function(stepActive) {
  99. let flage = false;
  100. switch(stepActive) {
  101. case 1:
  102. flage = this.errorHandle(this.condition.conditionIds.length > 0, 1);
  103. break;
  104. case 2:
  105. const {points} = this.checkRent.checkedItem;
  106. let condition = this.checkRent.checkedItem.id !== null && points;
  107. flage = this.errorHandle(condition, 2);
  108. break;
  109. }
  110. if(flage) this.myCommit('stepActive', stepActive + 1);
  111. },
  112. /**
  113. * 错误处理,满足条件返回true
  114. * @param {Object} condition 条件
  115. * @param {Object} index 当前下标
  116. */
  117. errorHandle: function(condition, index) {
  118. if(condition) {
  119. return true;
  120. } else {
  121. uni.showModal({
  122. title: '温馨提示',
  123. content: `请先选择${this.options[index].hint}!`,
  124. showCancel: false
  125. });
  126. return false;
  127. }
  128. },
  129. myCommit: function(key, data) {
  130. this.$store.commit({type: 'creatingSituations/comChangeState',key,data});
  131. }
  132. },
  133. components: {
  134. checkMapDetail,
  135. checkMapAdd
  136. }
  137. }
  138. </script>
  139. <style lang="less">
  140. .creatingSituations {
  141. width: 100%;
  142. height: 100%;
  143. background-color: #F5F6FA;
  144. .page-wrap {
  145. padding-bottom: 75rpx;
  146. width: 100%;
  147. height: 100%;
  148. }
  149. }
  150. </style>