checkMapAdd.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <tm-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. </tm-modal>
  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. condition: state => state.creatingSituations.condition,
  47. })
  48. },
  49. created:function(){
  50. if(this.checkMap.deptList.length === 0) {
  51. // 获取新增单位
  52. const {depType} =this.condition;
  53. this.dispatch('deptList', { depType }).then((data)=>{
  54. if(data) this.myCommit('deptList', data);
  55. });
  56. }
  57. },
  58. methods: {
  59. changeChecked: function(id) {
  60. this.checkedIds = arrFilter(id, this.checkedIds);
  61. },
  62. btnClick: function(id) {
  63. if(id === 'ok') {
  64. this.dispatch('addDeptList', {depIds: this.checkedIds}).then((data)=>{
  65. if(data) {
  66. const {list, actionItem} = this.checkMap;
  67. let arr = [...this.checkMap.list];
  68. data = data.map((item)=>{
  69. return {
  70. ...item,
  71. status: 'add'
  72. }
  73. });
  74. let index = list.findIndex(({id})=> id === actionItem.id);
  75. arr.splice(index + 1, 0, ...data);
  76. this.myCommit('list', arr);
  77. }
  78. });
  79. }
  80. this.commit('showCheckMapAdd', false);
  81. },
  82. /**
  83. * 更新condition数据
  84. * @param {Object} key 要更新的属性
  85. * @param {Object} value 值
  86. */
  87. myCommit: function(key, value) {
  88. let data = {...this.checkMap};
  89. data[key] = value;
  90. this.commit('checkMap', data);
  91. },
  92. dispatch: function(key, data) {
  93. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  94. },
  95. commit: function(key,data) {
  96. this.$store.commit({type: 'creatingSituations/comChangeState', key, data});
  97. },
  98. }
  99. }
  100. </script>
  101. <style lang="less">
  102. .modal-body {
  103. margin-top: 10%;
  104. border-radius: 25rpx 25rpx 0 0;
  105. padding: 35rpx 40rpx 75rpx;
  106. width: 100%;
  107. height: 90%;
  108. font-size: 22.5rpx;
  109. line-height: 33.75rpx;
  110. color: #292C33;
  111. background-color: #fff;
  112. .top-title {
  113. font-size: 30rpx;
  114. line-height: 45rpx;
  115. }
  116. .list {
  117. margin-top: 25rpx;
  118. .item {
  119. .item-title {
  120. margin-bottom: 3.75rpx;
  121. font-size: 25rpx;
  122. line-height: 37.5rpx;
  123. font-weight: bold;
  124. }
  125. .chidren {
  126. display: flex;
  127. flex-direction: row;
  128. flex-wrap: wrap;
  129. margin: 0 -17.5rpx;
  130. .child {
  131. position: relative;
  132. display: flex;
  133. flex-direction: row;
  134. justify-content: center;
  135. align-items: center;
  136. margin: 10rpx 17.5rpx;
  137. border-radius: 5rpx;
  138. width: 200rpx;
  139. height: 50rpx;
  140. font-weight: 500;
  141. background-color: #EBEDF2;
  142. image {
  143. position: absolute;
  144. right: 0;
  145. bottom: 0;
  146. width: 25rpx;
  147. height: 25rpx;
  148. }
  149. &.active {
  150. color: #3377FF;
  151. background-color: #E6EEFF;
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. </style>