checkMapAdd.vue 4.3 KB

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