searchProduct.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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></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. uni.hideLoading()
  181. }
  182. }else{
  183. _this.status = 'nomore'
  184. _this.productList = []
  185. _this.shelfPlaceCode = ''
  186. _this.total = 0
  187. _this.noDataText = '没有搜索到相关产品'
  188. }
  189. })
  190. },
  191. // 新增
  192. addItem(item){
  193. if(item.shelfProductApi&&item.shelfProductApi.enableFlag==0){
  194. uni.showToast({
  195. icon:'none',
  196. title: '此产品已被禁用,不可添加!'
  197. })
  198. return false
  199. }
  200. this.saveData(item,1)
  201. },
  202. // 修改数量
  203. updateNums(e){
  204. console.log(e)
  205. const row = this.productList.find(item => item.id == e.index)
  206. const nums = e.value
  207. const item = row.shelfCartApi || row.shelfProductApi
  208. if(item&&item.shelfCartSn){
  209. this.saveData(row,nums)
  210. }
  211. },
  212. saveData(row,nums){
  213. console.log(row,nums)
  214. // 继续修改数量
  215. uni.showLoading({
  216. title: '正在保存...'
  217. })
  218. const item = row.shelfCartApi || row.shelfProductApi
  219. const params = {
  220. shelfSn: this.shelfSn,
  221. shelfName: this.shelfName,
  222. shelfTierCode: item?item.shelfTierCode:this.layer,
  223. shelfPlaceSn: item?item.shelfPlaceSn:undefined,
  224. shelfPlaceCode: item?item.shelfPlaceCode:this.shelfPlaceCode,
  225. productSn: row.productSn,
  226. productCode: row.code,
  227. qty: nums,
  228. price: row.price,
  229. cost: row.terminalPrice,
  230. shelfCartSn: item?item.shelfCartSn:undefined
  231. }
  232. console.log(params)
  233. shelfCartSave(params).then(res => {
  234. if(res.status == 200){
  235. // this.toashMsg(res.message)
  236. if(!item){
  237. row.shelfCartApi={shelfPlaceCode:this.shelfPlaceCode}
  238. this.getProductList(true,row,row.pageNo)
  239. }else{
  240. uni.hideLoading()
  241. }
  242. }else{
  243. uni.hideLoading()
  244. }
  245. })
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="less">
  251. .productList{
  252. width: 100%;
  253. height: 100vh;
  254. .productList-search{
  255. padding: 20rpx 30rpx;
  256. background-color: #FFFFFF;
  257. .search{
  258. padding: 0.1rem;
  259. border-radius: 50rpx;
  260. border:1rpx solid #eee;
  261. .input{
  262. flex-grow: 1;
  263. padding: 4rpx;
  264. }
  265. .icon{
  266. width: 13%;
  267. text-align: center;
  268. font-size: 46rpx;
  269. color: #999;
  270. }
  271. }
  272. }
  273. .productList-body{
  274. flex-grow: 1;
  275. background-color: #fff;
  276. padding: 0 40upx;
  277. .scroll-view{
  278. height: calc(100vh - 150rpx);
  279. box-sizing: border-box;
  280. }
  281. .partList-list-box{
  282. padding: 10px 0;
  283. border-bottom: 2rpx solid #f5f5f5;
  284. .pinfo{
  285. flex-grow: 1;
  286. padding-left: 20rpx;
  287. .pname{
  288. color: #666;
  289. font-size: 26rpx;
  290. font-weight: bold;
  291. word-break: break-all;
  292. text{
  293. font-weight: normal;
  294. margin-right: 10rpx;
  295. padding: 0 10rpx;
  296. background: rgba(3, 54, 146, 0.15);
  297. border-radius: 30rpx;
  298. color: #033692;
  299. font-size: 26rpx;
  300. }
  301. }
  302. .ptxt{
  303. color: #666;
  304. font-size: 26rpx;
  305. padding: 10upx 0;
  306. }
  307. }
  308. .ptools{
  309. color: #666;
  310. font-size: 24rpx;
  311. .u-ninput{
  312. border: 2rpx solid #eee;
  313. border-radius: 50rpx;
  314. padding: 0 6rpx;
  315. }
  316. /deep/ .u-icon-disabled{
  317. background: #fff!important;
  318. }
  319. /deep/ .u-number-input{
  320. margin: 0 0;
  321. border: 2rpx solid #eee;
  322. border-top: 0;
  323. border-bottom: 0;
  324. }
  325. /deep/ .u-icon-plus, /deep/ .u-icon-minus{
  326. border-radius: 50rpx;
  327. }
  328. }
  329. }
  330. }
  331. }
  332. </style>