searchProduct.vue 7.7 KB

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