searchProduct.vue 8.9 KB

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