checkMap.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <view class="check-map">
  3. <view class="title">请对查核地图进行配置</view>
  4. <view class="check-map-list">
  5. <view class="item"
  6. v-for="(item, index) in checkMap.list"
  7. :class="{disable: item.status === 'disable'}"
  8. @click="detail(item)"
  9. :key="index">
  10. <tm-check-map-list :item="item"></tm-check-map-list>
  11. <view class="btn-group">
  12. <view class="btn"
  13. v-for="(btn, index) in btnGroupArr"
  14. @click="btnClick($event, btn.id, item)"
  15. :key="index">
  16. <image :src="`../../static/icon-${btn.id}${item.status === 'disable'
  17. ? 'dis' : ''}.png`"></image>
  18. <text>{{btn.label}}</text>
  19. </view>
  20. <view class="btn"
  21. @click="btnClick($event, creatIcon(item.status)['id'], item)">
  22. <image :src="`../../static/icon-${creatIcon(item.status)['id']}.png`">
  23. </image>
  24. <text>{{ creatIcon(item.status)['label'] }}</text>
  25. </view>
  26. </view>
  27. <view class="add-img-wrap" v-if="item.status === 'add'">
  28. <image src="../../../static/top-img.png"></image>
  29. <text>新增项</text>
  30. </view>
  31. <view class="dis-img-wrap" v-if="item.status === 'disable'">
  32. <image src="../../../static/disable-img.png"></image>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { mapState } from "vuex";
  40. import {_stopPropagation} from "../../../utils/compatible.js";
  41. const btnGroupArr = [
  42. {id: 'add', label: '新增'},
  43. {id: 'pre', label: '上移'},
  44. {id: 'next', label: '下移'},
  45. ];
  46. export default {
  47. data() {
  48. return {
  49. btnGroupArr,
  50. }
  51. },
  52. computed: {
  53. ...mapState({
  54. checkMap: state => state.creatingSituations.checkMap,
  55. checkRent: state => state.creatingSituations.checkRent,
  56. condition: state => state.creatingSituations.condition,
  57. needReload: state => state.creatingSituations.needReload,
  58. editConfig: state => state.creatingSituations.editConfig
  59. })
  60. },
  61. created:function(){
  62. this.init();
  63. },
  64. methods: {
  65. init: function() {
  66. const {checkedItem} = this.checkRent;
  67. const {depType} = this.condition;
  68. const {checkRent, condition, checkMap} = this.editConfig;
  69. // 编辑的时候不用获取数据
  70. if(this.editConfig && checkRent && depType === condition.depType && checkedItem.id === checkRent.checkedItem.id) {
  71. this.commit('checkMap', checkMap);
  72. } else if(this.needReload) { // 点击上一步不用获取数据
  73. if(!checkedItem.points) return;
  74. let checkPointIds = checkedItem.points.map(({id})=> id);
  75. this.dispatch('checkDeptList', { depType, checkPointIds })
  76. .then((data)=> {
  77. if(data) {
  78. let _data = this.checkDep(data);
  79. this.myCommit('list', _data);
  80. }
  81. });
  82. // 获取新增单位
  83. this.dispatch('deptList', { depType }).then((data)=>{
  84. if(data) this.myCommit('deptList', data);
  85. });
  86. }
  87. },
  88. checkDep: function(list) {
  89. return list.map((item, i)=>{
  90. return {
  91. ...item,
  92. status: 'normal',
  93. pointList: (item.pointList || []).map((ptem)=>{
  94. return {
  95. ...ptem,
  96. selectFlag: true,
  97. itemList: (ptem.itemList || []).map((ntem)=>{
  98. return {
  99. ...ntem,
  100. selectFlag: true
  101. }
  102. })
  103. }
  104. })
  105. }
  106. });
  107. },
  108. creatIcon: function(status) {
  109. let obj = {id: 'jinyong', label: '禁用'};
  110. switch(status) {
  111. case 'add':
  112. obj = {id: 'del', label: '删除'};
  113. break;
  114. case 'disable':
  115. obj = {id: 'qiyong', label: '启用'};
  116. break;
  117. }
  118. return obj;
  119. },
  120. detail: function(item) {
  121. if(item.status === 'disable') return;
  122. this.commit('needReload', false); // 不用新获取数据
  123. this.commit('showCheckMapDetail', true);
  124. this.myCommit('actionItem', item);
  125. },
  126. btnClick: function(e, btnType, item) {
  127. if(item.status === 'disable' && btnType !== 'qiyong') return;
  128. _stopPropagation(e);
  129. switch(btnType) {
  130. case 'add': // 新增
  131. this.commit('needReload', false); // 不用新获取数据
  132. this.commit('showCheckMapAdd', true);
  133. this.myCommit('actionItem', item);
  134. break;
  135. default: // 其他
  136. this.preAndNext(btnType, item);
  137. break;
  138. }
  139. },
  140. preAndNext: function(type, item) {
  141. let arr = [...this.checkMap.list];
  142. let index = arr.findIndex(({id}) => id === item.id);
  143. switch(type) {
  144. case 'pre': // 上移
  145. if(index > 0) {
  146. let pre = arr[index - 1];
  147. arr[index - 1] = item;
  148. arr[index] = pre;
  149. }
  150. break;
  151. case 'next': // 下移
  152. if(index < arr.length - 1) {
  153. let next = arr[index + 1];
  154. arr[index + 1] = item;
  155. arr[index] = next;
  156. }
  157. break;
  158. case 'del': // 删除
  159. arr.splice(index, 1);
  160. break;
  161. case 'jinyong': // 禁用
  162. arr.splice(index, 1);
  163. arr.push({...item, status: 'disable'});
  164. break;
  165. case 'qiyong': // 启用
  166. let _index = arr.findIndex(({status})=>status === 'disable');
  167. arr.splice(index, 1); // 删掉原来的
  168. arr.splice(_index, 0, {...item, status: 'normal'}); // 添加到disable的前面
  169. break;
  170. }
  171. this.myCommit('list', arr);
  172. },
  173. /**
  174. * 更新condition数据
  175. * @param {Object} key 要更新的属性
  176. * @param {Object} value 值
  177. */
  178. myCommit: function(key, value) {
  179. let data = {...this.checkMap};
  180. data[key] = value;
  181. this.commit('checkMap', data);
  182. },
  183. dispatch: function(key, data) {
  184. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  185. },
  186. commit: function(key, data) {
  187. this.$store.commit({type: 'creatingSituations/comChangeState', key, data});
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="less">
  193. .check-map {
  194. .check-map-list {
  195. .btn-group {
  196. display: flex;
  197. flex-direction: row;
  198. padding: 15rpx 0;
  199. width: 100%;
  200. height: 77.5rpx;
  201. background-color: #FAFBFC;
  202. .btn {
  203. display: flex;
  204. flex-direction: column;
  205. align-items: center;
  206. justify-content: center;
  207. border-right: 1px solid #DADEE6;
  208. flex: 1;
  209. font-size: 17.5rpx;
  210. line-height: 26.25rpx;
  211. color: #7A8599;
  212. &:last-child {
  213. border-right: 0;
  214. }
  215. image {
  216. width: 25rpx;
  217. height: 25rpx;
  218. }
  219. }
  220. }
  221. .dis-img-wrap,
  222. .add-img-wrap {
  223. position: absolute;
  224. top: 18.75rpx;
  225. right: 18.75rpx;
  226. width: 93.75rpx;
  227. height: 93.75rpx;
  228. image {
  229. width: 100%;
  230. height: 100%;
  231. }
  232. }
  233. .add-img-wrap {
  234. top: 0;
  235. right: 0;
  236. width: 100rpx;
  237. height: 35rpx;
  238. text {
  239. position: absolute;
  240. top: 4.37rpx;
  241. left: 28.75rpx;
  242. font-size: 17.5rpx;
  243. line-height: 26.25rpx;
  244. color: #fff;
  245. }
  246. }
  247. &.disable {
  248. .title-wrap {
  249. >text, >view {
  250. color: #B8BECC;
  251. }
  252. }
  253. .content {
  254. text {
  255. color: #B8BECC;
  256. }
  257. }
  258. .btn-group {
  259. .btn {
  260. color: #B8BECC;
  261. &:last-child {
  262. color: #7A8599;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. }
  269. </style>