|
|
@@ -50,34 +50,24 @@
|
|
|
</view>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import { mapGetters } from "vuex";
|
|
|
-import AppTabs from "@/components/plugin/tabs";
|
|
|
import TuiListCell from "@/components/plugin/list-cell";
|
|
|
import AppDeliveryModule from "@/components/app-delivery";
|
|
|
-import AppTrademark from "@/components/module/app-trademark";
|
|
|
import AppListModule from "@/components/module/app-order-list2";
|
|
|
-import AppCouponSel from "@/components/app-coupon-sel";
|
|
|
-import AlertModule from "@/components/plugin/alert";
|
|
|
import { getShopUser } from "@/utils/auth";
|
|
|
import { getOrderShop } from "@/utils/config";
|
|
|
-import { createOrder,freight } from "@/api/order";
|
|
|
+import { createOrder } from "@/api/order";
|
|
|
import { getUserDistance, getHasMap } from "@/api/express";
|
|
|
export default {
|
|
|
name: "buy",
|
|
|
components: {
|
|
|
- AppTabs,
|
|
|
AppDeliveryModule,
|
|
|
TuiListCell,
|
|
|
- AppListModule,
|
|
|
- AppCouponSel,
|
|
|
- AppTrademark,
|
|
|
- AlertModule
|
|
|
+ AppListModule
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ option: {},
|
|
|
goodsInfo: {},
|
|
|
- tabIndex: 0,
|
|
|
- showAlert: false,
|
|
|
form: {
|
|
|
sendDistance:"",
|
|
|
goodsId: "",
|
|
|
@@ -88,85 +78,94 @@ export default {
|
|
|
lat:'',
|
|
|
long:''
|
|
|
},
|
|
|
- discountArr: false,
|
|
|
freightPrice: 0,
|
|
|
- goodsNum: 1,
|
|
|
showDistance: 0,
|
|
|
goodsTotalPrice: 0,
|
|
|
- memberDiscount: 1,
|
|
|
- couponDiscountAmount: 0,
|
|
|
hasMap: 0 // 是否具备定位功能 0不具备 1具备
|
|
|
};
|
|
|
},
|
|
|
+ onLoad(option) {
|
|
|
+ this.option = option || {};
|
|
|
+ this.init();
|
|
|
+ },
|
|
|
mounted() {},
|
|
|
computed: {
|
|
|
- ...mapGetters({ orderShop: "getOrderShop" }),
|
|
|
- ...mapGetters({ shopUser: "getShopUser" }),
|
|
|
mayPayAmount(){
|
|
|
- let price = this.goodsInfo.price * this.goodsInfo.buyNum
|
|
|
+ let price = (this.goodsInfo.price || 0) * (this.goodsInfo.buyNum || 0)
|
|
|
price = Number(this.freightPrice)+Number(price)
|
|
|
return parseFloat(price.toFixed(2))
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
init() {
|
|
|
- let goodsInfo = uni.getStorageSync("buyGoodsDetil")
|
|
|
+ let goodsInfo = uni.getStorageSync("buyGoodsDetil") || {}
|
|
|
|
|
|
getOrderShop()
|
|
|
getShopUser();
|
|
|
|
|
|
- goodsInfo.buyNum = this.option.goodsNum;
|
|
|
- this.goodsInfo = goodsInfo;
|
|
|
+ const goodsNum = Number(this.option.goodsNum || goodsInfo.buyNum || 0)
|
|
|
+ goodsInfo.buyNum = goodsNum
|
|
|
+ this.goodsInfo = goodsInfo
|
|
|
|
|
|
- this.form.goodsId = this.option.goodsId
|
|
|
- this.form.goodsNum = this.option.goodsNum
|
|
|
+ this.form.goodsId = this.option.goodsId || ""
|
|
|
+ this.form.goodsNum = goodsNum
|
|
|
|
|
|
- this.goodsTotalPrice = goodsInfo.price * this.option.goodsNum;
|
|
|
- this.goodsTotalPrice = this.goodsTotalPrice.toFixed(2)
|
|
|
- this.goodsTotalPrice = parseFloat(this.goodsTotalPrice)
|
|
|
+ const total = Number(goodsInfo.price || 0) * goodsNum
|
|
|
+ this.goodsTotalPrice = parseFloat(total.toFixed(2))
|
|
|
|
|
|
getHasMap().then(res => {
|
|
|
- this.hasMap = res.data.hasMap || 0
|
|
|
+ this.hasMap = (res.data && res.data.hasMap) ? res.data.hasMap : 0
|
|
|
})
|
|
|
|
|
|
},
|
|
|
changeSendType(num){
|
|
|
this.form.sendType = num
|
|
|
if(num == 2){
|
|
|
- this.changeAddress()
|
|
|
+ this.$nextTick(()=>{
|
|
|
+ this.changeAddress()
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
changeAddress() {
|
|
|
- let lat = this.$refs.appDelivery.region.latitude;
|
|
|
- let long = this.$refs.appDelivery.region.longitude;
|
|
|
+ const ref = this.$refs.appDelivery
|
|
|
+ if(!ref || !ref.region) return
|
|
|
+ let lat = ref.region.latitude;
|
|
|
+ let long = ref.region.longitude;
|
|
|
this.form.lat = lat
|
|
|
this.form.long = long
|
|
|
getUserDistance({ lat: lat, lng: long }).then(res => {
|
|
|
- this.freightPrice = res.data.fee?parseFloat(res.data.fee):0;
|
|
|
- this.showDistance = res.data.showDistance;
|
|
|
+ const data = res.data || {}
|
|
|
+ this.freightPrice = data.fee?parseFloat(data.fee):0;
|
|
|
+ this.showDistance = data.showDistance || 0;
|
|
|
+ this.form.sendDistance = this.showDistance
|
|
|
});
|
|
|
},
|
|
|
- formSubmit(e) {
|
|
|
+ formSubmit() {
|
|
|
this.createOrderFn()
|
|
|
},
|
|
|
createOrderFn() {
|
|
|
let form = {}
|
|
|
if (this.form.sendType == 2) {
|
|
|
- form = this.$refs.appDelivery.form
|
|
|
+ const deliveryRef = this.$refs.appDelivery
|
|
|
+ if(!deliveryRef || !deliveryRef.form){
|
|
|
+ this.$msg("请完善配送信息")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ form = deliveryRef.form
|
|
|
let receiveUserName = form.receiveUserName;
|
|
|
if (this.$util.isEmpty(receiveUserName)) {
|
|
|
this.$msg("请填写收花人姓名");
|
|
|
- return false;
|
|
|
+ return;
|
|
|
}
|
|
|
let receiveMobile = form.receiveMobile;
|
|
|
if (this.$util.isEmpty(receiveMobile)) {
|
|
|
this.$msg("请填写收花人电话");
|
|
|
- return false;
|
|
|
+ return;
|
|
|
}
|
|
|
let address = form.address;
|
|
|
if (this.$util.isEmpty(address)) {
|
|
|
this.$msg("请填写地址");
|
|
|
- return false;
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
uni.showLoading({mask:true})
|
|
|
@@ -176,6 +175,8 @@ export default {
|
|
|
uni.hideLoading()
|
|
|
uni.removeStorageSync("buyGoodsDetil")
|
|
|
this.$util.pageTo({ url: "/pages/callback/pay", type: 2, query: { pageStatus: 1, ...res.data,hdId:hdId,account:account } })
|
|
|
+ }).catch(()=>{
|
|
|
+ uni.hideLoading()
|
|
|
})
|
|
|
}
|
|
|
}
|