searchProduct.vue 7.4 KB

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