Commit 3d831121 authored by zhengke's avatar zhengke

修改商品页

parent 5723292a
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<text>{{ goodprice }}</text> <text>{{ goodprice }}</text>
</view> </view>
<view class="amount">库存 {{ goodamount }} {{ g.unit }}</view> <view class="amount">库存 {{ goodamount }} {{ g.unit }}</view>
<view class="sku">{{ skuObj ? "已选择" : "选择" }} {{ sku }}</view> <view class="sku">{{ skuObj ? '已选择' : '选择' }} {{ sku }}</view>
</view> </view>
</view> </view>
<view class="sku-box"> <view class="sku-box">
...@@ -31,18 +31,14 @@ ...@@ -31,18 +31,14 @@
class="sku-chi" class="sku-chi"
:style="{ :style="{
background: y.attr_id == x.checkId ? mc : '#eee', background: y.attr_id == x.checkId ? mc : '#eee',
color: y.attr_id == x.checkId ? '#FFF' : '#333', color: y.attr_id == x.checkId ? '#FFF' : '#333'
}" }"
:class="{ disable: notStockGood.indexOf(y.attr_id) != -1 }" :class="{ disable: notStockGood.indexOf(y.attr_id) != -1 }"
v-for="(y, yi) in x.attr_list" v-for="(y, yi) in x.attr_list"
:key="yi" :key="yi"
@click="clickSkuItemHandler(yi, i)" @click="clickSkuItemHandler(yi, i)"
> >
<image <image :src="y.pic_url" class="img" v-if="i == 0 && y.pic_url"></image>
:src="y.pic_url"
class="img"
v-if="i == 0 && y.pic_url"
></image>
<text class="val">{{ y.attr_name }}</text> <text class="val">{{ y.attr_name }}</text>
</view> </view>
</view> </view>
...@@ -50,33 +46,11 @@ ...@@ -50,33 +46,11 @@
</view> </view>
<view class="count-box"> <view class="count-box">
<text class="label">购买数量</text> <text class="label">购买数量</text>
<u-number-box <u-number-box :disabled="!skuObj" v-model="gc" :min="1" :max="goodamount" @change="valChange"></u-number-box>
:disabled="!skuObj"
v-model="gc"
:min="1"
:max="goodamount"
@change="valChange"
></u-number-box>
</view> </view>
<view class="btn-box"> <view class="btn-box">
<view style="flex: 1;" v-if="optionType != 1"> <view style="flex: 1;" v-if="optionType != 1"><u-button @click="joinCar" :ripple="true" :hair-line="false" :custom-style="btn1">加入购物车</u-button></view>
<u-button <view style="flex: 1;" v-if="optionType != 0"><u-button @click="buy" :ripple="true" :hair-line="false" :custom-style="btn2">立即购买</u-button></view>
@click="joinCar"
:ripple="true"
:hair-line="false"
:custom-style="btn1"
>加入购物车</u-button
>
</view>
<view style="flex: 1;" v-if="optionType != 0">
<u-button
@click="buy"
:ripple="true"
:hair-line="false"
:custom-style="btn2"
>立即购买</u-button
>
</view>
</view> </view>
</view> </view>
</u-popup> </u-popup>
...@@ -88,83 +62,94 @@ export default { ...@@ -88,83 +62,94 @@ export default {
props: { props: {
borderRadius: { borderRadius: {
type: [String, Number], type: [String, Number],
default: 0, default: 0
}, },
value: { value: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
maskCloseAble: { maskCloseAble: {
type: Boolean, type: Boolean,
default: true, default: true
}, },
safeAreaInsetBottom: { safeAreaInsetBottom: {
type: Boolean, type: Boolean,
default: true, default: true
}, },
good: { good: {
type: Object, type: Object,
default: {}, default: {}
}, },
optionType: { optionType: {
type: [String, Number], type: [String, Number],
default: 0, default: 0
}, },
skued: { skued: {
type: Object, type: Object,
default: {}, default: {}
}, }
}, },
data() { data() {
return { return {
goodimage: "", goodimage: '',
goodprice: "", goodprice: '',
goodamount: "", goodamount: '',
mc: "", mc: '',
secondary: "", secondary: '',
gc: 1, gc: 1,
bian: false, bian: false,
btn1: { btn1: {
flex: 1, flex: 1,
height: "100%", height: '100%',
borderRadius: "40px", borderRadius: '40px',
border: "none", border: 'none',
color: "#FFF", color: '#FFF',
fontSize: "13px", fontSize: '13px',
width: "100%", width: '100%'
}, },
btn2: { btn2: {
flex: 1, flex: 1,
height: "100%", height: '100%',
borderRadius: "40px", borderRadius: '40px',
border: "none", border: 'none',
color: "#FFF", color: '#FFF',
fontSize: "13px", fontSize: '13px',
width: "100%", width: '100%'
}, },
sku: "", sku: '',
g: {}, g: {},
skuObj: null, skuObj: null,
notStockGood: [], notStockGood: [],
forms:{ forms: {
list: [ list: [
{ {
mch_id: 0, mch_id: 0,
goods_list: [], goods_list: [],
distance: 0, distance: 0,
remark: "", remark: '',
order_form: [], order_form: [],
use_integral: 0, use_integral: 0,
user_coupon_id: 0, user_coupon_id: 0
}, }
], ],
address_id: 0, address_id: 0
} }
}; };
}, },
mounted() { mounted() {
this.g = this.good; this.request2(
{
url: '/api/AppletGoods/GetAppletGoodsInfo',
data: {
GoodsId: this.good.id
}
},
res => {
console.log(res, 'resssssss');
this.g = res.data.goods;
this.goodimage = this.g.cover_pic;
this.mc = this.$uiConfig.mainColor; this.mc = this.$uiConfig.mainColor;
this.secondary = this.$uiConfig.secondary; this.secondary = this.$uiConfig.secondary;
this.skuObj = this.skued.id ? this.skued : null; this.skuObj = this.skued.id ? this.skued : null;
...@@ -174,23 +159,25 @@ export default { ...@@ -174,23 +159,25 @@ export default {
this.goodamount = this.skuObj.stock; this.goodamount = this.skuObj.stock;
} else { } else {
this.goodimage = this.g.cover_pic; this.goodimage = this.g.cover_pic;
this.goodprice = this.g.price_min && this.g.price_min!="" ?this.g.price_min:this.g.price_content; this.goodprice = this.g.price_min && this.g.price_min != '' ? this.g.price_min : this.g.price_content;
this.goodamount = this.g.goods_stock; this.goodamount = this.g.goods_stock;
} }
this.bian = this.$utils.is_biang; this.bian = this.$utils.is_biang;
this.btn1.background = this.secondary; this.btn1.background = this.secondary;
this.btn2.background = this.mc; this.btn2.background = this.mc;
if (this.optionType == 2) { if (this.optionType == 2) {
this.btn1.borderRadius = "40px 0 0 40px"; this.btn1.borderRadius = '40px 0 0 40px';
this.btn2.borderRadius = "0 40px 40px 0"; this.btn2.borderRadius = '0 40px 40px 0';
} }
console.log(this.skued); if (this.g.attr_groups && this.g.attr_groups.length > 0) {
this.g.attr_groups.forEach((x) => { this.g.attr_groups.forEach(x => {
if (!this.skuObj) { if (!this.skuObj) {
(x.checkId = 0), (x.checkName = x.attr_group_name); //(x.checkId = 0), (x.checkName = x.attr_group_name);
(x.checkId = 0), (x.checkName = x.attr_list[0].attr_name);
x.checkId = x.attr_list[0].attr_id;
} else { } else {
let sign = `:${this.skuObj.sign_id}:`; let sign = `:${this.skuObj.sign_id}:`;
x.attr_list.forEach((y) => { x.attr_list.forEach(y => {
if (sign.indexOf(`:${y.attr_id}:`) != -1) { if (sign.indexOf(`:${y.attr_id}:`) != -1) {
x.checkId = y.attr_id; x.checkId = y.attr_id;
x.checkName = y.attr_name; x.checkName = y.attr_name;
...@@ -198,41 +185,45 @@ export default { ...@@ -198,41 +185,45 @@ export default {
}); });
} }
}); });
}
this.formatDisableSku(); this.formatDisableSku();
this.formatChosenTips(); this.formatChosenTips();
}
);
// this.g = this.good;
}, },
methods: { methods: {
joinCar() { joinCar() {
let h = this.apiheader(); let h = this.apiheader();
h["content-type"] = "application/x-www-form-urlencoded"; h['content-type'] = 'application/x-www-form-urlencoded';
if (this.skuObj && this.skuObj.id) { if (this.skuObj && this.skuObj.id) {
this.request( this.request(
{ {
url: "", url: '',
data: { data: {
r: "api/cart/add", r: 'api/cart/add',
goods_id: this.g.id, goods_id: this.g.id,
attr: this.skuObj.id, attr: this.skuObj.id,
num: this.gc == 0 ? 1 : this.gc, num: this.gc == 0 ? 1 : this.gc
}, },
header: h, header: h,
method: "POST", method: 'POST'
}, },
(res) => { res => {
uni.showToast({ uni.showToast({
title: "加入购物车成功", title: '加入购物车成功',
icon: "success", icon: 'success',
duration: 2000, duration: 2000
}); });
this.popupClose(); this.popupClose();
} }
); );
} else { } else {
uni.showToast({ uni.showToast({
title: "请选择商品", title: '请选择商品',
position: "bottom", position: 'bottom',
icon: "none", icon: 'none',
duration: 2000, duration: 2000
}); });
} }
}, },
...@@ -243,29 +234,28 @@ export default { ...@@ -243,29 +234,28 @@ export default {
num: this.gc, num: this.gc,
cart_id: 0, cart_id: 0,
goods_attr_id: this.skuObj.id, goods_attr_id: this.skuObj.id,
attr: [], attr: []
}; };
this.skuObj.attr_list.forEach((x) => { this.skuObj.attr_list.forEach(x => {
g.attr.push({ g.attr.push({
attr_id: x.attr_id, attr_id: x.attr_id,
attr_group_id: x.attr_group_id, attr_group_id: x.attr_group_id
}); });
}); });
this.forms.list[0].goods_list.push(g) this.forms.list[0].goods_list.push(g);
this.forms.list[0].mch_id=this.g.mch_id this.forms.list[0].mch_id = this.g.mch_id;
uni.navigateTo({ uni.navigateTo({
url: url: '/pages/order-submit/order-submit?formData=' + encodeURIComponent(JSON.stringify(this.forms)),
"/pages/order-submit/order-submit?formData=" + encodeURIComponent(JSON.stringify(this.forms)),
complete(res) { complete(res) {
console.log(res); console.log(res);
}, }
}); });
} else { } else {
uni.showToast({ uni.showToast({
title: "请选择商品", title: '请选择商品',
position: "bottom", position: 'bottom',
icon: "none", icon: 'none',
duration: 2000, duration: 2000
}); });
} }
}, },
...@@ -280,9 +270,7 @@ export default { ...@@ -280,9 +270,7 @@ export default {
this.g.attr_groups[groupRow].checkName = temp.attr_name; this.g.attr_groups[groupRow].checkName = temp.attr_name;
} else { } else {
this.g.attr_groups[groupRow].checkId = 0; this.g.attr_groups[groupRow].checkId = 0;
this.g.attr_groups[groupRow].checkName = this.g.attr_groups[ this.g.attr_groups[groupRow].checkName = this.g.attr_groups[groupRow].attr_group_name;
groupRow
].attr_group_name;
} }
this.formatDisableSku(); this.formatDisableSku();
this.$forceUpdate(); this.$forceUpdate();
...@@ -290,20 +278,24 @@ export default { ...@@ -290,20 +278,24 @@ export default {
} }
}, },
formatChosenTips() { formatChosenTips() {
let unchosen = ""; let unchosen = '';
let chosen = ""; let chosen = '';
this.g.attr_groups.forEach((x) => { if (this.g.attr_groups && this.g.attr_groups.length > 0) {
if (x.checkId != 0) { this.g.attr_groups.forEach(x => {
chosen += (chosen == "" ? "" : ",") + x.checkName; // if (x.checkId != 0) {
if (x.checkId != -1) {
chosen += (chosen == '' ? '' : ',') + x.checkName;
} else { } else {
unchosen += (unchosen == "" ? "" : ",") + x.attr_group_name; unchosen += (unchosen == '' ? '' : ',') + x.attr_group_name;
} }
}); });
if (unchosen != "") { }
if (unchosen != '') {
this.sku = unchosen; this.sku = unchosen;
this.skuObj = null; this.skuObj = null;
this.goodimage = this.g.cover_pic; this.goodimage = this.g.cover_pic;
this.goodprice = this.g.price_min && this.g.price_min!="" ?this.g.price_min:this.g.price_content; this.goodprice = this.g.price_min && this.g.price_min != '' ? this.g.price_min : this.g.price_content;
this.goodamount = this.g.goods_stock; this.goodamount = this.g.goods_stock;
} else { } else {
this.sku = chosen; this.sku = chosen;
...@@ -312,7 +304,8 @@ export default { ...@@ -312,7 +304,8 @@ export default {
}, },
formatDisableSku() { formatDisableSku() {
let sign = []; let sign = [];
this.g.attr_groups.forEach((x) => { if (this.g.attr_groups && this.g.attr_groups.length > 0) {
this.g.attr_groups.forEach(x => {
if (x.checkId != 0) { if (x.checkId != 0) {
sign.push(`${x.checkId}`); sign.push(`${x.checkId}`);
} }
...@@ -321,9 +314,9 @@ export default { ...@@ -321,9 +314,9 @@ export default {
if (sign.length == this.g.attr_groups.length - 1) { if (sign.length == this.g.attr_groups.length - 1) {
this.formatDisable(sign); this.formatDisable(sign);
} else if (sign.length == this.g.attr_groups.length) { } else if (sign.length == this.g.attr_groups.length) {
let t = sign.join(":"); let t = sign.join(':');
let len = -1; let len = -1;
this.g.attr.forEach((x) => { this.g.attr.forEach(x => {
if (x.sign_id == t && x.stock == 0) { if (x.sign_id == t && x.stock == 0) {
len = this.g.attr_groups.length - 1; len = this.g.attr_groups.length - 1;
} }
...@@ -336,14 +329,15 @@ export default { ...@@ -336,14 +329,15 @@ export default {
this.formatDisable(sign.splice(sign.length - 1, 1)); this.formatDisable(sign.splice(sign.length - 1, 1));
} }
} }
}
}, },
formatDisable(sign) { formatDisable(sign) {
this.notStockGood = []; this.notStockGood = [];
this.g.attr.forEach((x) => { this.g.attr.forEach(x => {
if (x.stock == 0) { if (x.stock == 0) {
let t = x.sign_id.split(":"); let t = x.sign_id.split(':');
let t1 = []; let t1 = [];
t.forEach((x) => { t.forEach(x => {
if (sign.indexOf(x) == -1) { if (sign.indexOf(x) == -1) {
t1.push(x); t1.push(x);
} }
...@@ -356,39 +350,40 @@ export default { ...@@ -356,39 +350,40 @@ export default {
this.$forceUpdate(); this.$forceUpdate();
}, },
formatSku() { formatSku() {
let sign = ""; let sign = '';
this.g.attr_groups.forEach((x) => { if (this.g.attr_groups && this.g.attr_groups.length > 0) {
if (x.checkId != 0) { this.g.attr_groups.forEach(x => {
sign += (sign == "" ? "" : ":") + x.checkId; if (x.checkId != -1) {
sign += (sign == '' ? '' : ':') + x.checkId;
} }
}); });
this.g.attr.forEach((x) => { }
if (this.g.attr && this.g.attr.length) {
this.g.attr.forEach(x => {
if (x.sign_id == sign) { if (x.sign_id == sign) {
this.skuObj = x; this.skuObj = x;
} }
}); });
}
if (this.skuObj != null) { if (this.skuObj != null) {
this.goodimage = this.skuObj.pic_url || this.g.cover_pic; this.goodimage = this.skuObj.pic_url || this.g.cover_pic;
this.goodprice = ( this.goodprice = (parseFloat(this.skuObj.price) * parseFloat(this.gc)).toFixed(2);
parseFloat(this.skuObj.price) * parseFloat(this.gc)
).toFixed(2);
this.goodamount = this.skuObj.stock; this.goodamount = this.skuObj.stock;
} }
}, },
// 弹窗关闭 // 弹窗关闭
popupClose() { popupClose() {
this.$emit("close", this.skuObj); this.$emit('close', this.skuObj);
this.$emit("input", false); this.$emit('input', false);
}, },
valChange(e) { valChange(e) {
this.gc = e.value; this.gc = e.value;
if (this.skuObj) { if (this.skuObj) {
this.goodprice = ( this.goodprice = (parseFloat(this.skuObj.price) * parseFloat(this.gc)).toFixed(2);
parseFloat(this.skuObj.price) * parseFloat(this.gc) }
).toFixed(2); }
} }
},
},
}; };
</script> </script>
...@@ -417,7 +412,7 @@ export default { ...@@ -417,7 +412,7 @@ export default {
} }
.goodsku .goods .chosen-info .price { .goodsku .goods .chosen-info .price {
font-size: 24px; font-size: 24px;
font-family: "oswald"; font-family: 'oswald';
font-weight: unset; font-weight: unset;
} }
.goodsku .goods .chosen-info .price .small { .goodsku .goods .chosen-info .price .small {
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</div> </div>
<div class="good-price-info"> <div class="good-price-info">
<span class="price" :style="{ color: mainColor }">{{ <span class="price" :style="{ color: mainColor }">{{
goodsInfo.showGoodsPrice ? item.price : "" goodsInfo.showGoodsPrice ? getPrice(item.price) : ""
}}</span> }}</span>
<span class="buy" v-if="goodsInfo.showBuyBtn" @click.stop="showSkuHandler(item)"> <span class="buy" v-if="goodsInfo.showBuyBtn" @click.stop="showSkuHandler(item)">
<u-icon <u-icon
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
</view> </view>
<view class="good-price-info"> <view class="good-price-info">
<view class="price" :style="{'color':mainColor}">{{ <view class="price" :style="{'color':mainColor}">{{
goodsInfo.showGoodsPrice ? item.price : "" goodsInfo.showGoodsPrice ? getPrice(item.price) : ""
}}</view> }}</view>
<view class="buy" v-if="goodsInfo.showBuyBtn"> <view class="buy" v-if="goodsInfo.showBuyBtn">
<u-icon <u-icon
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
</div> </div>
<div class="good-price-info"> <div class="good-price-info">
<view class="price" :style="{'color':mainColor}">{{ <view class="price" :style="{'color':mainColor}">{{
goodsInfo.showGoodsPrice ? item.price : "" goodsInfo.showGoodsPrice ? getPrice(item.price) : ""
}}</view> }}</view>
<view class="buy" v-if="goodsInfo.showBuyBtn" @click.stop="showSkuHandler(item)"> <view class="buy" v-if="goodsInfo.showBuyBtn" @click.stop="showSkuHandler(item)">
<u-icon <u-icon
......
...@@ -109,18 +109,18 @@ export default { ...@@ -109,18 +109,18 @@ export default {
this.showSku=true this.showSku=true
}, },
//格式化价格添加.00 //格式化价格添加.00
getPrice(value){ // getPrice(value){
var html,_val; // var html,_val;
value =Number(value).toFixed(2); // value =Number(value).toFixed(2);
if(value==0){ // if(value==0){
value=0; // value=0;
return html = "¥0"; // return html = "¥0";
}else if(value.split('.')[1].substring(1)==0){ // }else if(value.split('.')[1].substring(1)==0){
value = Number(value).toFixed(2); // value = Number(value).toFixed(2);
} // }
_val = value.split('.'); // _val = value.split('.');
return html = '¥'+_val[0]+'.'+_val[1]; // return html = '¥'+_val[0]+'.'+_val[1];
} // }
}, },
}; };
</script> </script>
......
...@@ -40,9 +40,9 @@ ...@@ -40,9 +40,9 @@
</view> </view>
<view class="good-price-info"> <view class="good-price-info">
<view class="price" :style="{'color':mainColor}">{{ <view class="price" :style="{'color':mainColor}">{{
goodsInfo.showGoodsPrice ? item.price : "" goodsInfo.showGoodsPrice ? getPrice(item.price) : ""
}}</view> }}</view>
<view class="buy" v-if="goodsInfo.showBuyBtn"> <view class="buy" v-if="goodsInfo.showBuyBtn" @click.stop="showSkuHandler(item)">
<u-icon <u-icon
name="cart-o" name="cart-o"
size="40" size="40"
...@@ -78,17 +78,22 @@ ...@@ -78,17 +78,22 @@
</view> </view>
</view> </view>
</view> </view>
<view style="color:rgba(0,0,0,0);font-size:12px;">0</view> <good-sku v-if="showSku" :option-type="2" borderRadius="20" v-model="showSku" :good="sku"></good-sku>
</view> </view>
</template> </template>
<script> <script>
import goodSku from '../goods/goodsku'
export default { export default {
components:{
goodSku
},
props: ["goodList", "goodsInfo"], props: ["goodList", "goodsInfo"],
data() { data() {
return { return {
mainColor: "", mainColor: "",
activeKey: 0, activeKey: 0,
showSku:false,
sku:{}
}; };
}, },
created() { created() {
...@@ -98,6 +103,10 @@ export default { ...@@ -98,6 +103,10 @@ export default {
openGood(e) { openGood(e) {
console.log(e); console.log(e);
}, },
showSkuHandler(g){
this.sku=g
this.showSku=true
},
}, },
}; };
</script> </script>
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
}}</view> }}</view>
<view class="good-price-info"> <view class="good-price-info">
<view class="price" :style="{'color':mainColor}">{{ <view class="price" :style="{'color':mainColor}">{{
goodsInfo.showGoodsPrice ? item.price : "" goodsInfo.showGoodsPrice ? getPrice(item.price) : ""
}}</view> }}</view>
<view class="buy" v-if="goodsInfo.showBuyBtn"> <view class="buy" v-if="goodsInfo.showBuyBtn">
<u-icon <u-icon
......
...@@ -44,9 +44,9 @@ export default { ...@@ -44,9 +44,9 @@ export default {
'content-type': "application/json" 'content-type': "application/json"
}, },
data: { data: {
"MallBaseId": 1, MallBaseId: 1,
"TenantId": 1, TenantId: 1,
"OpenId": this.GetOpenId().OpenId, OpenId: this.GetOpenId().OpenId,
UserId:this.GetOpenId().UserId, UserId:this.GetOpenId().UserId,
MiniAppId: this.GetMiniAppId(), MiniAppId: this.GetMiniAppId(),
msg: param.data msg: param.data
...@@ -97,6 +97,11 @@ export default { ...@@ -97,6 +97,11 @@ export default {
return str; return str;
} }
} }
//价格返回.00
Vue.prototype.getPrice = function(val){
val =Number(val).toFixed(2);
return val
}
Vue.prototype.apiheader = function() { Vue.prototype.apiheader = function() {
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment