index.vue 10 KB

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