selGoods.vue 13 KB

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