searchProduct.vue 7.3 KB

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