| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- <template>
- <up-popup :show="showPopup" :closeOnClickOverlay="true" @close="close">
- <view
- class="product-window"
- :class="(iSbnt ? 'join' : '') + ' ' + (iScart ? 'joinCart' : '')"
- >
- <view class="textpic acea-row row-between-wrapper">
- <view class="pictrue">
- <image :src="attr.productSelect.image"></image>
- </view>
- <view class="text">
- <view class="line1">
- {{ attr.productSelect.storeName }}
- </view>
- <view class="money font-color">
- ¥<text class="num">{{ calcNumPrice }}</text>
- <text class="stock" v-if="isShow"
- >库存: {{ attr.productSelect.stock }}</text
- >
- <text class="stock" v-if="limitNum"
- >限量: {{ attr.productSelect.quota }}</text
- >
- </view>
- </view>
- <view class="iconfont icon-guanbi" @click="close"></view>
- </view>
- <view class="rollTop">
- <view class="productWinList">
- <view
- class="item"
- v-for="(item, indexw) in attr.productAttr"
- :key="indexw"
- >
- <view class="title">{{ item.attrName }}</view>
- <view class="listn acea-row row-middle">
- <view
- class="itemn"
- :class="item.index === itemn ? 'on' : ''"
- v-for="(itemn, indexn) in item.attrValues"
- @click="tapAttr(indexw, indexn)"
- :key="indexn"
- >
- {{ itemn }}
- </view>
- </view>
- </view>
- </view>
- <view class="cart acea-row row-between-wrapper">
- <view class="title">数量</view>
- <view class="carnum acea-row row-left">
- <view
- class="item reduce"
- :class="attr.productSelect.cart_num <= 1 ? 'on' : ''"
- @click="CartNumDes"
- >
- -
- </view>
- <view class="item num">
- <input
- type="number"
- v-model="attr.productSelect.cart_num"
- data-name="productSelect.cart_num"
- @input="bindCode(attr.productSelect.cart_num)"
- />
- </view>
- <view
- v-if="iSplus"
- class="item plus"
- :class="
- attr.productSelect.cart_num >= attr.productSelect.stock
- ? 'on'
- : ''
- "
- @click="CartNumAdd"
- >
- +
- </view>
- <view
- v-else
- class="item plus"
- :class="
- attr.productSelect.cart_num >= attr.productSelect.quota ||
- attr.productSelect.cart_num >= attr.productSelect.stock ||
- attr.productSelect.cart_num >= attr.productSelect.num
- ? 'on'
- : ''
- "
- @click="CartNumAdd"
- >+</view
- >
- </view>
- </view>
- </view>
- <view class="footer-box">
- <up-button
- v-if="attr.productSelect.stock > 0"
- class="confirm-btn"
- @click="submit"
- type="primary"
- text="确定"
- ></up-button>
- <up-button
- v-else
- class="confirm-btn"
- @click="submit"
- type="primary"
- text="已售罄"
- ></up-button>
- </view>
- </view>
- </up-popup>
- </template>
- <script setup>
- import { computed } from "vue";
- const props = defineProps({
- attr: {
- type: Object,
- default: () => ({}),
- },
- showPopup: {
- type: Boolean,
- default: false,
- },
- limitNum: {
- type: Number,
- default: 0,
- },
- isShow: {
- type: Number,
- default: 0,
- },
- iSbnt: {
- type: Number,
- default: 0,
- },
- iSplus: {
- type: Number,
- default: 0,
- },
- iScart: {
- type: Number,
- default: 0,
- },
- });
- const emit = defineEmits([
- "goCat",
- "iptCartNum",
- "myevent",
- "ChangeCartNum",
- "attrVal",
- "ChangeAttr",
- "submit",
- "closePopup",
- ]);
- const calcNumPrice = computed(() => {
- // 检查数据是否存在
- if (!props.attr?.productSelect) {
- return '0.00'
- }
-
- const { storePrice, cart_num } = props.attr.productSelect
-
- // 检查价格和数量是否存在且有效
- if (!storePrice || !cart_num) {
- return '0.00'
- }
-
- // 转换为数字并验证
- const price = Number(storePrice)
- const quantity = Number(cart_num)
-
- // 检查是否为有效数字
- if (isNaN(price) || isNaN(quantity)) {
- return '0.00'
- }
-
- // 检查是否为负数
- if (price < 0 || quantity < 0) {
- return '0.00'
- }
-
- // 计算总价并保留两位小数
- const total = price * quantity
- return total.toFixed(2)
- })
- function goCat() {
- emit("goCat");
- }
- function bindCode() {
- emit("iptCartNum", props.attr.productSelect.cart_num);
- }
- function close() {
- emit("closePopup");
- }
- function submit() {
- emit("submit");
- }
- function CartNumDes() {
- emit("ChangeCartNum", false);
- }
- function CartNumAdd() {
- emit("ChangeCartNum", true);
- }
- function tapAttr(indexw, indexn) {
- emit("attrVal", { indexw, indexn });
- // 直接修改 props 不推荐,建议父组件传递响应式对象
- if (props.attr.productAttr && props.attr.productAttr[indexw]) {
- props.attr.productAttr[indexw].index =
- props.attr.productAttr[indexw].attrValues[indexn];
- }
- const value = getCheckedValue().join(",");
- emit("ChangeAttr", value);
- }
- function getCheckedValue() {
- const productAttr = props.attr.productAttr || [];
- const value = [];
- for (let i = 0; i < productAttr.length; i++) {
- for (let j = 0; j < productAttr[i].attrValues.length; j++) {
- if (productAttr[i].index === productAttr[i].attrValues[j]) {
- value.push(productAttr[i].attrValues[j]);
- }
- }
- }
- return value;
- }
- </script>
- <style scoped lang="scss">
- .product-window {
- width: 100%;
- background-color: #fff;
- border-radius: 16rpx 16rpx 0 0;
- padding-bottom: 40rpx;
- &.join,
- &.joinCart {
- padding-bottom: 30rpx;
- }
- &.joinCart {
- z-index: 999;
- }
- .textpic {
- padding: 0 130rpx 0 30rpx;
- margin-top: 29rpx;
- position: relative;
- .pictrue {
- width: 150rpx;
- height: 150rpx;
- image {
- width: 100%;
- height: 100%;
- border-radius: 10rpx;
- }
- }
- .text {
- width: 410rpx;
- font-size: 32rpx;
- color: #333333;
- .money {
- font-size: 24rpx;
- margin-top: 40rpx;
- .num {
- font-size: 36rpx;
- }
- .stock {
- color: #999;
- margin-left: 18rpx;
- }
- }
- }
- .iconfont {
- position: absolute;
- right: 30rpx;
- top: -5rpx;
- font-size: 35rpx;
- color: #8a8a8a;
- }
- }
- .rollTop {
- max-height: 500rpx;
- overflow: auto;
- margin-top: 36rpx;
- }
- .footer-box {
- padding: 0 30rpx;
- margin: 30rpx 0 0 0;
- .confirm-btn {
- border-radius: 100rpx;
- background-color: $header-color;
- border-color: $header-color;
- }
- }
- .productWinList {
- .item {
- & + .item {
- margin-top: 36rpx;
- }
- .title {
- font-size: 30rpx;
- color: #999;
- padding: 0 30rpx;
- }
- .listn {
- padding: 0 30rpx 0 16rpx;
- .itemn {
- border: 1px solid #f2f2f2;
- font-size: 26rpx;
- color: #282828;
- padding: 7rpx 33rpx;
- border-radius: 40rpx;
- margin: 20rpx 0 0 14rpx;
- background-color: #f2f2f2;
- &.on {
- color: $theme-color;
- background: rgba(255, 244, 243, 1);
- border-color: $theme-color;
- }
- &.limit {
- color: #999;
- text-decoration: line-through;
- }
- }
- }
- }
- }
- .cart {
- margin-top: 36rpx;
- padding: 0 30rpx;
- .title {
- font-size: 30rpx;
- color: #999;
- }
- .carnum {
- height: 54rpx;
- margin-top: 24rpx;
- view {
- width: 84rpx;
- text-align: center;
- height: 100%;
- line-height: 54rpx;
- color: #282828;
- font-size: 45rpx;
- }
- .reduce {
- border-right: 0;
- border-radius: 6rpx 0 0 6rpx;
- line-height: 48rpx;
- &.on {
- color: #dedede;
- font-size: 44rpx;
- }
- }
- .plus {
- border-left: 0;
- border-radius: 0 6rpx 6rpx 0;
- line-height: 46rpx;
- &.on {
- border-color: #e3e3e3;
- color: #dedede;
- }
- }
- .num {
- background: rgba(242, 242, 242, 1);
- color: #282828;
- font-size: 28rpx;
- border-radius: 12rpx;
- line-height: 29px;
- height: 54rpx;
- input {
- display: -webkit-inline-box;
- }
- }
- }
- }
- .joinBnt {
- font-size: 30rpx;
- width: 620rpx;
- height: 86rpx;
- border-radius: 50rpx;
- text-align: center;
- line-height: 86rpx;
- color: #fff;
- margin: 21rpx auto 0 auto;
- &.on {
- background-color: #bbb;
- color: #fff;
- }
- }
- }
- </style>
|