creatingSituations.vue 12 KB

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