checkMap.vue 6.2 KB

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