checkMap.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. })
  59. },
  60. created:function(){
  61. this.init();
  62. },
  63. methods: {
  64. init: function() {
  65. if(this.needReload) { // 点击上一步不用获取数据
  66. const {points} = this.checkRent.checkedItem;
  67. const {depType} = this.condition;
  68. if(!points) return;
  69. let checkPointIds = points.map(({id})=> id);
  70. this.dispatch('checkDeptList', { depType, checkPointIds })
  71. .then((data)=> {
  72. if(data) {
  73. let _data = this.checkDep(data);
  74. this.myCommit('list', _data);
  75. }
  76. });
  77. // 获取新增单位
  78. this.dispatch('deptList', { depType }).then((data)=>{
  79. if(data) this.myCommit('deptList', data);
  80. });
  81. }
  82. },
  83. checkDep: function(list) {
  84. return list.map((item, i)=>{
  85. return {
  86. ...item,
  87. status: 'normal',
  88. pointList: (item.pointList || []).map((ptem)=>{
  89. return {
  90. ...ptem,
  91. selectFlag: true,
  92. itemList: (ptem.itemList || []).map((ntem)=>{
  93. return {
  94. ...ntem,
  95. selectFlag: true
  96. }
  97. })
  98. }
  99. })
  100. }
  101. });
  102. },
  103. creatIcon: function(status) {
  104. let obj = {id: 'jinyong', label: '禁用'};
  105. switch(status) {
  106. case 'add':
  107. obj = {id: 'del', label: '删除'};
  108. break;
  109. case 'disable':
  110. obj = {id: 'qiyong', label: '启用'};
  111. break;
  112. }
  113. return obj;
  114. },
  115. detail: function(item) {
  116. if(item.status === 'disable') return;
  117. this.commit('needReload', false); // 不用新获取数据
  118. this.commit('showCheckMapDetail', true);
  119. this.myCommit('actionItem', item);
  120. },
  121. btnClick: function(e, btnType, item) {
  122. if(item.status === 'disable' && btnType !== 'qiyong') return;
  123. _stopPropagation(e);
  124. switch(btnType) {
  125. case 'add': // 新增
  126. this.commit('needReload', false); // 不用新获取数据
  127. this.commit('showCheckMapAdd', true);
  128. this.myCommit('actionItem', item);
  129. break;
  130. default: // 其他
  131. this.preAndNext(btnType, item);
  132. break;
  133. }
  134. },
  135. preAndNext: function(type, item) {
  136. let arr = [...this.checkMap.list];
  137. let index = arr.findIndex(({id}) => id === item.id);
  138. switch(type) {
  139. case 'pre': // 上移
  140. if(index > 0) {
  141. let pre = arr[index - 1];
  142. arr[index - 1] = item;
  143. arr[index] = pre;
  144. }
  145. break;
  146. case 'next': // 下移
  147. if(index < arr.length - 1) {
  148. let next = arr[index + 1];
  149. arr[index + 1] = item;
  150. arr[index] = next;
  151. }
  152. break;
  153. case 'del': // 删除
  154. arr.splice(index, 1);
  155. break;
  156. case 'jinyong': // 禁用
  157. arr.splice(index, 1);
  158. arr.push({...item, status: 'disable'});
  159. break;
  160. case 'qiyong': // 启用
  161. let _index = arr.findIndex(({status})=>status === 'disable');
  162. arr.splice(index, 1); // 删掉原来的
  163. arr.splice(_index, 0, {...item, status: 'normal'}); // 添加到disable的前面
  164. break;
  165. }
  166. this.myCommit('list', arr);
  167. },
  168. /**
  169. * 更新condition数据
  170. * @param {Object} key 要更新的属性
  171. * @param {Object} value 值
  172. */
  173. myCommit: function(key, value) {
  174. let data = {...this.checkMap};
  175. data[key] = value;
  176. this.commit('checkMap', data);
  177. },
  178. dispatch: function(key, data) {
  179. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  180. },
  181. commit: function(key, data) {
  182. this.$store.commit({type: 'creatingSituations/comChangeState', key, data});
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="less">
  188. .check-map {
  189. .check-map-list {
  190. .btn-group {
  191. display: flex;
  192. flex-direction: row;
  193. padding: 15rpx 0;
  194. width: 100%;
  195. height: 77.5rpx;
  196. background-color: #FAFBFC;
  197. .btn {
  198. display: flex;
  199. flex-direction: column;
  200. align-items: center;
  201. justify-content: center;
  202. border-right: 1px solid #DADEE6;
  203. flex: 1;
  204. font-size: 17.5rpx;
  205. line-height: 26.25rpx;
  206. color: #7A8599;
  207. &:last-child {
  208. border-right: 0;
  209. }
  210. image {
  211. width: 25rpx;
  212. height: 25rpx;
  213. }
  214. }
  215. }
  216. .dis-img-wrap,
  217. .add-img-wrap {
  218. position: absolute;
  219. top: 18.75rpx;
  220. right: 18.75rpx;
  221. width: 93.75rpx;
  222. height: 93.75rpx;
  223. image {
  224. width: 100%;
  225. height: 100%;
  226. }
  227. }
  228. .add-img-wrap {
  229. top: 0;
  230. right: 0;
  231. width: 100rpx;
  232. height: 35rpx;
  233. text {
  234. position: absolute;
  235. top: 4.37rpx;
  236. left: 28.75rpx;
  237. font-size: 17.5rpx;
  238. line-height: 26.25rpx;
  239. color: #fff;
  240. }
  241. }
  242. &.disable {
  243. .title-wrap {
  244. >text, >view {
  245. color: #B8BECC;
  246. }
  247. }
  248. .content {
  249. text {
  250. color: #B8BECC;
  251. }
  252. }
  253. .btn-group {
  254. .btn {
  255. color: #B8BECC;
  256. &:last-child {
  257. color: #7A8599;
  258. }
  259. }
  260. }
  261. }
  262. }
  263. }
  264. </style>