index.vue 9.9 KB

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