|
@@ -50,36 +50,27 @@
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
|
<script>
|
|
<script>
|
|
|
-import { mapGetters } from "vuex";
|
|
|
|
|
-import AppTabs from "@/components/plugin/tabs";
|
|
|
|
|
import TuiListCell from "@/components/plugin/list-cell";
|
|
import TuiListCell from "@/components/plugin/list-cell";
|
|
|
import AppDeliveryModule from "@/components/app-delivery";
|
|
import AppDeliveryModule from "@/components/app-delivery";
|
|
|
-import AppTrademark from "@/components/module/app-trademark";
|
|
|
|
|
import AppListModule from "@/components/module/app-order-list2";
|
|
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 { getShopUser } from "@/utils/auth";
|
|
|
import { getOrderShop } from "@/utils/config";
|
|
import { getOrderShop } from "@/utils/config";
|
|
|
-import { createOrder,freight } from "@/api/order";
|
|
|
|
|
|
|
+import { createOrder,newFreight } from "@/api/order";
|
|
|
import { getUserDistance, getHasMap } from "@/api/express";
|
|
import { getUserDistance, getHasMap } from "@/api/express";
|
|
|
export default {
|
|
export default {
|
|
|
name: "buy",
|
|
name: "buy",
|
|
|
components: {
|
|
components: {
|
|
|
- AppTabs,
|
|
|
|
|
AppDeliveryModule,
|
|
AppDeliveryModule,
|
|
|
TuiListCell,
|
|
TuiListCell,
|
|
|
- AppListModule,
|
|
|
|
|
- AppCouponSel,
|
|
|
|
|
- AppTrademark,
|
|
|
|
|
- AlertModule
|
|
|
|
|
|
|
+ AppListModule
|
|
|
},
|
|
},
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
|
|
+ option: {},
|
|
|
goodsInfo: {},
|
|
goodsInfo: {},
|
|
|
- tabIndex: 0,
|
|
|
|
|
- showAlert: false,
|
|
|
|
|
form: {
|
|
form: {
|
|
|
sendDistance:"",
|
|
sendDistance:"",
|
|
|
|
|
+ sendCost: 0,
|
|
|
goodsId: "",
|
|
goodsId: "",
|
|
|
goodsStyleId: "",
|
|
goodsStyleId: "",
|
|
|
goodsNum: "",
|
|
goodsNum: "",
|
|
@@ -88,85 +79,146 @@ export default {
|
|
|
lat:'',
|
|
lat:'',
|
|
|
long:''
|
|
long:''
|
|
|
},
|
|
},
|
|
|
- discountArr: false,
|
|
|
|
|
freightPrice: 0,
|
|
freightPrice: 0,
|
|
|
- goodsNum: 1,
|
|
|
|
|
showDistance: 0,
|
|
showDistance: 0,
|
|
|
goodsTotalPrice: 0,
|
|
goodsTotalPrice: 0,
|
|
|
- memberDiscount: 1,
|
|
|
|
|
- couponDiscountAmount: 0,
|
|
|
|
|
hasMap: 0 // 是否具备定位功能 0不具备 1具备
|
|
hasMap: 0 // 是否具备定位功能 0不具备 1具备
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
|
|
+ onLoad(option) {
|
|
|
|
|
+ this.option = option || {};
|
|
|
|
|
+ this.init();
|
|
|
|
|
+ },
|
|
|
mounted() {},
|
|
mounted() {},
|
|
|
computed: {
|
|
computed: {
|
|
|
- ...mapGetters({ orderShop: "getOrderShop" }),
|
|
|
|
|
- ...mapGetters({ shopUser: "getShopUser" }),
|
|
|
|
|
mayPayAmount(){
|
|
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)
|
|
price = Number(this.freightPrice)+Number(price)
|
|
|
return parseFloat(price.toFixed(2))
|
|
return parseFloat(price.toFixed(2))
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
init() {
|
|
init() {
|
|
|
- let goodsInfo = uni.getStorageSync("buyGoodsDetil")
|
|
|
|
|
|
|
+ let goodsInfo = uni.getStorageSync("buyGoodsDetil") || {}
|
|
|
|
|
|
|
|
getOrderShop()
|
|
getOrderShop()
|
|
|
getShopUser();
|
|
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 => {
|
|
getHasMap().then(res => {
|
|
|
- this.hasMap = res.data.hasMap || 0
|
|
|
|
|
|
|
+ this.hasMap = (res.data && res.data.hasMap) ? res.data.hasMap : 0
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
changeSendType(num){
|
|
changeSendType(num){
|
|
|
this.form.sendType = num
|
|
this.form.sendType = num
|
|
|
if(num == 2){
|
|
if(num == 2){
|
|
|
- this.changeAddress()
|
|
|
|
|
|
|
+ this.$nextTick(()=>{
|
|
|
|
|
+ this.changeAddress()
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
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.lat = lat
|
|
|
this.form.long = long
|
|
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;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // getUserDistance({ lat: lat, lng: long }).then(res => {
|
|
|
|
|
+ // const data = res.data || {}
|
|
|
|
|
+ // this.freightPrice = data.fee?parseFloat(data.fee):0;
|
|
|
|
|
+ // this.showDistance = data.showDistance || 0;
|
|
|
|
|
+ // this.form.sendDistance = this.showDistance
|
|
|
|
|
+ // });
|
|
|
|
|
+ // 当需要的数据都具备时,调用 newFreight 计算运费
|
|
|
|
|
+ try {
|
|
|
|
|
+ const deliveryForm = (ref && ref.form) ? ref.form : {};
|
|
|
|
|
+ const goodsInfo = this.goodsInfo || {};
|
|
|
|
|
+ const cargoName = goodsInfo.goodsName || goodsInfo.name || '商品';
|
|
|
|
|
+ const packageNum = Number(goodsInfo.buyNum || this.form.goodsNum || 0);
|
|
|
|
|
+ // 商品总重量 = 单件重量(kg,缺省视为 1) * 数量
|
|
|
|
|
+ const unitWeight = goodsInfo.weight ? Number(goodsInfo.weight) : 1; // 单件重量,缺省视为 1 公斤
|
|
|
|
|
+ const totalWeight = Number((unitWeight * packageNum).toFixed(2));
|
|
|
|
|
+ const userName = deliveryForm.receiveUserName || '';
|
|
|
|
|
+ const userPhone = deliveryForm.receiveMobile || '';
|
|
|
|
|
+
|
|
|
|
|
+ // 仅当必要数据都具备时才调用 newFreight
|
|
|
|
|
+ const hasLocation = lat && long;
|
|
|
|
|
+ const hasValidNum = packageNum > 0;
|
|
|
|
|
+ const hasValidWeight = totalWeight > 0;
|
|
|
|
|
+ const hasContact = !!userName && !!userPhone;
|
|
|
|
|
+ if (!(hasLocation && hasValidNum && hasValidWeight && hasContact)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const params = {
|
|
|
|
|
+ cargo_name: cargoName,
|
|
|
|
|
+ price: this.goodsTotalPrice,
|
|
|
|
|
+ weight: totalWeight,
|
|
|
|
|
+ package_num: packageNum,
|
|
|
|
|
+ user_lng: long,
|
|
|
|
|
+ user_lat: lat,
|
|
|
|
|
+ user_name: userName,
|
|
|
|
|
+ user_phone: userPhone,
|
|
|
|
|
+ user_address: ref.region.province + ref.region.city + ref.region.dist + ref.region.address + ref.region.floor
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ newFreight(params).then(res => {
|
|
|
|
|
+ console.log('newFreight',res)
|
|
|
|
|
+ if (res && res.code == 1) {
|
|
|
|
|
+ const data = res.data || {};
|
|
|
|
|
+ this.freightPrice = data.est_fee ? parseFloat(Number(data.est_fee/100)) : 0;
|
|
|
|
|
+ this.showDistance = (data.distance/1000 || 0).toFixed(2);
|
|
|
|
|
+ this.form.sendDistance = (data.distance/1000 || 0).toFixed(2);
|
|
|
|
|
+ this.form.sendCost = this.freightPrice
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(() => {});
|
|
|
|
|
+ } catch (e) {}
|
|
|
},
|
|
},
|
|
|
- formSubmit(e) {
|
|
|
|
|
|
|
+ formSubmit() {
|
|
|
this.createOrderFn()
|
|
this.createOrderFn()
|
|
|
},
|
|
},
|
|
|
createOrderFn() {
|
|
createOrderFn() {
|
|
|
let form = {}
|
|
let form = {}
|
|
|
if (this.form.sendType == 2) {
|
|
if (this.form.sendType == 2) {
|
|
|
- form = this.$refs.appDelivery.form
|
|
|
|
|
|
|
+ if(this.form.hasMap == 0) {
|
|
|
|
|
+ this.$msg('由于地图定位服务停用,无法使用代叫跑腿')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if(this.form.freightPrice <= 0) {
|
|
|
|
|
+ this.$msg('选择代叫跑腿,必须获取运费')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ const deliveryRef = this.$refs.appDelivery
|
|
|
|
|
+ if(!deliveryRef || !deliveryRef.form){
|
|
|
|
|
+ this.$msg("请完善配送信息")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ form = deliveryRef.form
|
|
|
let receiveUserName = form.receiveUserName;
|
|
let receiveUserName = form.receiveUserName;
|
|
|
if (this.$util.isEmpty(receiveUserName)) {
|
|
if (this.$util.isEmpty(receiveUserName)) {
|
|
|
this.$msg("请填写收花人姓名");
|
|
this.$msg("请填写收花人姓名");
|
|
|
- return false;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
let receiveMobile = form.receiveMobile;
|
|
let receiveMobile = form.receiveMobile;
|
|
|
if (this.$util.isEmpty(receiveMobile)) {
|
|
if (this.$util.isEmpty(receiveMobile)) {
|
|
|
this.$msg("请填写收花人电话");
|
|
this.$msg("请填写收花人电话");
|
|
|
- return false;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
let address = form.address;
|
|
let address = form.address;
|
|
|
if (this.$util.isEmpty(address)) {
|
|
if (this.$util.isEmpty(address)) {
|
|
|
this.$msg("请填写地址");
|
|
this.$msg("请填写地址");
|
|
|
- return false;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
uni.showLoading({mask:true})
|
|
uni.showLoading({mask:true})
|
|
@@ -175,7 +227,13 @@ export default {
|
|
|
createOrder({...form, ...this.form,hdId:hdId}).then(res => {
|
|
createOrder({...form, ...this.form,hdId:hdId}).then(res => {
|
|
|
uni.hideLoading()
|
|
uni.hideLoading()
|
|
|
uni.removeStorageSync("buyGoodsDetil")
|
|
uni.removeStorageSync("buyGoodsDetil")
|
|
|
- this.$util.pageTo({ url: "/pages/callback/pay", type: 2, query: { pageStatus: 1, ...res.data,hdId:hdId,account:account } })
|
|
|
|
|
|
|
+ this.$util.pageTo({
|
|
|
|
|
+ url: "/pages/callback/pay",
|
|
|
|
|
+ type: 2,
|
|
|
|
|
+ query: { pageStatus: 1, ...res.data, hdId:hdId, account:account, freightPrice: this.freightPrice }
|
|
|
|
|
+ })
|
|
|
|
|
+ }).catch(()=>{
|
|
|
|
|
+ uni.hideLoading()
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|