selGoodsBasicBySku.vue 11 KB

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