index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <template>
  2. <view>
  3. <u-popup v-model="visible" mode="bottom" border-radius="24" :safe-area-inset-bottom="true" :mask-close-able="false"
  4. @close="close">
  5. <view class="popup-content" @click.stop>
  6. <!-- Header -->
  7. <view class="header">
  8. <text class="title">选择商品品相</text>
  9. <image src="/pages-sell/static/select-good/icon-close.png" class="close-icon" @click="close"></image>
  10. </view>
  11. <!-- Product Info -->
  12. <view class="product-info">
  13. <image :src="currentProduct.cover" class="book-cover" mode="aspectFill"></image>
  14. <view class="info-right">
  15. <view class="price-row">
  16. <text class="currency">¥</text>
  17. <text class="price">{{ displayUnitPrice }}</text>
  18. <view class="drop-tag">
  19. <text>↓可降至 ¥{{ displayMinPrice }}</text>
  20. </view>
  21. </view>
  22. <view class="tag-row">
  23. <view class="quality-tag">
  24. <text>品相{{ currentQualityName }}</text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- Tips -->
  30. <view class="tips-row">
  31. <text>不同品相有什么区别</text>
  32. <image src="/pages-sell/static/select-good/icon-tips.png" class="tips-icon"></image>
  33. </view>
  34. <!-- Promo Note -->
  35. <view class="promo-note">
  36. <text>下单时用书购余额支付可享余额价 ( 售价 8 折优惠 )</text>
  37. </view>
  38. <!-- Options -->
  39. <view class="options-list">
  40. <view class="option-item" v-for="(opt, index) in qualityOptions" :key="index"
  41. :class="{ active: currentQuality === opt.conditionType, disabled: isOptionDisabled(opt) }"
  42. @click="selectQuality(opt)">
  43. <image v-if="currentQuality === opt.conditionType && !isOptionDisabled(opt)"
  44. src="/pages-sell/static/select-good/selected.png" class="bg-image"></image>
  45. <view class="left">
  46. <text class="opt-name">{{ opt.conditionType | conditionText }}</text>
  47. <view class="opt-discount"
  48. :class="{ active: currentQuality === opt.conditionType && !isOptionDisabled(opt) }">
  49. <text>{{ opt.discount }}折</text>
  50. </view>
  51. </view>
  52. <view class="right">
  53. <text v-if="!isOptionDisabled(opt)">¥{{ opt.price }} ( 余额价 ¥{{ opt.balanceMoney }} )</text>
  54. <text v-else>无货</text>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- Quantity -->
  59. <view class="quantity-row">
  60. <text class="label">数量</text>
  61. <u-number-box v-model="quantity" :min="1" :max="99"></u-number-box>
  62. </view>
  63. <!-- Footer Buttons -->
  64. <view class="footer-btns">
  65. <view class="btn btn-orange" @click="handleShareAction">
  66. <text class="price">¥{{ currentProduct.maxReducePrice }}</text>
  67. <text class="desc">分享一人可降 {{ currentProduct.reducePrice }} 元</text>
  68. </view>
  69. <view class="btn btn-green" @click="handleAction">
  70. <text v-if="hasStock" class="price">¥{{ displayTotalPrice }}</text>
  71. <text class="desc" :class="{ 'notice': !hasStock }">{{ hasStock ? '加入购物车' : '到货通知' }}</text>
  72. </view>
  73. </view>
  74. </view>
  75. </u-popup>
  76. <price-reduction-popup ref="reducePopup" @scan="handleScan"></price-reduction-popup>
  77. <reduce-qrcode ref="reduceQrcode"></reduce-qrcode>
  78. </view>
  79. </template>
  80. <script>
  81. import PriceReductionPopup from '@/components/price-reduction-popup/price-reduction-popup.vue';
  82. import ReduceQrcode from '@/components/reduce-qrcode/reduce-qrcode.vue';
  83. export default {
  84. name: 'SelectGoodPopup',
  85. components: {
  86. PriceReductionPopup,
  87. ReduceQrcode
  88. },
  89. data() {
  90. return {
  91. visible: false,
  92. quantity: 1,
  93. currentQuality: 1,
  94. currentProduct: {},
  95. qualityOptions: [],
  96. sourceFrom: 0,
  97. isSubmitting: false, // 防重复提交标志
  98. };
  99. },
  100. computed: {
  101. currentQualityName() {
  102. const opt = this.$conditionMap[this.currentQuality];
  103. return opt || '未知';
  104. },
  105. selectedOption() {
  106. return this.qualityOptions.find(o => o.conditionType === this.currentQuality) || {};
  107. },
  108. displayUnitPrice() {
  109. return this.formatPrice(this.selectedOption.price);
  110. },
  111. displayMinPrice() {
  112. return this.formatPrice(this.selectedOption.balanceMoney);
  113. },
  114. displayTotalPrice() {
  115. const total = Number(this.selectedOption.price || 0) * this.quantity;
  116. return this.formatPrice(total);
  117. },
  118. hasStock() {
  119. const stock = this.selectedOption.stockNum;
  120. if (stock === 0) return false;
  121. if (stock === undefined || stock === null || stock === '') return true;
  122. return Number(stock) > 0;
  123. }
  124. },
  125. methods: {
  126. open(product, sourceFrom) {
  127. this.visible = true;
  128. this.quantity = 1;
  129. this.sourceFrom = sourceFrom || 0;
  130. if (product.isbn) {
  131. this.getGoodQualityInfo(product.isbn);
  132. }
  133. },
  134. //根据 isbn 获取商品品相信息
  135. getGoodQualityInfo(isbn) {
  136. uni.$u.http.get('/token/shop/bookDetail', { isbn }).then(res => {
  137. console.log(res);
  138. if (res.code === 200) {
  139. this.currentProduct = res.data || {};
  140. this.qualityOptions = res.data.skuList || [];
  141. if (this.qualityOptions.length > 0) {
  142. this.currentQuality = this.qualityOptions[0].conditionType
  143. }
  144. }
  145. });
  146. },
  147. close() {
  148. this.visible = false;
  149. },
  150. isOptionDisabled(opt) {
  151. const stock = opt.stockNum;
  152. if (stock === 0) return true;
  153. if (stock === undefined || stock === null || stock === '') return false;
  154. return Number(stock) <= 0;
  155. },
  156. selectQuality(opt) {
  157. if (this.isOptionDisabled(opt)) {
  158. this.$u.toast('该品相暂无库存');
  159. return;
  160. }
  161. this.currentQuality = opt.conditionType;
  162. },
  163. handleAction() {
  164. if (!this.hasStock) {
  165. this.handleNotify();
  166. return;
  167. }
  168. this.handleConfirm();
  169. },
  170. handleNotify() {
  171. //设置到货通知
  172. uni.$u.http.post('/token/shop/user/noticeArrival', {
  173. isbn: this.currentProduct.isbn,
  174. }).then(res => {
  175. if (res.code === 200) {
  176. this.$u.toast('到货通知设置成功');
  177. }
  178. }).finally(() => {
  179. this.close();
  180. });
  181. },
  182. handleConfirm() {
  183. if (this.isSubmitting) return; // 防止重复提交
  184. if (!this.currentProduct.isbn) {
  185. this.$u.toast('商品信息缺失');
  186. return;
  187. }
  188. const selectedOption = this.selectedOption;
  189. const conditionType = selectedOption.conditionType || this.currentQuality;
  190. if (!conditionType) {
  191. this.$u.toast('请选择品相');
  192. return;
  193. }
  194. this.isSubmitting = true; // 设置提交中状态
  195. this.$u.api.addShopCartAjax({
  196. isbn: this.currentProduct.isbn,
  197. quantity: this.quantity,
  198. conditionType: conditionType,
  199. sourceFrom: this.sourceFrom
  200. }).then(res => {
  201. if (res.code === 200) {
  202. this.$u.toast('加入购物车成功');
  203. this.$updateCartBadge();
  204. this.$emit('confirm', {
  205. product: this.currentProduct,
  206. quality: this.currentQuality,
  207. quantity: this.quantity
  208. });
  209. this.close();
  210. } else {
  211. this.$u.toast(res.msg || '加入购物车失败');
  212. }
  213. }).finally(() => {
  214. this.isSubmitting = false; // 重置提交状态
  215. });
  216. },
  217. handleShareAction() {
  218. if (this.isSubmitting) return; // 防止重复提交
  219. if (!this.currentProduct.isbn) {
  220. this.$u.toast('商品信息缺失');
  221. return;
  222. }
  223. const selectedOption = this.selectedOption;
  224. const conditionType = selectedOption.conditionType || this.currentQuality;
  225. if (!conditionType) {
  226. this.$u.toast('请选择品相');
  227. return;
  228. }
  229. this.isSubmitting = true; // 设置提交中状态
  230. this.$u.api.addShopCartAjax({
  231. isbn: this.currentProduct.isbn,
  232. quantity: this.quantity,
  233. conditionType: conditionType,
  234. sourceFrom: this.sourceFrom
  235. }).then(res => {
  236. if (res.code === 200) {
  237. this.$u.toast('加入购物车成功');
  238. this.$updateCartBadge();
  239. this.$emit('confirm', {
  240. product: this.currentProduct,
  241. quality: this.currentQuality,
  242. quantity: this.quantity
  243. });
  244. this.close();
  245. // 打开减价弹窗
  246. setTimeout(() => {
  247. if (this.$refs.reducePopup) {
  248. this.$refs.reducePopup.open({
  249. isbn: this.currentProduct.isbn,
  250. conditionType: conditionType
  251. });
  252. }
  253. }, 300);
  254. } else {
  255. this.$u.toast(res.msg || '加入购物车失败');
  256. }
  257. }).finally(() => {
  258. this.isSubmitting = false; // 重置提交状态
  259. });
  260. },
  261. handleScan(bookInfo) {
  262. this.$refs.reduceQrcode.open(bookInfo);
  263. },
  264. formatPrice(value) {
  265. if (value === undefined || value === null) return '0.00';
  266. const num = Number(value);
  267. return Number.isFinite(num) ? num.toFixed(2) : '0.00';
  268. }
  269. }
  270. };
  271. </script>
  272. <style lang="scss" scoped>
  273. .popup-content {
  274. padding: 30rpx 30rpx 20rpx;
  275. background-color: #fff;
  276. position: relative;
  277. }
  278. .header {
  279. display: flex;
  280. justify-content: center;
  281. align-items: center;
  282. position: relative;
  283. margin-bottom: 30rpx;
  284. padding-bottom: 30rpx;
  285. border-bottom: 2rpx dashed #eee;
  286. .title {
  287. font-size: 34rpx;
  288. font-weight: bold;
  289. color: #333;
  290. }
  291. .close-icon {
  292. position: absolute;
  293. right: 0;
  294. top: 0;
  295. width: 24rpx;
  296. height: 24rpx;
  297. padding: 10rpx;
  298. box-sizing: content-box;
  299. }
  300. }
  301. .product-info {
  302. display: flex;
  303. margin-bottom: 30rpx;
  304. .book-cover {
  305. width: 140rpx;
  306. height: 180rpx;
  307. border-radius: 8rpx;
  308. margin-right: 24rpx;
  309. background-color: #f5f5f5;
  310. }
  311. .info-right {
  312. flex: 1;
  313. display: flex;
  314. flex-direction: column;
  315. justify-content: space-between;
  316. padding: 10rpx 0;
  317. .price-row {
  318. display: flex;
  319. align-items: center;
  320. .currency {
  321. font-size: 36rpx;
  322. color: #D81A00;
  323. font-weight: bold;
  324. }
  325. .price {
  326. font-size: 40rpx;
  327. color: #D81A00;
  328. font-weight: bold;
  329. margin-right: 20rpx;
  330. line-height: 1;
  331. }
  332. .drop-tag {
  333. background: #E8F9EA;
  334. padding: 4rpx 12rpx;
  335. border-radius: 4rpx;
  336. text {
  337. color: #38C248;
  338. font-size: 24rpx;
  339. font-weight: 500;
  340. }
  341. }
  342. }
  343. .tag-row {
  344. .quality-tag {
  345. display: inline-block;
  346. background: linear-gradient(0deg, #FFAB26 0%, #FFD426 100%);
  347. border-radius: 21rpx 0px 21rpx 0px;
  348. padding: 2rpx 24rpx;
  349. margin-bottom: 24rpx;
  350. text {
  351. color: #fff;
  352. font-size: 24rpx;
  353. font-weight: 500;
  354. }
  355. }
  356. }
  357. }
  358. }
  359. .tips-row {
  360. display: flex;
  361. align-items: center;
  362. margin-bottom: 16rpx;
  363. text {
  364. font-size: 26rpx;
  365. color: #8D8D8D;
  366. margin-right: 10rpx;
  367. }
  368. .tips-icon {
  369. width: 36rpx;
  370. height: 36rpx;
  371. }
  372. }
  373. .promo-note {
  374. margin-bottom: 40rpx;
  375. text {
  376. font-size: 26rpx;
  377. color: #8D8D8D;
  378. }
  379. }
  380. .options-list {
  381. margin-bottom: 40rpx;
  382. .option-item {
  383. position: relative;
  384. display: flex;
  385. justify-content: space-between;
  386. align-items: center;
  387. background: #ffffff;
  388. border-radius: 12rpx;
  389. padding: 24rpx 30rpx;
  390. margin-bottom: 24rpx;
  391. border: 2rpx solid #dfdfdf;
  392. transition: all 0.2s;
  393. &.active {
  394. border-color: transparent;
  395. }
  396. &.disabled {
  397. background: #F0F0F0;
  398. border-color: #E0E0E0;
  399. opacity: 0.7;
  400. .opt-name,
  401. .right text {
  402. color: #999;
  403. }
  404. .opt-discount {
  405. background: #CCCCCC;
  406. }
  407. }
  408. .bg-image {
  409. position: absolute;
  410. top: -6rpx;
  411. left: -1%;
  412. width: 102%;
  413. height: 110rpx;
  414. z-index: 0;
  415. }
  416. .left,
  417. .right {
  418. position: relative;
  419. z-index: 1;
  420. }
  421. .left {
  422. display: flex;
  423. align-items: center;
  424. .opt-name {
  425. font-size: 30rpx;
  426. font-weight: bold;
  427. color: #333;
  428. margin-right: 16rpx;
  429. }
  430. .opt-discount {
  431. background: #D8D8D8;
  432. padding: 0 20rpx;
  433. border-radius: 0 20rpx 0 20rpx;
  434. text {
  435. color: #fff;
  436. font-size: 24rpx;
  437. display: inline-block;
  438. }
  439. &.active {
  440. background: linear-gradient(0deg, #30E030 0%, #28C445 100%);
  441. }
  442. }
  443. }
  444. .right {
  445. text {
  446. font-size: 28rpx;
  447. color: #333;
  448. }
  449. }
  450. }
  451. }
  452. .quantity-row {
  453. display: flex;
  454. justify-content: space-between;
  455. align-items: center;
  456. margin-bottom: 50rpx;
  457. .label {
  458. font-size: 30rpx;
  459. font-weight: bold;
  460. color: #333;
  461. }
  462. }
  463. .footer-btns {
  464. display: flex;
  465. justify-content: space-between;
  466. padding-bottom: 10rpx;
  467. .btn {
  468. flex: 1;
  469. height: 100rpx;
  470. display: flex;
  471. flex-direction: column;
  472. align-items: center;
  473. justify-content: center;
  474. font-family: Source Han Sans SC;
  475. font-weight: 500;
  476. border: none;
  477. outline: none;
  478. padding: 0;
  479. margin: 0;
  480. -webkit-tap-highlight-color: transparent;
  481. .price {
  482. font-size: 38rpx;
  483. color: #fff;
  484. line-height: 32rpx;
  485. }
  486. .desc {
  487. font-size: 24rpx;
  488. color: #fff;
  489. line-height: 32rpx;
  490. }
  491. .notice {
  492. font-size: 32rpx;
  493. color: #fff;
  494. }
  495. &.btn-orange {
  496. background: linear-gradient(0deg, #EFA941 0%, #FFB84F 100%);
  497. width: 340rpx;
  498. border-radius: 50rpx 0 0 50rpx;
  499. }
  500. &.btn-green {
  501. width: 340rpx;
  502. background: linear-gradient(0deg, #38C248 0%, #5FEA6F 100%);
  503. border-radius: 0 50rpx 50rpx 0;
  504. }
  505. }
  506. }
  507. </style>