GoodsbyWarehouse.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <template>
  2. <view>
  3. <view class="search-view">
  4. <u-search
  5. @custom="searchList()"
  6. @search="searchList()"
  7. @clear="searchList()"
  8. action-text="搜索"
  9. :clearabled="true"
  10. placeholder="请输入商品名称"
  11. v-model="keyword"
  12. ></u-search>
  13. </view>
  14. <view class="main-view clearfix">
  15. <view class="left-view float_left">
  16. <scroll-view scroll-y="true" class="left-scroll">
  17. <view class="cate-li" :class="[!category_id ? 'cate-on' : '']" @click="changeCate(0)">全部</view>
  18. <view
  19. class="cate-li ellipsis"
  20. v-for="(item, index) in category_list"
  21. :key="index"
  22. @click="changeCate(item.id)"
  23. :class="[category_id === item.id ? 'cate-on' : '']"
  24. >
  25. {{ item.title }}
  26. </view>
  27. </scroll-view>
  28. </view>
  29. <view class="rigth-view float_left">
  30. <scroll-view scroll-y="true" @scrolltolower="scrolltolower" class="rigth-scroll" :scroll-top="scrollTop">
  31. <view class="goods-li" v-for="(item, index) in goods_list" :key="index">
  32. <view class="add-btn">
  33. <text @click="addGoods(index)" v-if="item.buyNum === 0" class="custom-icon custom-icon-xinzeng"></text>
  34. <u-number-box v-else :min="0" :index="index" @change="buyNumChange" :value="item.buyNum"></u-number-box>
  35. </view>
  36. <view class="goods-main clearfix">
  37. <image class="goods-img float_left" :src="item.images[0]" mode="aspectFill"></image>
  38. <view class="goods-info float_left">
  39. <view class="goods-name ellipsis">{{ item.materielName }}</view>
  40. <view class="goods-code">{{ item.materielCode }}</view>
  41. <view class="goods-code">
  42. {{ item.unitName }};
  43. <text v-for="(sku, skuI) in item.specGroup" :key="skuI">{{ sku.specValueName }};</text>
  44. </view>
  45. <view class="num-ul">
  46. <view class="num-li">
  47. <view class="label">库存量</view>
  48. {{ $utils.formatNub(item.inventoryNum) }}{{ item.unitName }}
  49. </view>
  50. <view class="num-li">
  51. <view class="label">平均成本</view>
  52. ¥{{ $utils.formatNub(item.costPrice) }}
  53. </view>
  54. <view class="num-li">
  55. <view class="label">总成本</view>
  56. ¥{{ $utils.formatNub(item.total) }}
  57. </view>
  58. </view>
  59. <view class="goods-tag"><u-tag class="tag-li" mode="plain" size="mini" :text="item.categoryName" /></view>
  60. </view>
  61. </view>
  62. </view>
  63. <u-loadmore :status="load_status" />
  64. </scroll-view>
  65. </view>
  66. </view>
  67. <view class="bottom-view clearfix">
  68. <view class="float_left" @click="openPop">
  69. <view class="shop-icon-view"><u-icon name="shopping-cart-fill" class="uicon" color="#ffffff" size="40"></u-icon></view>
  70. <text>共{{ add_goods.length }}个商品</text>
  71. </view>
  72. <view class="float_right"><u-button type="primary" size="medium" @click="addGoodsTo">选好了</u-button></view>
  73. </view>
  74. <u-popup v-model="sel_pop" mode="bottom">
  75. <view class="sel-goods-pop">
  76. <view class="pop-tit clearfix">
  77. <view class="float_left">本次已选商品</view>
  78. <view class="float_right" @click="clearGoods">
  79. <text class="custom-icon custom-icon-shanchu"></text>
  80. <text>清空</text>
  81. </view>
  82. </view>
  83. <scroll-view class="goods-ul" scroll-y>
  84. <view class="goods-li" v-for="(item, index) in add_goods" :key="index">
  85. <view class="goods-name">{{ item.title }}</view>
  86. <view class="goods-code clearfix">{{ item.code }}</view>
  87. <view class="goods-code clearfix">
  88. <view class="float_left">
  89. {{ item.unitName }};
  90. <block v-if="item.specGroup">
  91. <text v-for="(sku, skuI) in item.specGroup" :key="skuI">{{ sku.specValueName }};</text>
  92. </block>
  93. <text v-else>{{ item.specGropName }}</text>
  94. </view>
  95. <view class="float_right"><u-number-box :min="0" :index="index" @change="addBuyNumChange" :value="item.buyNum"></u-number-box></view>
  96. </view>
  97. <text class="custom-icon custom-icon-shanchu" @click="delGoods(index)"></text>
  98. </view>
  99. <view style="padding-top: 100rpx;" v-if="!add_goods.length"><u-empty text="未选择商品" mode="data"></u-empty></view>
  100. </scroll-view>
  101. <view class="btn-view" @click="addGoodsTo">选好了</view>
  102. </view>
  103. </u-popup>
  104. </view>
  105. </template>
  106. <script>
  107. export default {
  108. data() {
  109. return {
  110. sel_pop: false, //已选商品
  111. load_status: 'nomore',
  112. activeName: 'all',
  113. keyword: '',
  114. is_more: false,
  115. page: 1,
  116. pageSize: 10,
  117. total: 0,
  118. category_list: [], // 分类列表
  119. category_id: '', // 分类id
  120. auditStatus: 2, // 审核状态
  121. goods_list: [],
  122. add_goods: [],
  123. sel_goods_id: [],
  124. goods_detail: {},
  125. isRevealSku: 4, // 5 只显示基本单位 4:主辅助单位都显示
  126. shopId: '',
  127. scrollTop: -1,
  128. warehouseId: ''
  129. };
  130. },
  131. onLoad(options) {
  132. this.warehouseId = options.id;
  133. this.add_goods = uni.getStorageSync('warehouseGoods').map(item => {
  134. return {
  135. ...item,
  136. title: item.materielName,
  137. code: item.materielCode
  138. };
  139. });
  140. console.log(this.add_goods)
  141. this.getAllCategory();
  142. this.getInventoryByWarehouseId();
  143. },
  144. methods: {
  145. clearGoods() {
  146. this.add_goods = [];
  147. },
  148. openPop() {
  149. this.sel_pop = true;
  150. },
  151. addGoodsTo() {
  152. this._prePage().warehouseGoods = this.add_goods;
  153. uni.navigateBack();
  154. },
  155. // 滚动到底部,触发上拉加载
  156. scrolltolower() {
  157. if (this.total / this.pageSize > this.page) {
  158. this.page += 1;
  159. this.getInventoryByWarehouseId();
  160. }
  161. },
  162. buyNumChange({ value, index }) {
  163. let target = this.$u.deepClone(this.goods_list);
  164. target[index].buyNum = value;
  165. let addGoods = this.$u.deepClone(this.add_goods);
  166. const goodsI = addGoods.findIndex(item => item.skuId === target[index].skuId);
  167. if (!Number(value)) {
  168. addGoods.splice(goodsI, 1);
  169. } else {
  170. addGoods[goodsI].buyNum = value;
  171. }
  172. this.add_goods = addGoods;
  173. this.goods_list = target;
  174. },
  175. addBuyNumChange({ value, index }) {
  176. let target = this.$u.deepClone(this.goods_list);
  177. let addGoods = this.$u.deepClone(this.add_goods);
  178. const goodsI = target.findIndex(item => item.skuId === addGoods[index].skuId);
  179. if (!Number(value)) {
  180. addGoods.splice(goodsI, 1);
  181. } else {
  182. addGoods[index].buyNum = value;
  183. }
  184. if (goodsI > -1) {
  185. target[goodsI].buyNum = value;
  186. }
  187. this.add_goods = addGoods;
  188. this.goods_list = target;
  189. },
  190. delGoods(index) {
  191. let target = this.$u.deepClone(this.goods_list);
  192. const goodsI = target.findIndex(item => item.skuId === this.add_goods[index].skuId);
  193. if (goodsI > -1) {
  194. target[goodsI].buyNum = 0;
  195. }
  196. this.goods_list = target;
  197. this.add_goods.splice(index, 1);
  198. },
  199. // 获取商品列表
  200. getInventoryByWarehouseId() {
  201. this.load_status = 'loading';
  202. this.$u.api
  203. .getInventoryByWarehouseId({
  204. page: this.page,
  205. pageSize: this.pageSize,
  206. warehouseId: this.warehouseId,
  207. categoryId: this.category_id
  208. })
  209. .then(res => {
  210. const list = res.data.map(item => {
  211. const goods = this.add_goods.find(agoods => agoods.skuId === item.skuId);
  212. return {
  213. ...item,
  214. buyNum: goods ? (goods.buyNum||goods.num) : 0
  215. };
  216. });
  217. if (this.page === 1) {
  218. this.goods_list = list;
  219. } else {
  220. this.goods_list = this.goods_list.concat(list);
  221. }
  222. // console.log(res.data)
  223. this.total = res.pageTotal;
  224. this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
  225. });
  226. },
  227. // 获取所有商品分类
  228. getAllCategory() {
  229. this.$u.api
  230. .getAllCategory({
  231. enableStatus: 5
  232. })
  233. .then(res => {
  234. this.category_list = res.data;
  235. });
  236. },
  237. // 切换分类
  238. changeCate(id) {
  239. this.scrollTop = 0;
  240. this.$nextTick(() => {
  241. this.scrollTop = -1;
  242. });
  243. this.category_id = id;
  244. this.page = 1;
  245. this.searchList();
  246. },
  247. searchList() {
  248. this.page = 1;
  249. this.getInventoryByWarehouseId();
  250. },
  251. addGoods(index) {
  252. const target = this.$u.deepClone(this.goods_list);
  253. const isindex = this.add_goods.findIndex(item => item.skuId === target[index].skuId);
  254. if (isindex === -1) {
  255. target[index].buyNum = 1;
  256. this.add_goods.push(target[index]);
  257. } else {
  258. this.add_goods[isindex].buyNum += target[index].buyNum;
  259. }
  260. this.goods_list = target;
  261. }
  262. }
  263. };
  264. </script>
  265. <style scoped lang="scss">
  266. .bottom-view {
  267. box-shadow: 0px 2px 12rpx rgba(0, 0, 0, 0.2);
  268. position: fixed;
  269. width: 100%;
  270. padding: 20rpx;
  271. bottom: 0;
  272. left: 0;
  273. background-color: #ffffff;
  274. .float_left {
  275. line-height: 70rpx;
  276. .shop-icon-view {
  277. display: inline-block;
  278. width: 60rpx;
  279. height: 60rpx;
  280. border-radius: 100%;
  281. background-color: $uni-color-primary;
  282. text-align: center;
  283. line-height: 60rpx;
  284. vertical-align: middle;
  285. margin-right: 20rpx;
  286. .uicon {
  287. display: inline-block;
  288. margin-top: 6rpx;
  289. }
  290. }
  291. }
  292. }
  293. .search-view {
  294. background-color: #ffffff;
  295. padding: 20rpx;
  296. .input-view {
  297. padding: 0 24rpx;
  298. input {
  299. height: 60rpx;
  300. line-height: 60rpx;
  301. padding: 0 24rpx;
  302. margin: 0 auto;
  303. width: 620rpx;
  304. border: 1px solid #f5f5f5;
  305. vertical-align: middle;
  306. border-radius: 8rpx;
  307. background-color: #f7f8fa;
  308. }
  309. }
  310. .search-other {
  311. display: flex;
  312. border-bottom: 1px solid #f5f5f5;
  313. .search-li {
  314. flex: 2;
  315. text-align: center;
  316. font-size: 24rpx;
  317. line-height: 80rpx;
  318. .arrow-down {
  319. margin-left: 10rpx;
  320. }
  321. }
  322. }
  323. }
  324. .main-view {
  325. .left-view {
  326. width: 168rpx;
  327. background-color: #f7f8fa;
  328. .left-scroll {
  329. width: 100%;
  330. height: calc(100vh - 214rpx);
  331. .cate-li {
  332. line-height: 90rpx;
  333. padding-left: 36rpx;
  334. color: #666666;
  335. }
  336. .cate-on {
  337. background-color: #ffffff;
  338. color: #000000;
  339. position: relative;
  340. &::before {
  341. content: '';
  342. display: block;
  343. width: 6rpx;
  344. height: 20rpx;
  345. background-color: $uni-color-primary;
  346. position: absolute;
  347. left: 14rpx;
  348. top: 50%;
  349. transform: translateY(-50%);
  350. }
  351. }
  352. }
  353. }
  354. .rigth-view {
  355. width: calc(100% - 168rpx);
  356. background-color: #ffffff;
  357. .rigth-scroll {
  358. width: 100%;
  359. height: calc(100vh - 214rpx);
  360. .goods-li {
  361. padding: 20rpx;
  362. border-bottom: 1px solid #f5f5f5;
  363. position: relative;
  364. .add-btn {
  365. position: absolute;
  366. right: 20rpx;
  367. bottom: 20rpx;
  368. .custom-icon {
  369. color: #ffffff;
  370. font-size: 32rpx;
  371. display: block;
  372. width: 46rpx;
  373. height: 46rpx;
  374. text-align: center;
  375. line-height: 46rpx;
  376. background-color: $uni-color-primary;
  377. border-radius: 100%;
  378. }
  379. }
  380. .add-on {
  381. background-color: #999999;
  382. }
  383. .goods-main {
  384. .goods-img {
  385. border-radius: 10rpx;
  386. width: 156rpx;
  387. height: 156rpx;
  388. margin-right: 20rpx;
  389. }
  390. .goods-info {
  391. width: 366rpx;
  392. .num-ul {
  393. display: flex;
  394. padding-top: 20rpx;
  395. .num-li {
  396. font-size: 24rpx;
  397. line-height: 36rpx;
  398. flex: 3;
  399. text-align: center;
  400. position: relative;
  401. font-weight: bold;
  402. .label {
  403. font-weight: 400;
  404. color: #999999;
  405. }
  406. &::after {
  407. display: block;
  408. content: '';
  409. position: absolute;
  410. width: 1px;
  411. height: 60rpx;
  412. top: 50%;
  413. transform: translateY(-50%);
  414. right: 0;
  415. background-color: #eeeeee;
  416. }
  417. &:last-child {
  418. &::after {
  419. display: block;
  420. content: '';
  421. position: absolute;
  422. width: 1px;
  423. height: 50rpx;
  424. top: 50%;
  425. transform: translateY(-50%);
  426. right: 0;
  427. background-color: transparent;
  428. }
  429. }
  430. }
  431. }
  432. .goods-name {
  433. -webkit-line-clamp: 1;
  434. }
  435. .goods-code {
  436. font-size: 24rpx;
  437. padding-top: 6rpx;
  438. }
  439. .goods-tag {
  440. padding: 10rpx 0;
  441. .tag-li {
  442. margin-right: 14rpx;
  443. }
  444. }
  445. .goods-num {
  446. color: #999999;
  447. font-size: 22rpx;
  448. text {
  449. padding-right: 10rpx;
  450. }
  451. }
  452. }
  453. }
  454. }
  455. }
  456. }
  457. }
  458. .sel-goods-pop {
  459. padding-bottom: 1px;
  460. .pop-tit {
  461. line-height: 70rpx;
  462. background-color: #f5f5f5;
  463. padding: 0 24rpx;
  464. .float_right {
  465. font-size: 24rpx;
  466. color: #666666;
  467. .custom-icon-shanchu {
  468. font-size: 26rpx;
  469. margin-right: 10rpx;
  470. }
  471. }
  472. }
  473. .goods-ul {
  474. min-height: 400rpx;
  475. max-height: 600rpx;
  476. .goods-li {
  477. padding: 24rpx;
  478. position: relative;
  479. border-bottom: 1px solid #f5f5f5;
  480. .goods-name {
  481. width: 660rpx;
  482. }
  483. .goods-code {
  484. padding-top: 10rpx;
  485. font-size: 24rpx;
  486. color: #999999;
  487. }
  488. .custom-icon-shanchu {
  489. position: absolute;
  490. right: 24rpx;
  491. top: 24rpx;
  492. width: 40rpx;
  493. height: 40rpx;
  494. color: $uni-color-error;
  495. }
  496. }
  497. }
  498. .btn-view {
  499. width: 680rpx;
  500. height: 70rpx;
  501. line-height: 70rpx;
  502. border-radius: 10rpx;
  503. background-color: $uni-color-primary;
  504. color: #ffffff;
  505. text-align: center;
  506. margin: 20rpx auto;
  507. }
  508. }
  509. </style>