SelectProduct.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!--
  2. * @Author: liuzhenlin 461480418@qq.ocm
  3. * @Date: 2023-02-15 10:34:49
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-02-20 18:20:37
  6. * @Description: file content
  7. * @FilePath: \frontend_mobile\components\SelectProduct.vue
  8. -->
  9. <template>
  10. <view>
  11. <u-popup :show="selectVisible" @close="close">
  12. <view class="select-header">
  13. <view class="tit">选择产品</view>
  14. <view class="save-btn" @click="close()">保存</view>
  15. </view>
  16. <view class="search-container">
  17. <view class="search-input">
  18. <u-input
  19. clearable
  20. placeholderStyle="font-size:26rpx"
  21. :customStyle="{ height: '66rpx' }"
  22. v-model="queryForm.prodName"
  23. prefixIcon="search"
  24. prefixIconStyle="font-size: 22px;color: #909399"
  25. placeholder="请输入产品名称"
  26. shape="circle"
  27. @input="getProjectList()"
  28. border="surround"></u-input>
  29. </view>
  30. </view>
  31. <view class="tit">产品名称/产品类别/产品型号</view>
  32. <view class="flex_l allCheck">
  33. <u-checkbox-group placement="column">
  34. <u-checkbox label="全部" :checked="isallcheck" @change="checkboxChange"></u-checkbox>
  35. </u-checkbox-group>
  36. </view>
  37. <u-empty mode="list" v-if="checkboxList.length == 0"></u-empty>
  38. <view class="concat-list" v-else>
  39. <u-checkbox-group v-model="userValue" placement="column">
  40. <view class="radio-item" v-for="item in checkboxList" :key="item.id">
  41. <u-checkbox
  42. :label="item.label"
  43. :name="item.id"
  44. :checked="item.ischeck"
  45. @change="radioChange(item)"></u-checkbox>
  46. </view>
  47. </u-checkbox-group>
  48. </view>
  49. </u-popup>
  50. </view>
  51. </template>
  52. <script>
  53. import productApi from '@/api/base/product'
  54. import to from 'await-to-js'
  55. export default {
  56. name: 'OmsCustomerContact',
  57. data() {
  58. return {
  59. selectVisible: false,
  60. checkboxList: [],
  61. queryForm: {
  62. prodName: '',
  63. pageNum: 1,
  64. pageSize: 999,
  65. type: '全部客户',
  66. },
  67. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  68. userValue: null,
  69. isallcheck: false, //全选
  70. checkedId: [],
  71. }
  72. },
  73. methods: {
  74. async getProjectList() {
  75. let params = Object.assign(this.queryForm, this.queryParams)
  76. const [err, res] = await to(productApi.getList(params))
  77. if (err) return
  78. if (res.code == 200) {
  79. if (res.data.list && res.data.list.length > 0) {
  80. this.checkboxList = res.data.list.map((item) => ({
  81. ...item,
  82. label: `${item.prodName}/${item.prodClass}/${item.prodCode}`,
  83. ischeck: false,
  84. prodNum: '1',
  85. }))
  86. } else {
  87. this.checkboxList = []
  88. }
  89. let allChecked = this.checkboxList.length == 0 ? false : this.checkboxList.every((el) => el.ischeck === true)
  90. if (allChecked) {
  91. this.isallcheck = true //都有 全选
  92. } else {
  93. this.isallcheck = false // 反选
  94. }
  95. }
  96. },
  97. open() {
  98. this.selectVisible = true
  99. this.getProjectList()
  100. },
  101. close() {
  102. this.selectVisible = false
  103. let selected = this.checkboxList.filter((item) => item.ischeck)
  104. this.$emit('close', selected)
  105. },
  106. radioChange(item) {
  107. item.ischeck = !item.ischeck
  108. let allChecked = this.checkboxList.length == 0 ? false : this.checkboxList.every((el) => el.ischeck === true)
  109. if (allChecked) {
  110. this.isallcheck = true //都有 全选
  111. } else {
  112. this.isallcheck = false // 反选
  113. }
  114. console.log(' this.isallcheck', this.isallcheck)
  115. },
  116. // 全部
  117. checkboxChange() {
  118. this.isallcheck = !this.isallcheck
  119. this.checkboxList.forEach((el) => {
  120. el.ischeck = this.isallcheck
  121. })
  122. console.log(this.checkboxList)
  123. },
  124. },
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .tit {
  129. font-size: 26rpx;
  130. font-weight: bold;
  131. padding: 30rpx 0 0 30rpx;
  132. }
  133. .search-container {
  134. padding: 30rpx 30rpx 0 30rpx;
  135. display: flex;
  136. align-items: center;
  137. .search-input {
  138. flex: 1;
  139. }
  140. .search-btn {
  141. text-align: center;
  142. line-height: 60rpx;
  143. border-radius: 12rpx;
  144. width: 100rpx;
  145. height: 60rpx;
  146. font-size: 26rpx;
  147. margin: 0 0 0 12rpx;
  148. background: $u-primary;
  149. color: #ffffff;
  150. }
  151. }
  152. .allCheck {
  153. padding: 30rpx 0 0 30rpx;
  154. }
  155. .concat-list {
  156. padding: 0 0 20rpx 0;
  157. width: 100%;
  158. height: 900rpx;
  159. overflow: auto;
  160. margin-top: 20rpx;
  161. .radio-item {
  162. padding: 20rpx 30rpx;
  163. border-bottom: 1px solid #ccc;
  164. }
  165. }
  166. </style>