checkMapDetail.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="pageContainer">
  3. <scroll-view scroll-y="true" class="check-map-detail">
  4. <view class="item" v-for="(item, index) in checkMap.actionItem.pointList" :key="index">
  5. <view class="icon-wrap" @click="openChildren(item.id)">
  6. <image :src="`../../static/list-${openItems.includes(item.id)
  7. ?'close':'open'}.png`"></image>
  8. </view>
  9. <view class="content">
  10. <view class="content-title" @click="openChildren(item.id)">{{item.name}}</view>
  11. <view class="children" v-if="openItems.includes(item.id)">
  12. <view class="child" v-for="(child, n) in item.itemList" :key="n">
  13. <view class="child-text">{{child.name}}</view>
  14. <view class="check-icon-wrap"
  15. @click="changeChecked(index, n, child.selectFlag)">
  16. <image :src="`../../static/check-${child.selectFlag
  17. ?'checkbox':'no'}.png`"></image>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="checkAllBtn"
  22. @click.stop="cancelAllChildHandle(index,item.selectFlag)">
  23. <image :src="`../../static/check-${item.selectFlag
  24. ?'checkbox':'no'}.png`"></image>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. <tm-simple-btn-group :options="botmBtnGroup"
  30. v-on:callback="btnClick" ></tm-simple-btn-group>
  31. </view>
  32. </template>
  33. <script>
  34. import { mapState } from "vuex";
  35. import {arrFilter} from "../../../utils/arrFilter.js";
  36. export default {
  37. data() {
  38. return {
  39. openItems: [],
  40. }
  41. },
  42. computed: {
  43. botmBtnGroup: function(){
  44. return [
  45. {id: 'cancle', label: '取消'},
  46. {id: 'ok', label: `已选${this.selectedNum}项,确定`}
  47. ];
  48. },
  49. ...mapState({
  50. checkMap: state => JSON.parse(JSON.stringify(state.creatingSituations.checkMap)),
  51. }),
  52. selectedNum: function() {
  53. let num = 0;
  54. this.checkMap.actionItem.pointList.map((item)=>{
  55. item.itemList.map((ntem)=>{
  56. if(ntem.selectFlag) num++;
  57. });
  58. });
  59. return num;
  60. },
  61. },
  62. created:function(){
  63. this.checkMap.actionItem.pointList.map((item)=>{
  64. // this.openItems.push(item.id);
  65. });
  66. },
  67. methods: {
  68. openChildren: function(key) {
  69. this.openItems = arrFilter(key, this.openItems);
  70. },
  71. //一键取消所有子项
  72. cancelAllChildHandle(index,selectFlag){
  73. this.checkMap.actionItem.pointList[index].selectFlag = !selectFlag;
  74. this.checkMap.actionItem.pointList[index].itemList.forEach(item=>{
  75. item.selectFlag = !selectFlag;
  76. });
  77. this.myCommit('actionItem', this.checkMap.actionItem);
  78. },
  79. changeChecked: function(i, n, selectFlag) {
  80. this.checkMap.actionItem.pointList[i].itemList[n].selectFlag = !selectFlag;
  81. const ifAllChildIsFalse = this.checkMap.actionItem.pointList[i].itemList.every(item=>item.selectFlag == false);
  82. this.checkMap.actionItem.pointList[i].selectFlag = !ifAllChildIsFalse;
  83. this.myCommit('actionItem', this.checkMap.actionItem);
  84. },
  85. btnClick: function(id) {
  86. if(id === 'ok') {
  87. const {id, pointList} = this.checkMap.actionItem;
  88. let _pointList = pointList.map((item)=>{
  89. let obj = item.itemList.find(({selectFlag}) => selectFlag);
  90. return {
  91. ...item,
  92. selectFlag: obj ? true : false
  93. }
  94. });
  95. let list = [...this.checkMap.list];
  96. let index = list.findIndex((item)=> item.id === id);
  97. list[index].pointList = _pointList;
  98. this.myCommit('list', list);
  99. }
  100. this.commit('showCheckMapDetail', false);
  101. },
  102. /**
  103. * 更新condition数据
  104. * @param {Object} key 要更新的属性
  105. * @param {Object} value 值
  106. */
  107. myCommit: function(key, value) {
  108. let data = {...this.checkMap};
  109. data[key] = value;
  110. this.commit('checkMap', data);
  111. },
  112. dispatch: function(key, data) {
  113. return this.$store.dispatch({type: 'creatingSituations/commActions', key, data});
  114. },
  115. commit: function(key,data) {
  116. this.$store.commit({type: 'creatingSituations/comChangeState', key, data});
  117. },
  118. }
  119. }
  120. </script>
  121. <style lang="less" scoped>
  122. .check-map-detail {
  123. // padding-bottom: 75rpx;
  124. width: 100%;
  125. height: 100%;
  126. .item {
  127. display: flex;
  128. flex-direction: row;
  129. border-top: 1px solid #DADEE6;
  130. padding-left: 25rpx;
  131. width: 100%;
  132. background-color: #fff;
  133. .icon-wrap {
  134. padding-top: 28.12rpx;
  135. padding-right: 23.75rpx;
  136. width: 45rpx;
  137. height: inherit;
  138. image {
  139. width: 100%;
  140. height: 12.5rpx;
  141. }
  142. }
  143. .content {
  144. position: relative;
  145. width: 100%;
  146. color: #292C33;
  147. .content-title {
  148. display: flex;
  149. flex-direction: row;
  150. align-items: center;
  151. min-height: 87.5rpx;
  152. font-size: 22.5rpx;
  153. font-weight: 500;
  154. }
  155. .children {
  156. width: 100%;
  157. .child {
  158. display: flex;
  159. flex-direction: row;
  160. justify-content: space-between;
  161. align-items: center;
  162. border-top: 1px solid #DADEE6;
  163. min-height: 87.5rpx;
  164. .child-text {
  165. width: calc(100% - 75rpx);
  166. }
  167. .check-icon-wrap {
  168. display: flex;
  169. flex-direction: row;
  170. justify-content: center;
  171. align-items: center;
  172. width: 75rpx;
  173. height: 87.5rpx;
  174. image {
  175. width: 25rpx;
  176. height: 25rpx;
  177. }
  178. }
  179. }
  180. }
  181. .checkAllBtn {
  182. display: flex;
  183. justify-content: center;
  184. align-items: center;
  185. position: absolute;
  186. right:20rpx;
  187. top:25rpx;
  188. width: 37.5rpx;
  189. height: 37.5rpx;
  190. z-index: 10;
  191. image {
  192. width: 25rpx;
  193. height: 25rpx;
  194. }
  195. }
  196. }
  197. }
  198. }
  199. </style>