searchProduct.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. <scroll-view scroll-y class="scroll-view" @scrolltolower="onreachBottom">
  22. <view v-if="status == 'loading'"><u-loadmore :status="status" :load-text="loadText" /></view>
  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.shelfProductApi&&item.shelfProductApi.enableFlag==1">
  37. 可用库存:<text>{{item.shelfProductApi.qty}}</text>{{item.unit}}
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="ptools flex align_center justify_between">
  43. <view></view>
  44. <view class="pcurnums flex align_center">
  45. <view class="u-ninput" v-if="item.shelfCartApi">
  46. <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>
  47. </view>
  48. <view v-else>
  49. <u-button :loading="status == 'loading'" @click="addItem(item)" plain style="height: 50rpx;line-height: 50rpx;" size="mini" shape="circle">
  50. <u-icon name="plus"></u-icon> 添加
  51. </u-button>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view v-if="productList && productList.length == 0 && status == 'nomore'">
  57. <u-empty :text="noDataText" mode="list" :img-width="200" :margin-top="60"></u-empty>
  58. </view>
  59. <view style="padding: 20upx;" v-if="productList.length && status != 'nomore'">
  60. <u-loadmore :status="status" :load-text="loadText" />
  61. </view>
  62. </scroll-view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import { queryProductPage, shelfCartSave } from '@/api/shelfCart'
  68. export default {
  69. data() {
  70. return {
  71. shelfSn: null,
  72. shelfName: '',
  73. layer:'',
  74. queryWord: '',
  75. productList: [],
  76. pageNo:1,
  77. pageSize: 10,
  78. total: 0, // 列表总数
  79. noDataText: '暂无产品',
  80. status: 'nomore',
  81. shelfPlaceCode: '',
  82. fromPage: null,
  83. loadText: {
  84. loading: '努力加载中',
  85. loadmore: '没有更多了'
  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. console.log(e)
  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. // 加载更多
  118. onreachBottom () {
  119. if(this.productList.length <this.total ){
  120. this.pageNo++
  121. this.getProductList()
  122. }else{
  123. this.status = "nomore"
  124. }
  125. },
  126. scanProduct(){
  127. uni.redirectTo({
  128. url: "/pages/batchShelves/scanProduct?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName+'&customerSn='+this.customerSn+'&from='+this.fromPage
  129. })
  130. },
  131. clearSearch(){
  132. this.queryWord = ''
  133. this.productList = []
  134. this.getProductList()
  135. },
  136. getProductList(){
  137. const _this = this
  138. if(this.queryWord == ''){
  139. this.productList = []
  140. return
  141. }
  142. let params = {
  143. pageNo:this.pageNo,
  144. pageSize:this.pageSize,
  145. code: this.$u.trim(this.queryWord),
  146. shelfSn: this.shelfSn,
  147. shelfTierCode: this.layer
  148. }
  149. console.log(params)
  150. this.status = 'loading'
  151. queryProductPage(params).then(res => {
  152. if(res.status == 200&&res.data&&res.data.page&&res.data.page.list&&res.data.page.list.length){
  153. _this.shelfPlaceCode = res.data.shelfPlaceCode
  154. let list = res.data.page.list
  155. console.log(list)
  156. if (list && list.length){
  157. // 分页 拼接数据
  158. if (_this.pageNo != 1) {
  159. _this.productList = _this.productList ? _this.productList.concat(list) : list
  160. } else {
  161. _this.productList = list
  162. }
  163. _this.total = res.data.page.count
  164. if (_this.productList.length == res.data.page.count) {
  165. _this.status = 'nomore'
  166. } else {
  167. _this.status = 'loadmore'
  168. }
  169. } else {
  170. _this.productList = list || []
  171. _this.total = 0
  172. _this.status = 'nomore'
  173. }
  174. _this.noDataText = '暂无匹配产品'
  175. }else{
  176. _this.status = 'nomore'
  177. _this.productList = []
  178. _this.shelfPlaceCode = ''
  179. _this.total = 0
  180. _this.noDataText = '没有搜索到相关产品'
  181. }
  182. })
  183. },
  184. // 新增
  185. addItem(item){
  186. if(item.shelfProductApi&&item.shelfProductApi.enableFlag==0){
  187. uni.showToast({
  188. icon:'none',
  189. title: '此产品已被禁用,不可添加!'
  190. })
  191. return false
  192. }
  193. this.saveData(item,1)
  194. },
  195. // 修改数量
  196. updateNums(e){
  197. console.log(e)
  198. const row = this.productList.find(item => item.id == e.index)
  199. const nums = e.value
  200. this.saveData(row,nums)
  201. },
  202. saveData(row,nums){
  203. // 继续修改数量
  204. uni.showLoading({
  205. title: '正在保存...'
  206. })
  207. const item = row.shelfCartApi || row.shelfProductApi
  208. const params = {
  209. shelfSn: this.shelfSn,
  210. shelfName: this.shelfName,
  211. shelfTierCode: item?item.shelfTierCode:this.layer,
  212. shelfPlaceSn: item?item.shelfPlaceSn:undefined,
  213. shelfPlaceCode: item?item.shelfPlaceCode:this.shelfPlaceCode,
  214. productSn: row.productSn,
  215. productCode: row.code,
  216. qty: nums,
  217. price: row.price,
  218. cost: row.terminalPrice,
  219. shelfCartSn: item?item.shelfCartSn:undefined
  220. }
  221. console.log(params)
  222. shelfCartSave(params).then(res => {
  223. uni.hideLoading()
  224. if(res.status == 200){
  225. // this.toashMsg(res.message)
  226. this.getProductList()
  227. }
  228. })
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="less">
  234. .productList{
  235. width: 100%;
  236. height: 100vh;
  237. .productList-search{
  238. padding: 20rpx 30rpx;
  239. background-color: #FFFFFF;
  240. .search{
  241. padding: 0.1rem;
  242. border-radius: 50rpx;
  243. border:1rpx solid #eee;
  244. .input{
  245. flex-grow: 1;
  246. padding: 4rpx;
  247. }
  248. .icon{
  249. width: 13%;
  250. text-align: center;
  251. font-size: 46rpx;
  252. color: #999;
  253. }
  254. }
  255. }
  256. .productList-body{
  257. flex-grow: 1;
  258. background-color: #fff;
  259. padding: 0 40upx;
  260. .scroll-view{
  261. height: calc(100vh - 180rpx);
  262. box-sizing: border-box;
  263. }
  264. .partList-list-box{
  265. padding: 10px 0;
  266. border-bottom: 2rpx solid #f5f5f5;
  267. .pinfo{
  268. flex-grow: 1;
  269. padding-left: 20rpx;
  270. .pname{
  271. color: #666;
  272. font-size: 26rpx;
  273. font-weight: bold;
  274. word-break: break-all;
  275. text{
  276. font-weight: normal;
  277. margin-right: 10rpx;
  278. padding: 0 10rpx;
  279. background: rgba(3, 54, 146, 0.15);
  280. border-radius: 30rpx;
  281. color: #033692;
  282. font-size: 26rpx;
  283. }
  284. }
  285. .ptxt{
  286. color: #666;
  287. font-size: 26rpx;
  288. padding: 10upx 0;
  289. }
  290. }
  291. .ptools{
  292. color: #666;
  293. font-size: 24rpx;
  294. .u-ninput{
  295. border: 2rpx solid #eee;
  296. border-radius: 50rpx;
  297. padding: 0 6rpx;
  298. }
  299. /deep/ .u-icon-disabled{
  300. background: #fff!important;
  301. }
  302. /deep/ .u-number-input{
  303. margin: 0 0;
  304. border: 2rpx solid #eee;
  305. border-top: 0;
  306. border-bottom: 0;
  307. }
  308. /deep/ .u-icon-plus, /deep/ .u-icon-minus{
  309. border-radius: 50rpx;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. </style>