SelectProduct.vue 4.7 KB

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