index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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[index - 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. toNumber(value) {
  188. const num = Number(value);
  189. return Number.isFinite(num) ? num : 0;
  190. },
  191. formatPrice(value) {
  192. const num = this.toNumber(value);
  193. return num.toFixed(2);
  194. }
  195. }
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. .popup-content {
  200. padding: 30rpx 30rpx 20rpx;
  201. background-color: #fff;
  202. position: relative;
  203. }
  204. .header {
  205. display: flex;
  206. justify-content: center;
  207. align-items: center;
  208. position: relative;
  209. margin-bottom: 30rpx;
  210. padding-bottom: 30rpx;
  211. border-bottom: 2rpx dashed #eee;
  212. .title {
  213. font-size: 34rpx;
  214. font-weight: bold;
  215. color: #333;
  216. }
  217. .close-icon {
  218. position: absolute;
  219. right: 0;
  220. top: 0;
  221. width: 24rpx;
  222. height: 24rpx;
  223. padding: 10rpx;
  224. box-sizing: content-box;
  225. }
  226. }
  227. .product-info {
  228. display: flex;
  229. margin-bottom: 30rpx;
  230. .book-cover {
  231. width: 140rpx;
  232. height: 180rpx;
  233. border-radius: 8rpx;
  234. margin-right: 24rpx;
  235. background-color: #f5f5f5;
  236. }
  237. .info-right {
  238. flex: 1;
  239. display: flex;
  240. flex-direction: column;
  241. justify-content: space-between;
  242. padding: 10rpx 0;
  243. .price-row {
  244. display: flex;
  245. align-items: center;
  246. .currency {
  247. font-size: 36rpx;
  248. color: #D81A00;
  249. font-weight: bold;
  250. }
  251. .price {
  252. font-size: 40rpx;
  253. color: #D81A00;
  254. font-weight: bold;
  255. margin-right: 20rpx;
  256. line-height: 1;
  257. }
  258. .drop-tag {
  259. background: #E8F9EA;
  260. padding: 4rpx 12rpx;
  261. border-radius: 4rpx;
  262. text {
  263. color: #38C248;
  264. font-size: 24rpx;
  265. font-weight: 500;
  266. }
  267. }
  268. }
  269. .tag-row {
  270. .quality-tag {
  271. display: inline-block;
  272. background: linear-gradient(0deg, #FFAB26 0%, #FFD426 100%);
  273. border-radius: 21rpx 0px 21rpx 0px;
  274. padding: 2rpx 24rpx;
  275. margin-bottom: 24rpx;
  276. text {
  277. color: #fff;
  278. font-size: 24rpx;
  279. font-weight: 500;
  280. }
  281. }
  282. }
  283. }
  284. }
  285. .tips-row {
  286. display: flex;
  287. align-items: center;
  288. margin-bottom: 16rpx;
  289. text {
  290. font-size: 26rpx;
  291. color: #8D8D8D;
  292. margin-right: 10rpx;
  293. }
  294. .tips-icon {
  295. width: 36rpx;
  296. height: 36rpx;
  297. }
  298. }
  299. .promo-note {
  300. margin-bottom: 40rpx;
  301. text {
  302. font-size: 26rpx;
  303. color: #8D8D8D;
  304. }
  305. }
  306. .options-list {
  307. margin-bottom: 40rpx;
  308. .option-item {
  309. position: relative;
  310. display: flex;
  311. justify-content: space-between;
  312. align-items: center;
  313. background: #F8F8F8;
  314. border-radius: 12rpx;
  315. padding: 24rpx 30rpx;
  316. margin-bottom: 24rpx;
  317. border: 2rpx solid #dfdfdf;
  318. transition: all 0.2s;
  319. &.active {
  320. border-color: transparent;
  321. }
  322. .bg-image {
  323. position: absolute;
  324. top: -6rpx;
  325. left: -1%;
  326. width: 102%;
  327. height: 110rpx;
  328. z-index: 0;
  329. }
  330. .left,
  331. .right {
  332. position: relative;
  333. z-index: 1;
  334. }
  335. .left {
  336. display: flex;
  337. align-items: center;
  338. .opt-name {
  339. font-size: 30rpx;
  340. font-weight: bold;
  341. color: #333;
  342. margin-right: 16rpx;
  343. }
  344. .opt-discount {
  345. background: #D8D8D8;
  346. padding: 0 20rpx;
  347. border-radius: 0 20rpx 0 20rpx;
  348. text {
  349. color: #fff;
  350. font-size: 24rpx;
  351. display: inline-block;
  352. }
  353. &.active {
  354. background: linear-gradient(0deg, #30E030 0%, #28C445 100%);
  355. }
  356. }
  357. }
  358. .right {
  359. text {
  360. font-size: 28rpx;
  361. color: #333;
  362. }
  363. }
  364. }
  365. }
  366. .quantity-row {
  367. display: flex;
  368. justify-content: space-between;
  369. align-items: center;
  370. margin-bottom: 50rpx;
  371. .label {
  372. font-size: 30rpx;
  373. font-weight: bold;
  374. color: #333;
  375. }
  376. }
  377. .footer-btns {
  378. display: flex;
  379. justify-content: space-between;
  380. padding-bottom: 10rpx;
  381. .btn {
  382. flex: 1;
  383. height: 100rpx;
  384. display: flex;
  385. flex-direction: column;
  386. align-items: center;
  387. justify-content: center;
  388. font-family: Source Han Sans SC;
  389. font-weight: 500;
  390. .price {
  391. font-size: 38rpx;
  392. color: #fff;
  393. line-height: 1.2;
  394. }
  395. .desc {
  396. font-size: 24rpx;
  397. color: #fff;
  398. }
  399. .notice {
  400. font-size: 32rpx;
  401. color: #fff;
  402. }
  403. &.btn-orange {
  404. background: linear-gradient(0deg, #EFA941 0%, #FFB84F 100%);
  405. width: 340rpx;
  406. border-radius: 50rpx 0 0 50rpx;
  407. }
  408. &.btn-green {
  409. width: 340rpx;
  410. background: linear-gradient(0deg, #38C248 0%, #5FEA6F 100%);
  411. border-radius: 0 50rpx 50rpx 0;
  412. }
  413. }
  414. }
  415. </style>