creatingSituations.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view class="creatingSituations">
  3. <uni-popup ref="popup" type="bottom" :maskClick="true" @change="popupChangehandle">
  4. <tm-radio-group :list="situationTypeList" :defaultValue='situationPreview.situationType' :setting="{
  5. value: 'situationType',
  6. name: 'situationTypeName'
  7. }" :openkeys="[0]" @change="situationTypeChanged" />
  8. </uni-popup>
  9. <check-map-detail v-if="showCheckMapDetail"></check-map-detail>
  10. <view v-else class="page-wrap"
  11. :style="{paddingBottom: stepActive !== 0 ? '75rpx' : 0}">
  12. <tm-steps class="tm-steps" :options="options" :active="stepActive"></tm-steps>
  13. <scroll-view scroll-y="true" class="component-wrap">
  14. <!-- <component :is="options[active].component"></component> -->
  15. <theme v-if="stepActive==0"></theme>
  16. <condition v-if="stepActive==1"></condition>
  17. <checkRent v-if="stepActive==2"></checkRent>
  18. <checkMap v-if="stepActive==3"></checkMap>
  19. <checkPlan v-if="stepActive==4"></checkPlan>
  20. <situationPreview v-if="stepActive==5"></situationPreview>
  21. </scroll-view>
  22. <tm-simple-btn-group v-if="stepActive !== 0"
  23. :options="botmBtnGroup"
  24. v-on:callback="changeStep"></tm-simple-btn-group>
  25. </view>
  26. <check-map-add v-if="showCheckMapAdd"></check-map-add>
  27. </view>
  28. </template>
  29. <script>
  30. import { mapState } from "vuex";
  31. import theme from "./components/theme.vue";
  32. import condition from "./components/condition.vue";
  33. import checkRent from "./components/checkRent.vue";
  34. import checkMap from "./components/checkMap.vue";
  35. import checkMapDetail from "./components/checkMapDetail.vue";
  36. import checkMapAdd from "./components/checkMapAdd.vue";
  37. import checkPlan from "./components/checkPlan.vue";
  38. import situationPreview from "./components/situationPreview.vue";
  39. import {
  40. themeList,
  41. normalBtnGroup,
  42. btnGroupPlan1,
  43. btnGroupPlan2,
  44. btnGroupSituationPreview,
  45. optionsHandle,
  46. checkDep,
  47. checkGroup,
  48. editCondition,
  49. editCheckRent,
  50. editCheckMap,
  51. editCheckPlan,
  52. checkPlanList,
  53. editSituationPreview
  54. } from "./components/utils.js";
  55. import {dateHandle} from "../../utils/dateHandle.js";
  56. export default {
  57. data() {
  58. return {
  59. saveType: 'POST',
  60. editID: '',
  61. options: [
  62. {id: 'theme', title: '主题', component: theme},
  63. {id: 'condition', title: '条件', component: condition, hint: '追踪条件'},
  64. {id: 'checkRent', title: '查核组', component: checkRent, hint: '查核组'},
  65. {id: 'checkMap', title: '地图', component: checkMap, hint: '地图'},
  66. {id: 'checkPlan', title: '计划', component: checkPlan, hint: '制定计划'},
  67. {id: 'situationPreview', title: '预览', component: situationPreview},
  68. ]
  69. }
  70. },
  71. computed: {
  72. ...mapState({
  73. showCheckMapDetail: state => state.creatingSituations.showCheckMapDetail,
  74. showCheckMapAdd: state => state.creatingSituations.showCheckMapAdd,
  75. showCheckPlan1: state => state.creatingSituations.showCheckPlan1,
  76. stepActive: state => state.creatingSituations.stepActive,
  77. theme: state => state.creatingSituations.theme,
  78. condition: state => state.creatingSituations.condition,
  79. checkRent: state => state.creatingSituations.checkRent,
  80. checkMap: state => state.creatingSituations.checkMap,
  81. checkPlan: state => state.creatingSituations.checkPlan,
  82. situationPreview: state => state.creatingSituations.situationPreview,
  83. situationTypeList:state => state.creatingSituations.situationTypeList,
  84. showSelectableSituationTypeList:state => state.creatingSituations.showSelectableSituationTypeList,
  85. }),
  86. situationTypeName(){
  87. const temp = this.situationTypeList.filter(item=>item.situationType == this.situationPreview.situationType);
  88. return temp[0].situationTypeName;
  89. },
  90. botmBtnGroup: function() {
  91. if(this.stepActive === 4) {
  92. if(this.showCheckPlan1) {
  93. return btnGroupPlan1;
  94. } else {
  95. return btnGroupPlan2;
  96. }
  97. } else if(this.stepActive === 5) {
  98. return btnGroupSituationPreview;
  99. } else {
  100. return normalBtnGroup;
  101. }
  102. },
  103. dataIsNull() {
  104. let data = this.checkMap.list.filter((item)=> item.status !== 'disable');
  105. return data.length === 0;
  106. }
  107. },
  108. watch:{
  109. /**
  110. * @param {Boolen} newVal
  111. * @param {Boolen} oldVal
  112. */
  113. showSelectableSituationTypeList:function(newVal, oldVal){
  114. if(newVal){
  115. this.$refs.popup.open();
  116. }else{
  117. this.$refs.popup.close();
  118. }
  119. }
  120. },
  121. onLoad:function({id,type}){
  122. this.saveType = type ? type : 'POST';
  123. this.dispatch('getSituationTypes').then(res=>{
  124. this.myCommit('situationTypeList', res);
  125. })
  126. if(id) {
  127. this.editID = id;
  128. this.dispatch('detialConfig',{id}).then((data)=>{
  129. if(data) {
  130. const {topic} = data;
  131. let theme = themeList[Number(topic)],
  132. condition = editCondition(data),
  133. editConfig = {};
  134. this.myCommit('theme', theme); // 主题
  135. if(type === 'PUT') { // 编辑
  136. let checkRent = editCheckRent(data),
  137. checkMap = editCheckMap(data),
  138. checkPlan = editCheckPlan(data),
  139. situationPreview = editSituationPreview(data);
  140. this.myCommit('checkPlan', checkPlan); // 查核计划
  141. this.myCommit('situationPreview', situationPreview); // 预览
  142. editConfig = {
  143. theme,
  144. condition,
  145. checkRent,
  146. checkMap,
  147. checkPlan,
  148. situationPreview
  149. };
  150. console.log({editConfig});
  151. } else { // 复制创建
  152. this.myCommit('condition', condition); // 条件
  153. editConfig = {
  154. theme,
  155. condition,
  156. };
  157. }
  158. this.myCommit('editConfig', editConfig);
  159. // 回到第一步或者第三步
  160. this.myCommit('stepActive', type === 'PUT' ? 0 : 2);
  161. }
  162. });
  163. }
  164. },
  165. methods: {
  166. situationTypeChanged(type,name){
  167. // console.log({type,name});
  168. this.$store.commit('creatingSituations/comChangeState',{key:'situationPreview',data:{...this.situationPreview,situationType:type}});
  169. // this.$store.commit('creatingSituations/comChangeState',{key:'showSelectableSituationTypeList',data:false});
  170. },
  171. save: function() {
  172. const {sitName,preDay,preH,startDay, description,situationType,showNotApplicable,showCountNum} = this.situationPreview;
  173. const {dateObj,checkedItem,checkList} = this.checkPlan;
  174. const {depType, options, conditionIds} = this.condition;
  175. if(!sitName || sitName.length < 2) {
  176. uni.showModal({
  177. title: '温馨提示',
  178. content: `情境名称不能为空也不能少于2个字!`,
  179. showCancel: false
  180. });
  181. return;
  182. }
  183. if(preDay > 31) {
  184. uni.showModal({
  185. title: '温馨提示',
  186. content: `提醒天数不得大于31天!`,
  187. showCancel: false
  188. });
  189. return;
  190. }
  191. if(preH > 24) {
  192. uni.showModal({
  193. title: '温馨提示',
  194. content: `提醒天数不得大于24小时!`,
  195. showCancel: false
  196. });
  197. return;
  198. }
  199. if(preDay != null&&! /^\d+$/.test(preDay)) {
  200. uni.showModal({
  201. title: '温馨提示',
  202. content: `提醒天数不能是小数!`,
  203. showCancel: false
  204. });
  205. return;
  206. }
  207. if(preH != null&&! /^\d+$/.test(preH)) {
  208. uni.showModal({
  209. title: '温馨提示',
  210. content: `提醒小时不能是小数!`,
  211. showCancel: false
  212. });
  213. return;
  214. }
  215. let data = {
  216. description,
  217. name: sitName,
  218. topic: this.theme.id,
  219. checkPlanStartDate: dateObj.start,
  220. checkPlanEndDate: dateObj.end,
  221. remindPlanDay: preDay,
  222. remindPlanHour: preH,
  223. remindCheckDay: startDay,
  224. depType,
  225. showNotApplicable:showNotApplicable,
  226. subtotal:showCountNum,
  227. situationType:situationType,
  228. filterCondition: optionsHandle(options, conditionIds),
  229. checkGroup: checkGroup(this.checkRent),
  230. checkDep: checkDep(this.checkMap.list),
  231. planConfig: {
  232. frequency: checkedItem.value,
  233. day: checkedItem.model,
  234. startDate: dateObj.start,
  235. endDate: dateObj.end,
  236. num: checkList.length
  237. },
  238. planList: [...checkList].map((date, i)=>{
  239. return {
  240. startDate: date,
  241. endDate: dateHandle.getNewData(date, checkedItem.model - 1)
  242. }
  243. })
  244. };
  245. if(this.saveType === 'PUT') {
  246. data.id = this.editID;
  247. }
  248. this.dispatch(`save${this.saveType}`, data).then((data)=>{
  249. if(data) {
  250. // 保存成功先清空数据
  251. this.clearData();
  252. uni.navigateTo({
  253. url: '/pages/situationsCenter/situationsCenter'
  254. });
  255. }
  256. });
  257. },
  258. changeStep: function(id) {
  259. switch(id) {
  260. case 'pre': // 上一步
  261. if(this.stepActive > 0)
  262. this.myCommit('needReload', false);
  263. this.myCommit('stepActive', this.stepActive - 1);
  264. break;
  265. case 'next': // 下一步
  266. if(this.stepActive < this.options.length)
  267. this.nextHandle(this.stepActive);
  268. break;
  269. case 'checkPlanCreate': // 生成查核计划
  270. if(this.checkPlan.checkList.length === 0&&this.checkPlan.dateObj.dayNum<1) {
  271. uni.showModal({
  272. title: '错误提示',
  273. content: '查核频次必须大于或等于1!',
  274. showCancel: false
  275. });
  276. }else {
  277. this.myCommit('showCheckPlan1', false);
  278. }
  279. break;
  280. case 'checkPlanCallback': // 生成查核计划-返回
  281. this.myCommit('showCheckPlan1', true);
  282. break;
  283. case 'situationPreviewOK': // 完成
  284. this.save();
  285. break;
  286. }
  287. },
  288. /**
  289. * 处理【下一步】逻辑
  290. */
  291. nextHandle: function(stepActive) {
  292. let flage = false;
  293. switch(stepActive) {
  294. case 1:
  295. flage = this.errorHandle(this.condition.conditionIds.length > 0, 1);
  296. break;
  297. case 2:
  298. const {points} = this.checkRent.checkedItem;
  299. let condition = this.checkRent.checkedItem.id !== null && points;
  300. flage = this.errorHandle(condition, 2);
  301. break;
  302. case 3: flage = this.errorHandle(!this.dataIsNull, 3);
  303. break;
  304. case 4:
  305. const {checkList} = this.checkPlan;
  306. flage = this.errorHandle(checkList.length > 0, 4);
  307. break;
  308. case 5:
  309. this.dispatch('getSituationTypes').then(res=>{
  310. console.log({res});
  311. })
  312. break;
  313. default:
  314. flage = true;
  315. break;
  316. }
  317. if(flage) {
  318. this.myCommit('needReload', true);
  319. this.myCommit('stepActive', stepActive + 1);
  320. }
  321. },
  322. /**
  323. * 错误处理,满足条件返回true
  324. * @param {Object} condition 条件
  325. * @param {Object} index 当前下标
  326. */
  327. errorHandle: function(condition, index) {
  328. if(condition) {
  329. return true;
  330. } else {
  331. uni.showModal({
  332. title: '温馨提示',
  333. content: index === 3 ? '查核地图不能为空' :`请先选择${this.options[index].hint}!`,
  334. showCancel: false
  335. });
  336. return false;
  337. }
  338. },
  339. myCommit: function(key, data) {
  340. // console.log({key, data});
  341. this.$store.commit({type: 'creatingSituations/comChangeState',key,data});
  342. },
  343. dispatch: function(key, data) {
  344. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  345. },
  346. clearData:function() {
  347. checkPlanList[5].model = null;
  348. this.$store.commit({type: 'creatingSituations/setInit'});
  349. },
  350. popupChangehandle:function(data){
  351. const {show} = data;
  352. this.$store.commit('creatingSituations/comChangeState',{key:'showSelectableSituationTypeList',data:show});
  353. },
  354. },
  355. destroyed() {
  356. this.clearData();
  357. },
  358. components: {
  359. checkMapDetail,
  360. checkMapAdd,
  361. theme,
  362. condition,
  363. checkRent,
  364. checkMap,
  365. checkPlan,
  366. situationPreview
  367. }
  368. }
  369. </script>
  370. <style lang="less">
  371. .creatingSituations {
  372. width: 100%;
  373. height: 100vh;
  374. background-color: #F5F6FA;
  375. .page-wrap {
  376. padding-bottom: 75rpx;
  377. width: 100%;
  378. height: 100%;
  379. .tm-steps {
  380. height: auto;
  381. }
  382. .component-wrap {
  383. padding-bottom: 87.5rpx;
  384. }
  385. }
  386. }
  387. </style>