SelectProduct.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. },
  115. // 全部
  116. checkboxChange() {
  117. this.isallcheck = !this.isallcheck
  118. this.checkboxList.forEach((el) => {
  119. el.ischeck = this.isallcheck
  120. })
  121. },
  122. },
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .tit {
  127. font-size: 26rpx;
  128. font-weight: bold;
  129. padding: 30rpx 0 0 30rpx;
  130. }
  131. .search-container {
  132. padding: 30rpx 30rpx 0 30rpx;
  133. display: flex;
  134. align-items: center;
  135. .search-input {
  136. flex: 1;
  137. }
  138. .search-btn {
  139. text-align: center;
  140. line-height: 60rpx;
  141. border-radius: 12rpx;
  142. width: 100rpx;
  143. height: 60rpx;
  144. font-size: 26rpx;
  145. margin: 0 0 0 12rpx;
  146. background: $u-primary;
  147. color: #ffffff;
  148. }
  149. }
  150. .allCheck {
  151. padding: 30rpx 0 0 30rpx;
  152. }
  153. .concat-list {
  154. padding: 0 0 20rpx 0;
  155. width: 100%;
  156. height: 900rpx;
  157. overflow: auto;
  158. margin-top: 20rpx;
  159. .radio-item {
  160. padding: 20rpx 30rpx;
  161. border-bottom: 1px solid #ccc;
  162. }
  163. }
  164. </style>