diff --git a/src/core/models/service.js b/src/core/models/service.js index aedf62b..c29951e 100644 --- a/src/core/models/service.js +++ b/src/core/models/service.js @@ -156,5 +156,76 @@ export default { return reject(response.msg); }).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 => { }); + }); } } diff --git a/src/pages/service/other/distribution.vue b/src/pages/service/other/distribution.vue index 509add3..752b311 100644 --- a/src/pages/service/other/distribution.vue +++ b/src/pages/service/other/distribution.vue @@ -84,7 +84,7 @@ ¥ {{ utils.formatNumber(total) }} - +
立即支付
@@ -109,8 +109,8 @@ export default { name: "非营运", }, ], - unitPrice: 3, - minDistance: 5, + unitPrice: 0, + minDistance: 0, carTypeId: 0, carTypeText: "", pickupAddressId: 0, @@ -128,17 +128,30 @@ export default { }, onLoad() { 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() {}, onReady() {}, onReachBottom() {}, onPullDownRefresh() {}, methods: { + /** + * 选择车型 + */ selectCarType(e) { let { id, name } = this.carTypeList[e.detail.value]; this.carTypeId = id; this.carTypeText = name; }, + /** + * 选择取货地址 + */ selectPickupAddress() { const that = this; this.$utils.toPage("/pages/address/address?openType=choose&id=" + that.pickupAddressId, { @@ -150,6 +163,9 @@ export default { }, }); }, + /** + * 选择卸货地址 + */ selectUnloadAddress() { const that = this; this.$utils.toPage("/pages/address/address?openType=choose&id=" + that.unloadAddressId, { @@ -161,9 +177,15 @@ export default { }, }); }, + /** + * 选择日期 + */ bindDateChange(e) { this.datetime = e.detail.value; }, + /** + * 计算价格 + */ changeDistance(num) { num = parseFloat(num); if (num < this.minDistance) { @@ -171,6 +193,26 @@ export default { } 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); + }); + }, }, };