searchProduct.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="productList flex flex_column">
  3. <view class="productList-search">
  4. <view class="search flex align_center">
  5. <view class="input">
  6. <u-search
  7. focus
  8. v-model="queryWord"
  9. @input="$u.debounce(getProductList, 800)"
  10. @custom="$u.debounce(getProductList, 500)"
  11. @search="$u.debounce(getProductList, 500)"
  12. @clear="clearSearch"
  13. bg-color="#fff"
  14. :show-action="false"
  15. placeholder="请输入产品编码查询"></u-search>
  16. </view>
  17. <!-- <view class="icon" @click="toScan">
  18. <u-icon name="scan"></u-icon>
  19. </view> -->
  20. </view>
  21. </view>
  22. <view class="productList-body">
  23. <view class="partList-list-box" v-for="item in productList" :key="item.shelfCartSn">
  24. <view class="flex align_center flex_1">
  25. <view class="pimgs">
  26. <u-image :src="item.images?item.images:`../../static/${$config('themePath')}/def_img@2x.png`" width="120" height="120" border-radius="10"></u-image>
  27. </view>
  28. <view class="pinfo">
  29. <view class="pname">
  30. <text v-if="item.shelfCartApi&&item.shelfCartApi.shelfPlaceCode">{{item.shelfCartApi.shelfPlaceCode}}</text>
  31. {{item.productName}}
  32. </view>
  33. <view class="ptxt flex justify_between">
  34. <text>{{item.code}}</text>
  35. <view v-if="item.shelfProductApi">
  36. 可用库存:<text>{{item.shelfProductApi.qty}}</text>{{item.unit}}
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="ptools flex align_center justify_between">
  42. <view></view>
  43. <view class="pcurnums flex align_center">
  44. <view class="u-ninput" v-if="item.shelfCartApi">
  45. <u-number-box :index="item.id" @blur="updateNums" @minus="updateNums" @plus="updateNums" color="#000" bg-color="#fff" v-model="item.shelfCartApi.qty" :min="0"></u-number-box>
  46. </view>
  47. <view v-else>
  48. <u-button @click="addItem(item)" plain style="width: 40rpx;height: 40rpx;line-height: 40rpx;" size="mini" shape="circle">
  49. <u-icon name="plus"></u-icon>
  50. </u-button>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view v-if="productList&&productList.length==0">
  56. <u-empty v-if="status!='loading'" :src="`/static/${$config('themePath')}/def_no_data@3x.png`" icon-size="180" :text="noDataText" mode="list" :margin-top="50"></u-empty>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { queryProduct, shelfCartSave } from '@/api/shelfCart'
  63. export default {
  64. data() {
  65. return {
  66. shelfSn: null,
  67. shelfName: '',
  68. layer:'',
  69. queryWord: '',
  70. productList: [],
  71. total: 0, // 列表总数
  72. noDataText: '暂无产品',
  73. status: 'nomore',
  74. shelfPlaceCode: ''
  75. }
  76. },
  77. onLoad(options) {
  78. this.shelfSn = options.shelfSn
  79. this.layer = options.layer
  80. this.shelfName = options.shelfName
  81. uni.setNavigationBarTitle({
  82. title: '按产品编码搜索——' +this.layer+'层'
  83. })
  84. },
  85. onNavigationBarButtonTap(e) {
  86. this.scanProduct()
  87. },
  88. methods: {
  89. scanProduct(){
  90. uni.redirectTo({
  91. url: "/pages/batchShelves/scanProduct?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName
  92. })
  93. },
  94. clearSearch(){
  95. this.queryWord = ''
  96. this.productList = []
  97. this.getProductList()
  98. },
  99. getProductList(){
  100. const _this = this
  101. if(this.queryWord == ''){
  102. this.productList = []
  103. return
  104. }
  105. uni.showLoading({
  106. title: "正在查询..."
  107. })
  108. let params = {
  109. code: this.queryWord,
  110. shelfSn: this.shelfSn,
  111. shelfTierCode: this.layer
  112. }
  113. console.log(params)
  114. queryProduct(params).then(res => {
  115. console.log(res)
  116. if(res.status == 200&&res.data){
  117. this.productList = res.data.productList.slice(0,20)
  118. this.shelfPlaceCode = res.data.shelfTierCode
  119. this.total = res.data.productList.length
  120. }else{
  121. this.noDataText = '查询最近20条数据,没有匹配到相关产品,请输入更多内容'
  122. }
  123. uni.hideLoading()
  124. })
  125. },
  126. // 新增
  127. addItem(item){
  128. this.saveData(item,1)
  129. },
  130. // 修改数量
  131. updateNums(e){
  132. console.log(e)
  133. const row = this.productList.find(item => item.id == e.index)
  134. const nums = e.value
  135. this.saveData(row,nums)
  136. },
  137. saveData(row,nums){
  138. // 继续修改数量
  139. uni.showLoading({
  140. title: '正在保存...'
  141. })
  142. const item = row.shelfCartApi || row.shelfProductApi
  143. const params = {
  144. shelfSn: this.shelfSn,
  145. shelfName: this.shelfName,
  146. shelfTierCode: item?item.shelfTierCode:this.layer,
  147. shelfPlaceSn: item?item.shelfPlaceSn:'',
  148. shelfPlaceCode: item?item.shelfPlaceCode:this.shelfPlaceCode,
  149. productSn: row.productSn,
  150. productCode: row.code,
  151. qty: nums,
  152. price: row.price,
  153. cost: row.cost,
  154. shelfCartSn: item?item.shelfCartSn:''
  155. }
  156. console.log(params)
  157. shelfCartSave(params).then(res => {
  158. if(res.status == 200){
  159. this.toashMsg(res.message)
  160. this.getProductList()
  161. }
  162. uni.hideLoading()
  163. })
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="less">
  169. .productList{
  170. width: 100%;
  171. height: 100vh;
  172. .productList-search{
  173. padding: 20rpx 30rpx;
  174. background-color: #FFFFFF;
  175. .search{
  176. padding: 0.1rem;
  177. border-radius: 50rpx;
  178. border:0.1rpx solid #eee;
  179. .input{
  180. flex-grow: 1;
  181. padding: 0.1rpx;
  182. }
  183. .icon{
  184. width: 13%;
  185. text-align: center;
  186. font-size: 46rpx;
  187. color: #999;
  188. }
  189. }
  190. }
  191. .productList-body{
  192. flex-grow: 1;
  193. background-color: #fff;
  194. padding: 0 40upx;
  195. overflow: auto;
  196. .partList-list-box{
  197. padding: 10px 0;
  198. border-bottom: 2rpx solid #f5f5f5;
  199. .pinfo{
  200. flex-grow: 1;
  201. padding-left: 20rpx;
  202. .pname{
  203. color: #191919;
  204. font-size: 24rpx;
  205. text{
  206. font-weight: normal;
  207. margin-right: 10rpx;
  208. padding: 0 10rpx;
  209. background: rgba(3, 54, 146, 0.15);
  210. border-radius: 30rpx;
  211. color: #033692;
  212. font-size: 24rpx;
  213. }
  214. }
  215. .ptxt{
  216. color: #666;
  217. font-size: 24rpx;
  218. padding: 10upx 0;
  219. }
  220. }
  221. .ptools{
  222. color: #666;
  223. font-size: 24rpx;
  224. .u-ninput{
  225. border: 2rpx solid #eee;
  226. border-radius: 50rpx;
  227. padding: 0 6rpx;
  228. }
  229. /deep/ .u-icon-disabled{
  230. background: #fff!important;
  231. }
  232. /deep/ .u-number-input{
  233. margin: 0 0;
  234. border: 2rpx solid #eee;
  235. border-top: 0;
  236. border-bottom: 0;
  237. }
  238. /deep/ .u-icon-plus, /deep/ .u-icon-minus{
  239. border-radius: 50rpx;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. </style>