checkMapAdd.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 class="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. </scroll-view>
  24. <tm-simple-btn-group :options="botmBtnGroup"
  25. v-on:callback="btnClick" ></tm-simple-btn-group>
  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. // console.log({id});
  70. if(id === 'ok') {
  71. if(this.checkedIds.length>0){
  72. this.dispatch('addDeptList', {depIds: this.checkedIds}).then((data)=>{
  73. if(data) {
  74. const {list, actionItem} = this.checkMap;
  75. let arr = [...this.checkMap.list];
  76. let _data = this.checkDep(data);
  77. let index = list.findIndex(({id})=> id === actionItem.id);
  78. arr.splice(index + 1, 0, ..._data);
  79. this.myCommit('list', arr);
  80. }
  81. });
  82. }else {
  83. uni.showModal({
  84. title: '提示',
  85. content: '新增单位不能为空!',
  86. showCancel:false,
  87. success: function (res) {
  88. if (res.confirm) {
  89. // console.log('用户点击确定');
  90. }
  91. }
  92. });
  93. }
  94. }
  95. if(id=='cancle'){
  96. //点击取消
  97. }
  98. this.commit('showCheckMapAdd', false);
  99. },
  100. checkDep: function(list) {
  101. return list.map((item, i)=>{
  102. return {
  103. ...item,
  104. status: 'add',
  105. pointList: (item.pointList || []).map((ptem)=>{
  106. return {
  107. ...ptem,
  108. selectFlag: true,
  109. itemList: (ptem.itemList || []).map((ntem)=>{
  110. return {
  111. ...ntem,
  112. selectFlag: true
  113. }
  114. })
  115. }
  116. })
  117. }
  118. });
  119. },
  120. /**
  121. * 更新condition数据
  122. * @param {Object} key 要更新的属性
  123. * @param {Object} value 值
  124. */
  125. myCommit: function(key, value) {
  126. let data = {...this.checkMap};
  127. data[key] = value;
  128. this.commit('checkMap', data);
  129. },
  130. dispatch: function(key, data) {
  131. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  132. },
  133. commit: function(key,data) {
  134. this.$store.commit({type: 'creatingSituations/comChangeState', key, data});
  135. },
  136. }
  137. }
  138. </script>
  139. <style lang="less">
  140. .modal-body {
  141. margin-top: 10%;
  142. border-radius: 25rpx 25rpx 0 0;
  143. padding: 35rpx 40rpx 75rpx;
  144. width: 100%;
  145. height: 90%;
  146. font-size: 22.5rpx;
  147. line-height: 33.75rpx;
  148. color: #292C33;
  149. background-color: #fff;
  150. .top-title {
  151. font-size: 30rpx;
  152. line-height: 45rpx;
  153. }
  154. .list {
  155. margin-top: 25rpx;
  156. .item {
  157. .item-title {
  158. margin-bottom: 3.75rpx;
  159. font-size: 25rpx;
  160. line-height: 37.5rpx;
  161. font-weight: bold;
  162. }
  163. .chidren {
  164. display: flex;
  165. flex-direction: row;
  166. flex-wrap: wrap;
  167. margin: 0 -17.5rpx;
  168. .child {
  169. position: relative;
  170. display: flex;
  171. flex-direction: row;
  172. justify-content: center;
  173. align-items: center;
  174. margin: 10rpx 17.5rpx;
  175. border-radius: 5rpx;
  176. width: 200rpx;
  177. height: 50rpx;
  178. font-weight: 500;
  179. background-color: #EBEDF2;
  180. .text {
  181. overflow:hidden;
  182. text-overflow: ellipsis;
  183. white-space: nowrap;
  184. }
  185. image {
  186. position: absolute;
  187. right: 0;
  188. bottom: 0;
  189. width: 25rpx;
  190. height: 25rpx;
  191. }
  192. &.active {
  193. color: #3377FF;
  194. background-color: #E6EEFF;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. </style>