| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- <template>
- <u-popup v-model="visible" mode="bottom" border-radius="24" :safe-area-inset-bottom="true" :mask-close-able="true"
- @close="close">
- <view class="popup-content">
- <!-- Header -->
- <view class="header">
- <text class="title">选择商品品相</text>
- <image src="/pages-sell/static/select-good/icon-close.png" class="close-icon" @click="close"></image>
- </view>
- <!-- Product Info -->
- <view class="product-info">
- <image :src="currentProduct.cover" class="book-cover" mode="aspectFill"></image>
- <view class="info-right">
- <view class="price-row">
- <text class="currency">¥</text>
- <text class="price">{{ displayUnitPrice }}</text>
- <view class="drop-tag">
- <text>↓可降至 ¥{{ displayMinPrice }}</text>
- </view>
- </view>
- <view class="tag-row">
- <view class="quality-tag">
- <text>品相{{ currentQualityName }}</text>
- </view>
- </view>
- </view>
- </view>
- <!-- Tips -->
- <view class="tips-row">
- <text>不同品相有什么区别</text>
- <image src="/pages-sell/static/select-good/icon-tips.png" class="tips-icon"></image>
- </view>
- <!-- Promo Note -->
- <view class="promo-note">
- <text>下单时用书购余额支付可享余额价 ( 售价 8 折优惠 )</text>
- </view>
- <!-- Options -->
- <view class="options-list">
- <view class="option-item" v-for="(opt, index) in qualityOptions" :key="index"
- :class="{ active: currentQuality === opt.conditionType }" @click="selectQuality(opt)">
- <image v-if="currentQuality === opt.conditionType" src="/pages-sell/static/select-good/selected.png"
- class="bg-image"></image>
- <view class="left">
- <text class="opt-name">{{ qualityNames[index - 1] || '未知' }}</text>
- <view class="opt-discount" :class="{ active: currentQuality === opt.conditionType }">
- <text>{{ opt.discount }}折</text>
- </view>
- </view>
- <view class="right">
- <text>¥{{ opt.price }} ( 余额价 ¥{{ opt.balanceMoney }} )</text>
- </view>
- </view>
- </view>
- <!-- Quantity -->
- <view class="quantity-row">
- <text class="label">数量</text>
- <u-number-box v-model="quantity" :min="1" :max="99"></u-number-box>
- </view>
- <!-- Footer Buttons -->
- <view class="footer-btns">
- <view class="btn btn-orange">
- <text class="price">¥0.3</text>
- <text class="desc">分享一人可降 0.5 元</text>
- </view>
- <view class="btn btn-green" @click="handleAction">
- <text v-if="hasStock" class="price">¥{{ displayTotalPrice }}</text>
- <text class="desc" :class="{ 'notice': !hasStock }">{{ hasStock ? '加入购物车' : '到货通知' }}</text>
- </view>
- </view>
- </view>
- </u-popup>
- </template>
- <script>
- export default {
- name: 'SelectGoodPopup',
- data() {
- return {
- visible: false,
- quantity: 1,
- currentQuality: 1,
- currentProduct: {},
- qualityOptions: [],
- //1-良好 2-中等 3-次品 4-全新
- qualityNames: ['良好', '中等', '次品', '全新'],
- };
- },
- computed: {
- currentQualityName() {
- const opt = this.qualityNames[this.currentQuality - 1];
- return opt || '未知';
- },
- selectedOption() {
- return this.qualityOptions.find(o => o.conditionType === this.currentQuality) || {};
- },
- displayUnitPrice() {
- return this.formatPrice(this.selectedOption.price);
- },
- displayMinPrice() {
- return this.formatPrice(this.selectedOption.balanceMoney);
- },
- displayTotalPrice() {
- const total = this.toNumber(this.selectedOption.price) * this.quantity;
- return this.formatPrice(total);
- },
- hasStock() {
- const stock = this.selectedOption.stockNum;
- if (stock === 0) return false;
- if (stock === undefined || stock === null || stock === '') return true;
- return this.toNumber(stock) > 0;
- }
- },
- methods: {
- open(product) {
- this.visible = true;
- this.quantity = 1;
- if (product.isbn) {
- this.getGoodQualityInfo(product.isbn);
- }
- },
- //根据 isbn 获取商品品相信息
- getGoodQualityInfo(isbn) {
- uni.$u.http.get('/token/shop/bookDetail', { isbn }).then(res => {
- console.log(res);
- if (res.code === 200) {
- this.currentProduct = res.data || {};
- this.qualityOptions = res.data.skuList || [];
- if (this.qualityOptions.length > 0) {
- this.currentQuality = this.qualityOptions[0].conditionType
- }
- }
- });
- },
- close() {
- this.visible = false;
- },
- selectQuality(opt) {
- this.currentQuality = opt.conditionType;
- },
- handleAction() {
- if (!this.hasStock) {
- this.handleNotify();
- return;
- }
- this.handleConfirm();
- },
- handleNotify() {
- //设置到货通知
- uni.$u.http.post('/token/shop/user/noticeArrival', {
- isbn: this.currentProduct.isbn,
- }).then(res => {
- if (res.code === 200) {
- this.$u.toast('到货通知设置成功');
- }
- }).finally(() => {
- this.close();
- });
- },
- handleConfirm() {
- if (!this.currentProduct.isbn) {
- this.$u.toast('商品信息缺失');
- return;
- }
- const selectedOption = this.selectedOption;
- const conditionType = selectedOption.conditionType || this.currentQuality;
- if (!conditionType) {
- this.$u.toast('请选择品相');
- return;
- }
- this.$u.api.addShopCartAjax({
- isbn: this.currentProduct.isbn,
- quantity: this.quantity,
- conditionType: conditionType
- }).then(res => {
- if (res.code === 200) {
- this.$u.toast('加入购物车成功');
- this.$emit('confirm', {
- product: this.currentProduct,
- quality: this.currentQuality,
- quantity: this.quantity
- });
- this.close();
- } else {
- this.$u.toast(res.msg || '加入购物车失败');
- }
- });
- },
- toNumber(value) {
- const num = Number(value);
- return Number.isFinite(num) ? num : 0;
- },
- formatPrice(value) {
- const num = this.toNumber(value);
- return num.toFixed(2);
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .popup-content {
- padding: 30rpx 30rpx 20rpx;
- background-color: #fff;
- position: relative;
- }
- .header {
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
- margin-bottom: 30rpx;
- padding-bottom: 30rpx;
- border-bottom: 2rpx dashed #eee;
- .title {
- font-size: 34rpx;
- font-weight: bold;
- color: #333;
- }
- .close-icon {
- position: absolute;
- right: 0;
- top: 0;
- width: 24rpx;
- height: 24rpx;
- padding: 10rpx;
- box-sizing: content-box;
- }
- }
- .product-info {
- display: flex;
- margin-bottom: 30rpx;
- .book-cover {
- width: 140rpx;
- height: 180rpx;
- border-radius: 8rpx;
- margin-right: 24rpx;
- background-color: #f5f5f5;
- }
- .info-right {
- flex: 1;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- padding: 10rpx 0;
- .price-row {
- display: flex;
- align-items: center;
- .currency {
- font-size: 36rpx;
- color: #D81A00;
- font-weight: bold;
- }
- .price {
- font-size: 40rpx;
- color: #D81A00;
- font-weight: bold;
- margin-right: 20rpx;
- line-height: 1;
- }
- .drop-tag {
- background: #E8F9EA;
- padding: 4rpx 12rpx;
- border-radius: 4rpx;
- text {
- color: #38C248;
- font-size: 24rpx;
- font-weight: 500;
- }
- }
- }
- .tag-row {
- .quality-tag {
- display: inline-block;
- background: linear-gradient(0deg, #FFAB26 0%, #FFD426 100%);
- border-radius: 21rpx 0px 21rpx 0px;
- padding: 2rpx 24rpx;
- margin-bottom: 24rpx;
- text {
- color: #fff;
- font-size: 24rpx;
- font-weight: 500;
- }
- }
- }
- }
- }
- .tips-row {
- display: flex;
- align-items: center;
- margin-bottom: 16rpx;
- text {
- font-size: 26rpx;
- color: #8D8D8D;
- margin-right: 10rpx;
- }
- .tips-icon {
- width: 36rpx;
- height: 36rpx;
- }
- }
- .promo-note {
- margin-bottom: 40rpx;
- text {
- font-size: 26rpx;
- color: #8D8D8D;
- }
- }
- .options-list {
- margin-bottom: 40rpx;
- .option-item {
- position: relative;
- display: flex;
- justify-content: space-between;
- align-items: center;
- background: #F8F8F8;
- border-radius: 12rpx;
- padding: 24rpx 30rpx;
- margin-bottom: 24rpx;
- border: 2rpx solid #dfdfdf;
- transition: all 0.2s;
- &.active {
- border-color: transparent;
- }
- .bg-image {
- position: absolute;
- top: -6rpx;
- left: -1%;
- width: 102%;
- height: 110rpx;
- z-index: 0;
- }
- .left,
- .right {
- position: relative;
- z-index: 1;
- }
- .left {
- display: flex;
- align-items: center;
- .opt-name {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- margin-right: 16rpx;
- }
- .opt-discount {
- background: #D8D8D8;
- padding: 0 20rpx;
- border-radius: 0 20rpx 0 20rpx;
- text {
- color: #fff;
- font-size: 24rpx;
- display: inline-block;
- }
- &.active {
- background: linear-gradient(0deg, #30E030 0%, #28C445 100%);
- }
- }
- }
- .right {
- text {
- font-size: 28rpx;
- color: #333;
- }
- }
- }
- }
- .quantity-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 50rpx;
- .label {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- }
- .footer-btns {
- display: flex;
- justify-content: space-between;
- padding-bottom: 10rpx;
- .btn {
- flex: 1;
- height: 100rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- font-family: Source Han Sans SC;
- font-weight: 500;
- .price {
- font-size: 38rpx;
- color: #fff;
- line-height: 1.2;
- }
- .desc {
- font-size: 24rpx;
- color: #fff;
- }
- .notice {
- font-size: 32rpx;
- color: #fff;
- }
- &.btn-orange {
- background: linear-gradient(0deg, #EFA941 0%, #FFB84F 100%);
- width: 340rpx;
- border-radius: 50rpx 0 0 50rpx;
- }
- &.btn-green {
- width: 340rpx;
- background: linear-gradient(0deg, #38C248 0%, #5FEA6F 100%);
- border-radius: 0 50rpx 50rpx 0;
- }
- }
- }
- </style>
|