index.vue 11 KB

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