WareHouseGoodsSelector.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view>
  3. <u-form-item label="商品名称" :prop="'wareHouse[' + rowIndex + '].tradeName'" :required="true">
  4. <view class="goods-input-wrap">
  5. <u--input class="goods-input" :value="currentValue" placeholder="请输入或选择商品名称" :disabled="disabled"
  6. @input="handleManualInput"></u--input>
  7. <el-button class="goods-select-btn" type="primary" plain :disabled="disabled" @click="openPicker">
  8. 选择
  9. </el-button>
  10. </view>
  11. </u-form-item>
  12. <view class="selector-mask" :class="{ show: visible }" @tap="closePicker"></view>
  13. <view class="selector-panel" :class="{ show: visible }">
  14. <view class="selector-header">
  15. <view class="selector-action" @tap="closePicker">取消</view>
  16. <view class="selector-title">选择商品</view>
  17. <view class="selector-action selector-action-placeholder">取消</view>
  18. </view>
  19. <view class="selector-search">
  20. <u-search :show-action="false" v-model="keyword" placeholder="搜索商品名称"></u-search>
  21. </view>
  22. <scroll-view scroll-y class="selector-list">
  23. <view v-if="loading" class="selector-state">加载中...</view>
  24. <view v-else-if="filteredList.length === 0" class="selector-state">暂无可选商品</view>
  25. <view v-else class="selector-list-inner">
  26. <view class="selector-card" v-for="item in filteredList" :key="item.id || item.tradeName"
  27. @tap="selectItem(item)">
  28. <view class="selector-name">{{ item.tradeName }}</view>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import WareHouseService from '@/api/psi/WareHouseService'
  37. export default {
  38. name: 'WareHouseGoodsSelector',
  39. props: {
  40. rowIndex: Number,
  41. inputForm: Object,
  42. disabled: Boolean
  43. },
  44. data() {
  45. return {
  46. visible: false,
  47. loading: false,
  48. keyword: '',
  49. goodsList: [],
  50. wareHouseService: null
  51. }
  52. },
  53. computed: {
  54. currentRow() {
  55. return (this.inputForm.wareHouse || [])[this.rowIndex] || {}
  56. },
  57. currentValue() {
  58. return this.currentRow.tradeName || ''
  59. },
  60. filteredList() {
  61. const keyword = (this.keyword || '').trim().toLowerCase()
  62. if (!keyword) {
  63. return this.goodsList
  64. }
  65. return this.goodsList.filter(item => (item.tradeName || '').toLowerCase().includes(keyword))
  66. }
  67. },
  68. created() {
  69. this.wareHouseService = new WareHouseService()
  70. },
  71. methods: {
  72. isEmpty(value) {
  73. if (value === null || value === undefined) {
  74. return true
  75. }
  76. if (typeof value === 'string' && value.trim() === '') {
  77. return true
  78. }
  79. if (Array.isArray(value) && value.length === 0) {
  80. return true
  81. }
  82. return false
  83. },
  84. handleManualInput(value) {
  85. if (this.disabled) {
  86. return
  87. }
  88. const rows = (this.inputForm && this.inputForm.wareHouse) || []
  89. const row = rows[this.rowIndex]
  90. if (!row) {
  91. return
  92. }
  93. this.$set(row, 'tradeName', value)
  94. },
  95. async openPicker() {
  96. if (this.disabled) {
  97. return
  98. }
  99. if (this.isEmpty(this.currentRow.wareHouseTypeId)) {
  100. uni.showToast({
  101. title: '请先选择入库类型',
  102. icon: 'none'
  103. })
  104. return
  105. }
  106. this.visible = true
  107. this.keyword = ''
  108. await this.loadGoodsList()
  109. },
  110. closePicker() {
  111. this.visible = false
  112. },
  113. async loadGoodsList() {
  114. this.loading = true
  115. try {
  116. const data = await this.wareHouseService.findTradeByTypeId(this.currentRow.wareHouseTypeId)
  117. this.goodsList = (data || []).map(item => ({
  118. ...item,
  119. tradeName: item.tradeName || ''
  120. }))
  121. } catch (e) {
  122. this.goodsList = []
  123. uni.showToast({
  124. title: '商品数据加载失败',
  125. icon: 'none'
  126. })
  127. } finally {
  128. this.loading = false
  129. }
  130. },
  131. selectItem(item) {
  132. this.$emit('selected', {
  133. index: this.rowIndex,
  134. item
  135. })
  136. this.closePicker()
  137. }
  138. }
  139. }
  140. </script>
  141. <style scoped>
  142. .goods-input-wrap {
  143. display: flex;
  144. align-items: center;
  145. width: 100%;
  146. gap: 16rpx;
  147. }
  148. .goods-input {
  149. flex: 1;
  150. min-width: 0;
  151. }
  152. .goods-select-btn {
  153. flex: 0 0 132rpx;
  154. width: 132rpx;
  155. }
  156. .selector-mask {
  157. position: fixed;
  158. inset: 0;
  159. background: rgba(0, 0, 0, 0.35);
  160. opacity: 0;
  161. visibility: hidden;
  162. transition: all 0.25s ease;
  163. z-index: 1000;
  164. }
  165. .selector-mask.show {
  166. opacity: 1;
  167. visibility: visible;
  168. }
  169. .selector-panel {
  170. position: fixed;
  171. left: 0;
  172. right: 0;
  173. bottom: 0;
  174. height: 68vh;
  175. background: #f7f9fc;
  176. border-radius: 28rpx 28rpx 0 0;
  177. transform: translateY(100%);
  178. transition: transform 0.25s ease;
  179. z-index: 1001;
  180. display: flex;
  181. flex-direction: column;
  182. }
  183. .selector-panel.show {
  184. transform: translateY(0);
  185. }
  186. .selector-header {
  187. display: flex;
  188. align-items: center;
  189. justify-content: space-between;
  190. padding: 28rpx 32rpx 16rpx;
  191. background: #fff;
  192. border-bottom: 1rpx solid #eef2f7;
  193. }
  194. .selector-title {
  195. font-size: 32rpx;
  196. font-weight: 600;
  197. color: #1f2937;
  198. }
  199. .selector-action {
  200. min-width: 80rpx;
  201. font-size: 28rpx;
  202. color: #2979ff;
  203. }
  204. .selector-action-placeholder {
  205. opacity: 0;
  206. }
  207. .selector-search {
  208. padding: 20rpx 24rpx 8rpx;
  209. background: #fff;
  210. }
  211. .selector-list {
  212. flex: 1;
  213. padding: 16rpx 24rpx 32rpx;
  214. }
  215. .selector-list-inner {
  216. display: flex;
  217. flex-direction: column;
  218. gap: 16rpx;
  219. }
  220. .selector-state {
  221. padding-top: 120rpx;
  222. text-align: center;
  223. font-size: 28rpx;
  224. color: #94a3b8;
  225. }
  226. .selector-card {
  227. background: #fff;
  228. border-radius: 20rpx;
  229. padding: 24rpx;
  230. box-shadow: 0 8rpx 24rpx rgba(15, 23, 42, 0.06);
  231. }
  232. .selector-name {
  233. font-size: 30rpx;
  234. font-weight: 600;
  235. color: #0f172a;
  236. }
  237. </style>