checkMap.vue 6.9 KB

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