SelectProduct.vue 5.0 KB

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