checkBoxPicker.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view>
  3. <u-popup v-model="isShow" @close="isShow = false" mode="bottom" safe-area-inset-bottom border-radius="20">
  4. <view class="content flex flex_column">
  5. <view class="con">
  6. <view class="choose-list u-flex u-row-between" v-for="(item, i) in list" :key="item.id" @click="getChooseItem(i)">
  7. <view>{{ item.dispName }}</view>
  8. <u-icon v-show="item.isChecked" name="checkbox-mark" color="#2979ff" size="28"></u-icon>
  9. </view>
  10. </view>
  11. <view class="btn u-flex">
  12. <view class="cancleStyle" @click="isShow = false">取消</view>
  13. <view class="confimStyle" :style="{ background: $config('primaryColor'), color: '#fff' }" @click="submit">确定</view>
  14. </view>
  15. </view>
  16. </u-popup>
  17. </view>
  18. </template>
  19. <script>
  20. import { getLookUpDatas } from '@/api/data';
  21. export default {
  22. props: {
  23. showModal: {
  24. type: Boolean,
  25. default: false
  26. },
  27. code: {
  28. type: String,
  29. default: ''
  30. },
  31. val: {
  32. type: String,
  33. default: ''
  34. }
  35. },
  36. data() {
  37. return {
  38. isShow: this.showModal,
  39. chooseObj: null,
  40. chooseFlag: -1,
  41. list: []
  42. };
  43. },
  44. methods: {
  45. getList() {
  46. if (this.code == 'SALES_BILL_STATUS') {
  47. var newList = [
  48. { id: 1099, isChecked: false, code: 'WAIT_SUBMIT', dispName: '待提交' },
  49. { id: 1100, isChecked: false, code: 'WAIT_AUDIT', dispName: '待审核' },
  50. { id: 1102, isChecked: false, code: 'WAIT_OUT_WAREHOUSE', dispName: '待出库' },
  51. { id: 1103, isChecked: false, code: 'FINISH', dispName: '已完结' }
  52. ];
  53. if (this.val) {
  54. //勾选上次选中值
  55. let valArr = this.val.split(',');
  56. newList.forEach(con => {
  57. valArr.forEach(item => {
  58. if (con.code == item) {
  59. con.isChecked = true;
  60. } else {
  61. con.isChecked = false;
  62. }
  63. });
  64. });
  65. }
  66. this.list = newList;
  67. } else {
  68. getLookUpDatas({
  69. lookupCode: this.code,
  70. pageNo: 1,
  71. pageSize: 1000
  72. }).then(result => {
  73. if (result && result.status == 200) {
  74. if (this.val) {
  75. //勾选上次选中值
  76. let valArr = this.val.split(',');
  77. result.data.list.forEach(con => {
  78. valArr.forEach(item => {
  79. if (con.code == item) {
  80. con.isChecked = true;
  81. } else {
  82. con.isChecked = false;
  83. }
  84. });
  85. });
  86. } else {
  87. result.data.list.forEach(con => {
  88. con.isChecked = false;
  89. });
  90. }
  91. this.list = result.data.list;
  92. }
  93. });
  94. }
  95. },
  96. submit(index) {
  97. let arr = [];
  98. this.list.forEach(con => {
  99. if (con.isChecked) {
  100. arr.push(con);
  101. }
  102. });
  103. this.$emit('chooseCon', arr);
  104. this.isShow = false;
  105. },
  106. getChooseItem(index) {
  107. this.list[index].isChecked = !this.list[index].isChecked;
  108. }
  109. },
  110. watch: {
  111. // 父页面传过来的弹框状态
  112. showModal(newValue, oldValue) {
  113. this.isShow = newValue;
  114. },
  115. // 重定义的弹框状态
  116. isShow(newValue, oldValue) {
  117. if (!newValue) {
  118. this.$emit('close');
  119. } else {
  120. this.getList();
  121. }
  122. }
  123. }
  124. };
  125. </script>
  126. <style lang="scss" scoped>
  127. .content {
  128. width: 100%;
  129. height: 100%;
  130. .con {
  131. flex-grow: 1;
  132. overflow: auto;
  133. padding: 0 40rpx;
  134. .choose-list {
  135. border-bottom: 1rpx solid #efefef;
  136. padding: 20rpx 0;
  137. &:last-child {
  138. border-bottom: 0rpx solid #efefef;
  139. }
  140. }
  141. }
  142. .btn {
  143. border-top: 1rpx solid #efefef;
  144. .cancleStyle,
  145. .confimStyle {
  146. width: 50%;
  147. text-align: center;
  148. height: 89rpx;
  149. line-height: 89rpx;
  150. text-align: center;
  151. }
  152. }
  153. }
  154. </style>