SelSkuPop.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <view class="blanck-pop">
  3. <u-popup
  4. :custom-style="{
  5. background: 'rgba(0,0,0,0)'
  6. }"
  7. :value="isShow"
  8. :mask-close-able="false"
  9. mode="bottom"
  10. >
  11. <view class="detail-box">
  12. <view class="detail-view">
  13. <view class="close-icon"><u-icon @click="closeaddcartPop" name="close" color="#EAEAEA" size="32"></u-icon></view>
  14. <view class="goods-view clearfix">
  15. <view class="float_left"><image class="goods-img" :src="goods_detail.images[0]" mode="aspectFill"></image></view>
  16. <view class="float_right goods-info">
  17. <view class="goods-name ellipsis">{{ goods_detail.title || '' }}</view>
  18. <view class="goods-desc">
  19. <block v-if="baseSet.stockDisplay === 5">
  20. <!-- 总库存大于0 且 支持负库存销售 显示【有货】 -->
  21. <text class="goods-desc-text">
  22. 总库存:{{ Math.floor(goods_detail.inventoryTotal) > 0 || goods_detail.isDistribution === 5 ? '有货' : '库存不足' }}
  23. </text>
  24. </block>
  25. <block v-if="baseSet.stockDisplay === 6">
  26. <!-- 负库存销售即使没有库存也 显示【有货】 -->
  27. <text class="goods-desc-text" v-if="goods_detail.isDistribution === 5">总库存:{{ Math.floor(goods_detail.inventoryTotal) || '有货' }}</text>
  28. <text class="goods-desc-text" v-else>总库存:{{ Math.floor(goods_detail.inventoryTotal) || '库存不足' }}</text>
  29. </block>
  30. <text class="goods-desc-text">已售:{{ goods_detail.salesNum || 0 }}</text>
  31. </view>
  32. </view>
  33. </view>
  34. <scroll-view scroll-y="true" style="max-height: 700rpx;">
  35. <view class="sku-ul">
  36. <view class="sku-li" v-for="(item, index) in specMultiple" :key="index">
  37. <view class="sku-name ellipsis">
  38. {{ item.unitName }}
  39. <text style="margin-left: 8rpx;" v-for="(sku, skuI) in item.specGroup" :key="skuI">{{ sku.specValueName }}</text>
  40. </view>
  41. <view class="sku-desc">
  42. <!-- 库存大于0 且 支持负库存销售 显示【有货】 -->
  43. <text class="sku-desc-text" v-if="baseSet.stockDisplay === 5">
  44. 库存:{{ Math.floor(item.inventory) > 0 || goods_detail.isDistribution === 5 ? '有货' : '库存不足' }}
  45. </text>
  46. <text class="sku-desc-text" v-if="baseSet.stockDisplay === 6">
  47. <!-- 负库存销售即使没有库存也 显示【有货】 -->
  48. <block v-if="goods_detail.isDistribution === 5 && Math.floor(item.inventory) <= 0">库存:有货</block>
  49. <block v-else>库存:{{ Math.floor(item.inventory) }}{{ item.unitName }}</block>
  50. </text>
  51. <text class="sku-desc-text" v-if="item.setNum > 1">{{ item.setNum }}{{ item.unitName }}起购</text>
  52. <text class="sku-desc-text" v-if="item.isMaster === 4">
  53. 1{{ item.unitName }}{{ goodsDetail.isEq === 5 ? '≈' : '=' }}{{ Number(item.conversion) }}{{ goods_detail.unitName }}
  54. </text>
  55. </view>
  56. <view class="sku-price clearfix ">
  57. <!-- 阶梯价 -->
  58. <block v-if="!showGoodsPrice">
  59. <view class="float_left ladder-ul" v-if="item.enabledLadder === 1">
  60. <view class="ladder-li" v-for="(ladder, ladderI) in item.ladderPrice" :key="ladderI">
  61. <view class="price-text clearfix primary-color">
  62. <view class="float_left rmb-icon">¥</view>
  63. <rich-text class="float_left" :nodes="$_utils.splitPrice(ladder.price)"></rich-text>
  64. </view>
  65. <view class="num-region" v-if="ladderI + 1 === item.ladderPrice.length">≥{{ ladder.from }}{{ item.unitName }}</view>
  66. <view class="num-region" v-else>{{ ladder.from }}~{{ ladder.to }}{{ item.unitName }}</view>
  67. </view>
  68. </view>
  69. <!-- 非阶梯价 -->
  70. <view v-else class="float_left clearfix primary-color price-text">
  71. <view class="float_left rmb-icon">¥</view>
  72. <rich-text class="float_left" :nodes="$_utils.splitPrice(item.salePrice)"></rich-text>
  73. </view>
  74. </block>
  75. <block v-else>
  76. <text class="showGoodsPrice primary-color">{{ showGoodsPrice }}</text>
  77. </block>
  78. <view class="vip-price float_left clearfix" v-if="item.memberPrice > 0">
  79. <view class="price-text">¥{{ item.memberPrice }}</view>
  80. <view class="price-bs">VIP</view>
  81. </view>
  82. <!-- 步进器 -->
  83. <view class="num-edit-view float_right">
  84. <view class="subr-view p-background-img " :class="[item.buy_num <= 0 ? 'disabled-color' : '']" @click="delNum(index)">
  85. <u-icon size="28" name="minus"></u-icon>
  86. </view>
  87. <view class="buy-num-input-view">
  88. <input type="number" @blur="buyNumInput($event, index)" class="buy-num-input" :value="item.buy_num" />
  89. </view>
  90. <!-- 数量大于库存或者当前商品不支持负库存销售 则当前加号按钮禁用-->
  91. <view
  92. class="plus-view p-background-img"
  93. :class="[item.buy_num >= Math.floor(item.inventory) && goods_detail.isDistribution !== 5 ? 'disabled-color' : '']"
  94. @click="plusNum(index)"
  95. >
  96. <u-icon size="28" name="plus"></u-icon>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. </view>
  102. </scroll-view>
  103. <view class="sub-btn p-background-img">加入购物车</view>
  104. </view>
  105. </view>
  106. </u-popup>
  107. <NoLoginTip @cancel="cancelTip" :show="loginTip" v-if="loginTip" />
  108. </view>
  109. </template>
  110. <script>
  111. import NoLoginTip from './NoLoginTip.vue';
  112. export default {
  113. components: {
  114. NoLoginTip
  115. },
  116. props: {
  117. selAddress: {
  118. type: Object,
  119. default: () => {
  120. return {};
  121. }
  122. },
  123. isShow: {
  124. type: Boolean,
  125. default: false
  126. },
  127. goodsId: {
  128. type: [Number, String],
  129. default: 0
  130. },
  131. isList: {
  132. type: Boolean,
  133. default: true
  134. },
  135. skuId: {
  136. type: [Number, String],
  137. default: ''
  138. }
  139. },
  140. computed: {
  141. hasLogin() {
  142. return this.$store.state.hasLogin;
  143. },
  144. baseSet() {
  145. return this.$store.state.baseSet;
  146. },
  147. userStatus() {
  148. return this.$store.state.userStatus;
  149. },
  150. showGoodsPrice() {
  151. if (this.baseSet.goodsPrice === 5 && this.hasLogin) {
  152. return '';
  153. } else if (!this.hasLogin && this.baseSet.goodsPrice === 4) {
  154. return '请登录';
  155. } else if (this.userStatus.enableStatus === 4 && this.baseSet.goodsPrice === 4) {
  156. return '已禁用';
  157. } else if (this.userStatus.status !== 2 && this.baseSet.goodsPrice === 4) {
  158. if (this.userStatus.status === 0) {
  159. return '待审核';
  160. } else if (this.userStatus.status === 1) {
  161. return '审核中';
  162. } else if (this.userStatus.status === 3) {
  163. return '已驳回';
  164. }
  165. } else {
  166. return '';
  167. }
  168. }
  169. },
  170. watch: {
  171. goodsId(val) {
  172. if (this.isShow) {
  173. this.goods_detail = {};
  174. this.specMultiple = [];
  175. this.getGoodsDetail();
  176. }
  177. }
  178. },
  179. data() {
  180. return {
  181. eq_sku_kg: {},
  182. isLogin: true, // 判断是否登录
  183. loginTip: false,
  184. goods_detail: {
  185. images: [],
  186. specGroup: [],
  187. unitData: []
  188. },
  189. spec_id_group: [],
  190. now_sku_data: {},
  191. buy_num: 1,
  192. now_sel_address: {},
  193. address_data: {}, // 客户地址数据
  194. not_dispatch_areas: {}, // 该商品不能配送区域
  195. is_not_express: true, // 当前选择区域是否能够配送
  196. activityId: '',
  197. specMultiple: []
  198. };
  199. },
  200. methods: {
  201. // 请求商品品详情
  202. async getGoodsDetail() {
  203. this.$u.api.getGoodsDetail(this.goodsId).then(res => {
  204. this.goods_detail = res.data;
  205. this.specMultiple = res.data.specMultiple.map(item => {
  206. return {
  207. ...item,
  208. buy_num: 0
  209. };
  210. });
  211. });
  212. },
  213. // 关闭加入购物车弹窗
  214. closeaddcartPop() {
  215. this.$emit('close', false);
  216. },
  217. // 减号按钮
  218. delNum(index) {
  219. let target = this.$u.deepClone(this.specMultiple);
  220. if (target[index].buy_num > 0) {
  221. // 当前数量为起订量的时候,点击减号按钮直接设置成0
  222. if (target[index].setNum > 1 && target[index].buy_num === target[index].setNum) {
  223. target[index].buy_num = 0;
  224. } else {
  225. target[index].buy_num = target[index].buy_num - 1;
  226. }
  227. }
  228. this.specMultiple = target;
  229. },
  230. // 加号按钮
  231. plusNum(index) {
  232. let target = this.$u.deepClone(this.specMultiple);
  233. // 数量小于库存或者当前商品支持负库存销售,则可以继续添加数量
  234. if (target[index].buy_num < Math.floor(target[index].inventory) || this.goods_detail.isDistribution === 5) {
  235. if (target[index].buy_num < 1) {
  236. // 当前数量为0的时候,第一次加起订量
  237. target[index].buy_num += target[index].setNum;
  238. } else {
  239. target[index].buy_num += 1;
  240. }
  241. }
  242. this.specMultiple = target;
  243. },
  244. // 输入框失去焦点
  245. buyNumInput(e, index) {
  246. let target = this.$u.deepClone(this.specMultiple);
  247. target[index].buy_num = e.detail.value - 0;
  248. // 数量小于库存或者当前商品支持负库存销售,则可以继续添加数量
  249. if (target[index].buy_num >= Math.floor(target[index].inventory) && this.goods_detail.isDistribution !== 5) {
  250. this.$u.toast('库存不足,已为您修正');
  251. this.$nextTick(() => {
  252. target[index].buy_num = Math.floor(target[index].inventory);
  253. });
  254. }
  255. this.specMultiple = target;
  256. }
  257. }
  258. };
  259. </script>
  260. <style lang="scss">
  261. .detail-box {
  262. padding-top: 34rpx;
  263. .detail-view {
  264. padding: 0 32rpx 32rpx;
  265. background-color: #ffffff;
  266. position: relative;
  267. .close-icon {
  268. position: absolute;
  269. right: 32rpx;
  270. top: 30rpx;
  271. }
  272. .goods-view {
  273. .goods-img {
  274. display: block;
  275. transform: translateY(-34rpx);
  276. width: 176rpx;
  277. height: 176rpx;
  278. background: #f5f7f7;
  279. border-radius: 8rpx;
  280. }
  281. .goods-info {
  282. width: calc(100% - 188rpx);
  283. padding-top: 24rpx;
  284. padding-right: 58rpx;
  285. .goods-name {
  286. width: 100%;
  287. color: #111111;
  288. font-size: 28rpx;
  289. font-weight: 500;
  290. line-height: 40rpx;
  291. margin-bottom: 8rpx;
  292. -webkit-line-clamp: 1;
  293. height: 40rpx;
  294. }
  295. .goods-desc {
  296. color: #9d9d9d;
  297. font-size: 20rpx;
  298. .goods-desc-text{
  299. margin-right: 8rpx;
  300. }
  301. }
  302. }
  303. }
  304. .sub-btn {
  305. width: 686rpx;
  306. height: 80rpx;
  307. background: linear-gradient(90deg, #fe923e 0%, #ff3724 100%);
  308. border-radius: 40rpx;
  309. line-height: 80rpx;
  310. text-align: center;
  311. margin: 56rpx auto 0;
  312. color: #ffffff;
  313. font-size: 32rpx;
  314. font-weight: 500;
  315. }
  316. .sku-ul {
  317. .sku-li {
  318. padding: 24rpx 0;
  319. border-bottom: 1px solid #eeeeee;
  320. &:last-child {
  321. border-bottom: 0 none;
  322. }
  323. .sku-name {
  324. width: 100%;
  325. color: #111111;
  326. font-size: 28rpx;
  327. font-weight: 500;
  328. line-height: 40rpx;
  329. margin-bottom: 8rpx;
  330. -webkit-line-clamp: 1;
  331. height: 40rpx;
  332. }
  333. .sku-desc {
  334. color: #9d9d9d;
  335. font-size: 20rpx;
  336. .sku-desc-text {
  337. margin-right: 8rpx;
  338. }
  339. }
  340. .sku-price {
  341. .ladder-ul {
  342. display: flex;
  343. width: 432rpx;
  344. .ladder-li {
  345. position: relative;
  346. flex: 3;
  347. .num-region {
  348. font-size: 22rpx;
  349. color: #9d9d9d;
  350. font-weight: 500;
  351. margin-top: 8rpx;
  352. }
  353. }
  354. }
  355. .price-text {
  356. font-size: 32rpx;
  357. font-family: DIN-Medium;
  358. padding-top: 16rpx;
  359. .rmb-icon {
  360. font-size: 20rpx;
  361. margin-top: 12rpx;
  362. }
  363. }
  364. .vip-price {
  365. margin-left: 20upx;
  366. margin-top: 18upx;
  367. line-height: 32rpx;
  368. height: 32rpx;
  369. border-radius: 4rpx;
  370. overflow: hidden;
  371. font-family: DINPro-Regular;
  372. .price-text {
  373. min-width: 80rpx;
  374. text-align: center;
  375. float: left;
  376. vertical-align: middle;
  377. font-size: 20rpx;
  378. color: #ffdfa2;
  379. background: linear-gradient(270deg, #1e5657 0%, #0d2b2c 100%);
  380. padding: 0 8rpx;
  381. }
  382. .price-bs {
  383. text-align: center;
  384. float: left;
  385. vertical-align: middle;
  386. width: 32rpx;
  387. background-color: #ffdfa2;
  388. font-size: 16rpx;
  389. color: #2c7564;
  390. font-family: DIN-Medium;
  391. }
  392. }
  393. .num-edit-view {
  394. text-align: center;
  395. display: inline-flex;
  396. align-items: center;
  397. .buy-num-input-view {
  398. display: flex;
  399. position: relative;
  400. text-align: center;
  401. padding: 0;
  402. justify-content: center;
  403. align-items: center;
  404. margin: 0 16rpx;
  405. flex-direction: row;
  406. .buy-num-input {
  407. width: 104upx;
  408. text-align: center;
  409. font-family: DIN-Medium;
  410. line-height: 48upx;
  411. height: 48upx;
  412. font-size: 26upx;
  413. color: #111111;
  414. background: rgba(202, 202, 202, 0.39);
  415. border-radius: 6rpx;
  416. }
  417. }
  418. .subr-view,
  419. .plus-view {
  420. justify-content: center;
  421. align-items: center;
  422. flex-direction: row;
  423. display: flex;
  424. margin-top: 0upx;
  425. width: 48rpx;
  426. height: 48rpx;
  427. line-height: 48rpx;
  428. color: #ffffff;
  429. border-radius: 100%;
  430. }
  431. .disabled-color {
  432. background-image: linear-gradient(90deg, rgba(202, 202, 202, 0.39) 0%, rgba(202, 202, 202, 0.39) 100%) !important;
  433. }
  434. }
  435. }
  436. }
  437. }
  438. }
  439. }
  440. </style>