LossGoodsSelector.vue 7.7 KB

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