searchProduct.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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">{{item.shelfCartApi.shelfPlaceCode}}</text>
  31. {{item.productName}}
  32. </view>
  33. <view class="ptxt flex justify_between">
  34. <text>{{item.code}}</text>
  35. <view v-if="item.shelfProductApi">
  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 :index="item.id" @blur="updateNums" @minus="updateNums" @plus="updateNums" color="#000" bg-color="#fff" v-model="item.shelfCartApi.qty" :min="0"></u-number-box>
  46. </view>
  47. <view v-else>
  48. <u-button @click="addItem(item)" plain style="width: 40rpx;height: 40rpx;line-height: 40rpx;" 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">
  56. <u-empty v-if="status!='loading'" :src="`/static/${$config('themePath')}/def_no_data@3x.png`" icon-size="180" :text="noDataText" mode="list" :margin-top="50"></u-empty>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { queryProduct, shelfCartSave } from '@/api/shelfCart'
  63. export default {
  64. data() {
  65. return {
  66. shelfSn: null,
  67. shelfName: '',
  68. layer:'',
  69. queryWord: '',
  70. productList: [],
  71. total: 0, // 列表总数
  72. noDataText: '暂无产品',
  73. status: 'nomore',
  74. shelfPlaceCode: ''
  75. }
  76. },
  77. onLoad(options) {
  78. this.shelfSn = options.shelfSn
  79. this.layer = options.layer
  80. this.shelfName = options.shelfName
  81. uni.setNavigationBarTitle({
  82. title: '按产品编码搜索——' +this.layer+'层'
  83. })
  84. },
  85. onNavigationBarButtonTap(e) {
  86. this.scanProduct()
  87. },
  88. methods: {
  89. scanProduct(){
  90. uni.redirectTo({
  91. url: "/pages/batchShelves/scanProduct?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName
  92. })
  93. },
  94. clearSearch(){
  95. this.queryWord = ''
  96. this.productList = []
  97. this.getProductList()
  98. },
  99. getProductList(){
  100. const _this = this
  101. if(this.queryWord == ''){
  102. this.productList = []
  103. return
  104. }
  105. uni.showLoading({
  106. title: "正在查询..."
  107. })
  108. let params = {
  109. code: this.queryWord,
  110. shelfSn: this.shelfSn,
  111. shelfTierCode: this.layer
  112. }
  113. console.log(params)
  114. queryProduct(params).then(res => {
  115. console.log(res)
  116. if(res.status == 200&&res.data){
  117. this.productList = res.data.productList.slice(0,20)
  118. this.shelfPlaceCode = res.data.shelfTierCode
  119. this.total = res.data.productList.length
  120. }else{
  121. this.noDataText = '查询最近20条数据,没有匹配到相关产品,请输入更多内容'
  122. }
  123. uni.hideLoading()
  124. })
  125. },
  126. // 新增
  127. addItem(item){
  128. this.saveData(item,1)
  129. },
  130. // 修改数量
  131. updateNums(e){
  132. console.log(e)
  133. const row = this.productList.find(item => item.id == e.index)
  134. const nums = e.value
  135. this.saveData(row,nums)
  136. },
  137. saveData(row,nums){
  138. // 继续修改数量
  139. uni.showLoading({
  140. title: '正在保存...'
  141. })
  142. const params = {
  143. shelfSn: this.shelfSn,
  144. shelfName: this.shelfName,
  145. shelfTierCode: row.shelfCartApi?row.shelfCartApi.shelfTierCode:this.layer,
  146. shelfPlaceSn: row.shelfCartApi?row.shelfCartApi.shelfPlaceSn:'',
  147. shelfPlaceCode: row.shelfCartApi?row.shelfCartApi.shelfPlaceCode:this.shelfPlaceCode,
  148. productSn: row.productSn,
  149. productCode: row.code,
  150. qty: nums,
  151. price: row.price,
  152. cost: row.cost,
  153. shelfCartSn: row.shelfCartApi?row.shelfCartApi.shelfCartSn:''
  154. }
  155. console.log(params)
  156. shelfCartSave(params).then(res => {
  157. if(res.status == 200){
  158. this.toashMsg(res.message)
  159. this.getProductList()
  160. }
  161. uni.hideLoading()
  162. })
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="less">
  168. .productList{
  169. width: 100%;
  170. height: 100vh;
  171. .productList-search{
  172. padding: 20rpx 30rpx;
  173. background-color: #FFFFFF;
  174. .search{
  175. padding: 0.1rem;
  176. border-radius: 50rpx;
  177. border:0.1rpx solid #eee;
  178. .input{
  179. flex-grow: 1;
  180. padding: 0.1rpx;
  181. }
  182. .icon{
  183. width: 13%;
  184. text-align: center;
  185. font-size: 46rpx;
  186. color: #999;
  187. }
  188. }
  189. }
  190. .productList-body{
  191. flex-grow: 1;
  192. background-color: #fff;
  193. padding: 0 40upx;
  194. overflow: auto;
  195. .partList-list-box{
  196. padding: 10px 0;
  197. border-bottom: 2rpx solid #f5f5f5;
  198. .pinfo{
  199. flex-grow: 1;
  200. padding-left: 20rpx;
  201. .pname{
  202. color: #191919;
  203. font-size: 24rpx;
  204. text{
  205. font-weight: normal;
  206. margin-right: 10rpx;
  207. padding: 0 10rpx;
  208. background: rgba(3, 54, 146, 0.15);
  209. border-radius: 30rpx;
  210. color: #033692;
  211. font-size: 24rpx;
  212. }
  213. }
  214. .ptxt{
  215. color: #666;
  216. font-size: 24rpx;
  217. padding: 10upx 0;
  218. }
  219. }
  220. .ptools{
  221. color: #666;
  222. font-size: 24rpx;
  223. .u-ninput{
  224. border: 2rpx solid #eee;
  225. border-radius: 50rpx;
  226. padding: 0 6rpx;
  227. }
  228. /deep/ .u-icon-disabled{
  229. background: #fff!important;
  230. }
  231. /deep/ .u-number-input{
  232. margin: 0 0;
  233. border: 2rpx solid #eee;
  234. border-top: 0;
  235. border-bottom: 0;
  236. }
  237. /deep/ .u-icon-plus, /deep/ .u-icon-minus{
  238. border-radius: 50rpx;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. </style>