checkMapAdd.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="modal">
  3. <scroll-view scroll-y="true" class="modal-body">
  4. <view class="body-content">
  5. <text class="top-title">选择要新增的单位</text>
  6. <view class="list">
  7. <view class="item"v-for="(item, index) in checkMap.deptList" :key="index">
  8. <view class="item-title">{{item.name}}</view>
  9. <view class="chidren">
  10. <view class="child"
  11. v-for="(child, n) in item.departmentList"
  12. :key="n"
  13. :class="{active: checkedIds.includes(child.id)}"
  14. @click="changeChecked(child.id)">
  15. <text>{{child.name}}</text>
  16. <image v-if="checkedIds.includes(child.id)"
  17. src="../../../static/bottom-img.png"></image>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <tm-simple-btn-group :options="botmBtnGroup"
  24. v-on:callback="btnClick" ></tm-simple-btn-group>
  25. </scroll-view>
  26. </view>
  27. </template>
  28. <script>
  29. import { mapState } from "vuex";
  30. import {arrFilter} from "../../../utils/arrFilter.js";
  31. export default {
  32. data() {
  33. return {
  34. checkedIds: []
  35. }
  36. },
  37. computed: {
  38. botmBtnGroup: function() {
  39. return [
  40. {id: 'cancle', label: '取消'},
  41. {id: 'ok', label: `已选${this.checkedIds.length}项,确定新增`}
  42. ];
  43. },
  44. ...mapState({
  45. checkMap: state => state.creatingSituations.checkMap,
  46. })
  47. },
  48. methods: {
  49. changeChecked: function(id) {
  50. this.checkedIds = arrFilter(id, this.checkedIds);
  51. },
  52. btnClick: function(id) {
  53. if(id === 'ok') {
  54. this.dispatch('addDeptList', {depIds: this.checkedIds}).then((data)=>{
  55. if(data) {
  56. const {list, actionItem} = this.checkMap;
  57. let arr = [...this.checkMap.list];
  58. data = data.map((item)=>{
  59. return {
  60. ...item,
  61. status: 'add'
  62. }
  63. });
  64. let index = list.findIndex(({id})=> id === actionItem.id);
  65. arr.splice(index + 1, 0, ...data);
  66. this.myCommit('list', arr);
  67. }
  68. });
  69. }
  70. this.commit('showCheckMapAdd', false);
  71. },
  72. /**
  73. * 更新condition数据
  74. * @param {Object} key 要更新的属性
  75. * @param {Object} value 值
  76. */
  77. myCommit: function(key, value) {
  78. let data = {...this.checkMap};
  79. data[key] = value;
  80. this.commit('checkMap', data);
  81. },
  82. dispatch: function(key, data) {
  83. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  84. },
  85. commit: function(key,data) {
  86. this.$store.commit({type: 'creatingSituations/comChangeState', key, data});
  87. },
  88. }
  89. }
  90. </script>
  91. <style lang="less">
  92. .modal {
  93. .modal-body {
  94. margin-top: 10%;
  95. border-radius: 25rpx 25rpx 0 0;
  96. padding: 35rpx 40rpx 75rpx;
  97. width: 100%;
  98. height: 90%;
  99. font-size: 22.5rpx;
  100. line-height: 33.75rpx;
  101. color: #292C33;
  102. background-color: #fff;
  103. .top-title {
  104. font-size: 30rpx;
  105. line-height: 45rpx;
  106. }
  107. .list {
  108. margin-top: 25rpx;
  109. .item {
  110. .item-title {
  111. margin-bottom: 3.75rpx;
  112. font-size: 25rpx;
  113. line-height: 37.5rpx;
  114. font-weight: bold;
  115. }
  116. .chidren {
  117. display: flex;
  118. flex-direction: row;
  119. flex-wrap: wrap;
  120. margin: 0 -17.5rpx;
  121. .child {
  122. position: relative;
  123. display: flex;
  124. flex-direction: row;
  125. justify-content: center;
  126. align-items: center;
  127. margin: 10rpx 17.5rpx;
  128. border-radius: 5rpx;
  129. width: 200rpx;
  130. height: 50rpx;
  131. font-weight: 500;
  132. background-color: #EBEDF2;
  133. image {
  134. position: absolute;
  135. right: 0;
  136. bottom: 0;
  137. width: 25rpx;
  138. height: 25rpx;
  139. }
  140. &.active {
  141. color: #3377FF;
  142. background-color: #E6EEFF;
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. </style>