完成货运订单的提交

This commit is contained in:
TOP糯米 2023-03-12 01:47:38 +08:00
parent f3b0870c94
commit dec1fbbb39
2 changed files with 116 additions and 3 deletions

View File

@ -156,5 +156,76 @@ export default {
return reject(response.msg); return reject(response.msg);
}).catch(e => { }); }).catch(e => { });
}); });
},
/**
* 获取货运配置
*/
distributionConfig() {
return new Promise((resolve, reject) => {
prototype.$request({
api: "service.distribution.config",
}).then(response => {
if (response.code == 1) {
return resolve({
unitPrice: response.data.money,
minDistance: response.data.min,
});
}
return reject(response.msg);
}).catch(e => { });
});
},
distributionCar() {
return new Promise((resolve, reject) => {
prototype.$request({
api: "service.distribution.carType",
}).then(response => {
if (response.code == 1) {
let list = [];
response.data.forEach(item => {
list.push({
id: item.id,
name: item.title
});
});
return resolve(list);
}
return reject(response.msg);
}).catch(e => { });
});
},
/**
* 创建货运订单
*/
createDistributionOrder(data) {
return new Promise((resolve, reject) => {
prototype.$request({
api: "service.distribution.submit",
data: data,
}).then(response => {
if (response.code == 1) {
return resolve(response.data);
}
return reject(response.msg);
}).catch(e => { });
});
},
/**
* 支付货运订单
*/
payDistributionOrder(id) {
return new Promise((resolve, reject) => {
prototype.$request({
api: "service.distribution.pay",
data: {
id: id,
}
}).then(response => {
if (response.code == 1) {
return resolve(response.data);
}
return reject(response.msg);
}).catch(e => { });
});
} }
} }

View File

@ -84,7 +84,7 @@
</view> </view>
<view class="common-bottom-components" :style="{ bottom: pageConfig.safeAreaInsets.bottom + 'px' }"> <view class="common-bottom-components" :style="{ bottom: pageConfig.safeAreaInsets.bottom + 'px' }">
<text class="price">¥ {{ utils.formatNumber(total) }}</text> <text class="price">¥ {{ utils.formatNumber(total) }}</text>
<view class="btn" @click="pay"> <view class="btn" @click="submit">
<div class="text">立即支付</div> <div class="text">立即支付</div>
</view> </view>
</view> </view>
@ -109,8 +109,8 @@ export default {
name: "非营运", name: "非营运",
}, },
], ],
unitPrice: 3, unitPrice: 0,
minDistance: 5, minDistance: 0,
carTypeId: 0, carTypeId: 0,
carTypeText: "", carTypeText: "",
pickupAddressId: 0, pickupAddressId: 0,
@ -128,17 +128,30 @@ export default {
}, },
onLoad() { onLoad() {
this.pageConfig = getApp().globalData.pageConfig; this.pageConfig = getApp().globalData.pageConfig;
this.$models.service.distributionConfig().then((config) => {
this.unitPrice = config.unitPrice;
this.minDistance = config.minDistance;
});
this.$models.service.distributionCar().then((list) => {
this.carTypeList = list;
});
}, },
onShow() {}, onShow() {},
onReady() {}, onReady() {},
onReachBottom() {}, onReachBottom() {},
onPullDownRefresh() {}, onPullDownRefresh() {},
methods: { methods: {
/**
* 选择车型
*/
selectCarType(e) { selectCarType(e) {
let { id, name } = this.carTypeList[e.detail.value]; let { id, name } = this.carTypeList[e.detail.value];
this.carTypeId = id; this.carTypeId = id;
this.carTypeText = name; this.carTypeText = name;
}, },
/**
* 选择取货地址
*/
selectPickupAddress() { selectPickupAddress() {
const that = this; const that = this;
this.$utils.toPage("/pages/address/address?openType=choose&id=" + that.pickupAddressId, { this.$utils.toPage("/pages/address/address?openType=choose&id=" + that.pickupAddressId, {
@ -150,6 +163,9 @@ export default {
}, },
}); });
}, },
/**
* 选择卸货地址
*/
selectUnloadAddress() { selectUnloadAddress() {
const that = this; const that = this;
this.$utils.toPage("/pages/address/address?openType=choose&id=" + that.unloadAddressId, { this.$utils.toPage("/pages/address/address?openType=choose&id=" + that.unloadAddressId, {
@ -161,9 +177,15 @@ export default {
}, },
}); });
}, },
/**
* 选择日期
*/
bindDateChange(e) { bindDateChange(e) {
this.datetime = e.detail.value; this.datetime = e.detail.value;
}, },
/**
* 计算价格
*/
changeDistance(num) { changeDistance(num) {
num = parseFloat(num); num = parseFloat(num);
if (num < this.minDistance) { if (num < this.minDistance) {
@ -171,6 +193,26 @@ export default {
} }
this.total = num * this.unitPrice; this.total = num * this.unitPrice;
}, },
/**
* 提交订单
*/
submit() {
this.$models.service
.createDistributionOrder({
car: this.carTypeId,
address: this.pickupAddressId,
addressb: this.unloadAddressId,
starttime: this.datetime,
sendtime: 0,
distance: this.distance,
})
.then((data) => {
this.$models.service.payDistributionOrder(data.id);
})
.catch((e) => {
this.$utils.toast(e);
});
},
}, },
}; };
</script> </script>