index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. <view class="btn btn-orange">
  65. <text class="price">¥0.3</text>
  66. <text class="desc">分享一人可降 0.5 元</text>
  67. </view>
  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. };
  88. },
  89. computed: {
  90. currentQualityName() {
  91. const opt = this.$conditionMap[this.currentQuality];
  92. return opt || '未知';
  93. },
  94. selectedOption() {
  95. return this.qualityOptions.find(o => o.conditionType === this.currentQuality) || {};
  96. },
  97. displayUnitPrice() {
  98. return this.formatPrice(this.selectedOption.price);
  99. },
  100. displayMinPrice() {
  101. return this.formatPrice(this.selectedOption.balanceMoney);
  102. },
  103. displayTotalPrice() {
  104. const total = this.toNumber(this.selectedOption.price) * this.quantity;
  105. return this.formatPrice(total);
  106. },
  107. hasStock() {
  108. const stock = this.selectedOption.stockNum;
  109. if (stock === 0) return false;
  110. if (stock === undefined || stock === null || stock === '') return true;
  111. return this.toNumber(stock) > 0;
  112. }
  113. },
  114. methods: {
  115. open(product, sourceFrom) {
  116. this.visible = true;
  117. this.quantity = 1;
  118. this.sourceFrom = sourceFrom || 0;
  119. if (product.isbn) {
  120. this.getGoodQualityInfo(product.isbn);
  121. }
  122. },
  123. //根据 isbn 获取商品品相信息
  124. getGoodQualityInfo(isbn) {
  125. uni.$u.http.get('/token/shop/bookDetail', { isbn }).then(res => {
  126. console.log(res);
  127. if (res.code === 200) {
  128. this.currentProduct = res.data || {};
  129. this.qualityOptions = res.data.skuList || [];
  130. if (this.qualityOptions.length > 0) {
  131. this.currentQuality = this.qualityOptions[0].conditionType
  132. }
  133. }
  134. });
  135. },
  136. close() {
  137. this.visible = false;
  138. },
  139. isOptionDisabled(opt) {
  140. const stock = opt.stockNum;
  141. if (stock === 0) return true;
  142. if (stock === undefined || stock === null || stock === '') return false;
  143. return this.toNumber(stock) <= 0;
  144. },
  145. selectQuality(opt) {
  146. if (this.isOptionDisabled(opt)) {
  147. this.$u.toast('该品相暂无库存');
  148. return;
  149. }
  150. this.currentQuality = opt.conditionType;
  151. },
  152. handleAction() {
  153. if (!this.hasStock) {
  154. this.handleNotify();
  155. return;
  156. }
  157. this.handleConfirm();
  158. },
  159. handleNotify() {
  160. //设置到货通知
  161. uni.$u.http.post('/token/shop/user/noticeArrival', {
  162. isbn: this.currentProduct.isbn,
  163. }).then(res => {
  164. if (res.code === 200) {
  165. this.$u.toast('到货通知设置成功');
  166. }
  167. }).finally(() => {
  168. this.close();
  169. });
  170. },
  171. handleConfirm() {
  172. if (!this.currentProduct.isbn) {
  173. this.$u.toast('商品信息缺失');
  174. return;
  175. }
  176. const selectedOption = this.selectedOption;
  177. const conditionType = selectedOption.conditionType || this.currentQuality;
  178. if (!conditionType) {
  179. this.$u.toast('请选择品相');
  180. return;
  181. }
  182. this.$u.api.addShopCartAjax({
  183. isbn: this.currentProduct.isbn,
  184. quantity: this.quantity,
  185. conditionType: conditionType,
  186. sourceFrom: this.sourceFrom
  187. }).then(res => {
  188. if (res.code === 200) {
  189. this.$u.toast('加入购物车成功');
  190. this.$updateCartBadge();
  191. this.$emit('confirm', {
  192. product: this.currentProduct,
  193. quality: this.currentQuality,
  194. quantity: this.quantity
  195. });
  196. this.close();
  197. } else {
  198. this.$u.toast(res.msg || '加入购物车失败');
  199. }
  200. });
  201. },
  202. formatPrice(price) {
  203. if (price === undefined || price === null) return '0.00';
  204. return Number(price).toFixed(2);
  205. },
  206. toNumber(value) {
  207. const num = Number(value);
  208. return Number.isFinite(num) ? num : 0;
  209. },
  210. formatPrice(value) {
  211. const num = this.toNumber(value);
  212. return num.toFixed(2);
  213. }
  214. }
  215. };
  216. </script>
  217. <style lang="scss" scoped>
  218. .popup-content {
  219. padding: 30rpx 30rpx 20rpx;
  220. background-color: #fff;
  221. position: relative;
  222. }
  223. .header {
  224. display: flex;
  225. justify-content: center;
  226. align-items: center;
  227. position: relative;
  228. margin-bottom: 30rpx;
  229. padding-bottom: 30rpx;
  230. border-bottom: 2rpx dashed #eee;
  231. .title {
  232. font-size: 34rpx;
  233. font-weight: bold;
  234. color: #333;
  235. }
  236. .close-icon {
  237. position: absolute;
  238. right: 0;
  239. top: 0;
  240. width: 24rpx;
  241. height: 24rpx;
  242. padding: 10rpx;
  243. box-sizing: content-box;
  244. }
  245. }
  246. .product-info {
  247. display: flex;
  248. margin-bottom: 30rpx;
  249. .book-cover {
  250. width: 140rpx;
  251. height: 180rpx;
  252. border-radius: 8rpx;
  253. margin-right: 24rpx;
  254. background-color: #f5f5f5;
  255. }
  256. .info-right {
  257. flex: 1;
  258. display: flex;
  259. flex-direction: column;
  260. justify-content: space-between;
  261. padding: 10rpx 0;
  262. .price-row {
  263. display: flex;
  264. align-items: center;
  265. .currency {
  266. font-size: 36rpx;
  267. color: #D81A00;
  268. font-weight: bold;
  269. }
  270. .price {
  271. font-size: 40rpx;
  272. color: #D81A00;
  273. font-weight: bold;
  274. margin-right: 20rpx;
  275. line-height: 1;
  276. }
  277. .drop-tag {
  278. background: #E8F9EA;
  279. padding: 4rpx 12rpx;
  280. border-radius: 4rpx;
  281. text {
  282. color: #38C248;
  283. font-size: 24rpx;
  284. font-weight: 500;
  285. }
  286. }
  287. }
  288. .tag-row {
  289. .quality-tag {
  290. display: inline-block;
  291. background: linear-gradient(0deg, #FFAB26 0%, #FFD426 100%);
  292. border-radius: 21rpx 0px 21rpx 0px;
  293. padding: 2rpx 24rpx;
  294. margin-bottom: 24rpx;
  295. text {
  296. color: #fff;
  297. font-size: 24rpx;
  298. font-weight: 500;
  299. }
  300. }
  301. }
  302. }
  303. }
  304. .tips-row {
  305. display: flex;
  306. align-items: center;
  307. margin-bottom: 16rpx;
  308. text {
  309. font-size: 26rpx;
  310. color: #8D8D8D;
  311. margin-right: 10rpx;
  312. }
  313. .tips-icon {
  314. width: 36rpx;
  315. height: 36rpx;
  316. }
  317. }
  318. .promo-note {
  319. margin-bottom: 40rpx;
  320. text {
  321. font-size: 26rpx;
  322. color: #8D8D8D;
  323. }
  324. }
  325. .options-list {
  326. margin-bottom: 40rpx;
  327. .option-item {
  328. position: relative;
  329. display: flex;
  330. justify-content: space-between;
  331. align-items: center;
  332. background: #F8F8F8;
  333. border-radius: 12rpx;
  334. padding: 24rpx 30rpx;
  335. margin-bottom: 24rpx;
  336. border: 2rpx solid #dfdfdf;
  337. transition: all 0.2s;
  338. &.active {
  339. border-color: transparent;
  340. }
  341. &.disabled {
  342. background: #F0F0F0;
  343. border-color: #E0E0E0;
  344. opacity: 0.7;
  345. .opt-name,
  346. .right text {
  347. color: #999;
  348. }
  349. .opt-discount {
  350. background: #CCCCCC;
  351. }
  352. }
  353. .bg-image {
  354. position: absolute;
  355. top: -6rpx;
  356. left: -1%;
  357. width: 102%;
  358. height: 110rpx;
  359. z-index: 0;
  360. }
  361. .left,
  362. .right {
  363. position: relative;
  364. z-index: 1;
  365. }
  366. .left {
  367. display: flex;
  368. align-items: center;
  369. .opt-name {
  370. font-size: 30rpx;
  371. font-weight: bold;
  372. color: #333;
  373. margin-right: 16rpx;
  374. }
  375. .opt-discount {
  376. background: #D8D8D8;
  377. padding: 0 20rpx;
  378. border-radius: 0 20rpx 0 20rpx;
  379. text {
  380. color: #fff;
  381. font-size: 24rpx;
  382. display: inline-block;
  383. }
  384. &.active {
  385. background: linear-gradient(0deg, #30E030 0%, #28C445 100%);
  386. }
  387. }
  388. }
  389. .right {
  390. text {
  391. font-size: 28rpx;
  392. color: #333;
  393. }
  394. }
  395. }
  396. }
  397. .quantity-row {
  398. display: flex;
  399. justify-content: space-between;
  400. align-items: center;
  401. margin-bottom: 50rpx;
  402. .label {
  403. font-size: 30rpx;
  404. font-weight: bold;
  405. color: #333;
  406. }
  407. }
  408. .footer-btns {
  409. display: flex;
  410. justify-content: space-between;
  411. padding-bottom: 10rpx;
  412. .btn {
  413. flex: 1;
  414. height: 100rpx;
  415. display: flex;
  416. flex-direction: column;
  417. align-items: center;
  418. justify-content: center;
  419. font-family: Source Han Sans SC;
  420. font-weight: 500;
  421. .price {
  422. font-size: 38rpx;
  423. color: #fff;
  424. line-height: 1.2;
  425. }
  426. .desc {
  427. font-size: 24rpx;
  428. color: #fff;
  429. }
  430. .notice {
  431. font-size: 32rpx;
  432. color: #fff;
  433. }
  434. &.btn-orange {
  435. background: linear-gradient(0deg, #EFA941 0%, #FFB84F 100%);
  436. width: 340rpx;
  437. border-radius: 50rpx 0 0 50rpx;
  438. }
  439. &.btn-green {
  440. width: 340rpx;
  441. background: linear-gradient(0deg, #38C248 0%, #5FEA6F 100%);
  442. border-radius: 0 50rpx 50rpx 0;
  443. }
  444. }
  445. }
  446. </style>