checkMapDetail.vue 5.3 KB

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