index.vue 10 KB

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