SelectProduct.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <!--
  2. * @Author: liuzhenlin 461480418@qq.ocm
  3. * @Date: 2023-02-15 10:34:49
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-03-27 16:58:46
  6. * @Description: file content
  7. * @FilePath: \oms\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. props: {
  58. selectedRows: {
  59. default: () => [],
  60. },
  61. },
  62. data() {
  63. return {
  64. selectVisible: false,
  65. checkboxList: [],
  66. queryForm: {
  67. prodName: '',
  68. pageNum: 1,
  69. pageSize: 999,
  70. type: '全部客户',
  71. },
  72. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  73. userValue: null,
  74. isallcheck: false, //全选
  75. checkedId: [],
  76. }
  77. },
  78. methods: {
  79. async getProjectList() {
  80. let params = Object.assign(this.queryForm, this.queryParams)
  81. const [err, res] = await to(productApi.getList(params))
  82. if (err) return
  83. if (res.code == 200) {
  84. if (res.data.list && res.data.list.length > 0) {
  85. this.checkboxList = res.data.list.map((itemA) => {
  86. const itemB = this.selectedRows.find((itemB) => itemB.id === itemA.id)
  87. return {
  88. ...itemA,
  89. label: `${itemA.prodName}/${itemA.prodClass}/${itemA.prodCode}`,
  90. prodNum: '1',
  91. ischeck: Boolean(itemB),
  92. }
  93. })
  94. } else {
  95. this.checkboxList = []
  96. }
  97. let allChecked = this.checkboxList.length == 0 ? false : this.checkboxList.every((el) => el.ischeck === true)
  98. if (allChecked) {
  99. this.isallcheck = true //都有 全选
  100. } else {
  101. this.isallcheck = false // 反选
  102. }
  103. }
  104. },
  105. open() {
  106. this.selectVisible = true
  107. this.getProjectList()
  108. },
  109. close() {
  110. this.selectVisible = false
  111. let selected = this.checkboxList.filter((item) => item.ischeck)
  112. this.$emit('close', selected)
  113. },
  114. radioChange(item) {
  115. item.ischeck = !item.ischeck
  116. let allChecked = this.checkboxList.length == 0 ? false : this.checkboxList.every((el) => el.ischeck === true)
  117. if (allChecked) {
  118. this.isallcheck = true //都有 全选
  119. } else {
  120. this.isallcheck = false // 反选
  121. }
  122. },
  123. // 全部
  124. checkboxChange() {
  125. this.isallcheck = !this.isallcheck
  126. this.checkboxList.forEach((el) => {
  127. el.ischeck = this.isallcheck
  128. })
  129. },
  130. },
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .tit {
  135. font-size: 26rpx;
  136. font-weight: bold;
  137. padding: 30rpx 0 0 30rpx;
  138. }
  139. .search-container {
  140. padding: 30rpx 30rpx 0 30rpx;
  141. display: flex;
  142. align-items: center;
  143. .search-input {
  144. flex: 1;
  145. }
  146. .search-btn {
  147. text-align: center;
  148. line-height: 60rpx;
  149. border-radius: 12rpx;
  150. width: 100rpx;
  151. height: 60rpx;
  152. font-size: 26rpx;
  153. margin: 0 0 0 12rpx;
  154. background: $u-primary;
  155. color: #ffffff;
  156. }
  157. }
  158. .allCheck {
  159. padding: 30rpx 0 0 30rpx;
  160. }
  161. .concat-list {
  162. padding: 0 0 20rpx 0;
  163. width: 100%;
  164. height: 900rpx;
  165. overflow: auto;
  166. margin-top: 20rpx;
  167. .radio-item {
  168. padding: 20rpx 30rpx;
  169. border-bottom: 1px solid #ccc;
  170. }
  171. }
  172. </style>