selBaseGoods.vue 11 KB

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