You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
6.7 KiB

<template>
<view class="modify-page">
<!-- 顶部导航 -->
<u-navbar title="修改订单" :is-back="true" back-icon-color="#fff" :background="{'background':'#1479ff'}"
title-color="#fff" :border-bottom="false"></u-navbar>
<view class="b-border"></view>
<!-- 修改表单 -->
<view class="modify-form">
<!-- 金额修改 -->
<view class="form-card">
<view class="card-title">修改总金额</view>
<view class="amount-input">
<text class="symbol">¥</text>
<u-input placeholder="请输入修改后的总金额" v-model="form.price" type="number" :border="false" font-size="40">
</u-input>
<u-icon name="pan"></u-icon>
</view>
<view class="original-price">原价格 ¥{{orderInfo.price}}</view>
</view>
<!-- 修改原因 -->
<view class="form-card">
<view class="card-title">修改原因</view>
<u-input v-model="form.update_price_reason" placeholder="请输入修改原因" height="200" :border="false"
type="textarea"></u-input>
</view>
<!-- 底部按钮 -->
<view class="bottom-btns">
<u-button size="mini" shape="circle" type="primary" :custom-style="normalStyle"
@click="cancel">取消</u-button>
<u-button type="primary" @click="confirm" size="mini" shape="circle"
:custom-style="parStyle" :throttle-time="2000"></u-button>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
orderId: '',
orderInfo:{},
form:{
update_price_reason:'',
price:''
},
loginRole: '',
normalStyle: {
'background': '#969da7',
'color': '#fff',
'font-size': '28rpx',
'padding': '0 30rpx',
'margin-left': '15rpx'
},
parStyle: {
'background': 'linear-gradient(to right, #476de4, #7bb9f7)',
'color': '#fff',
'font-size': '28rpx',
'padding': '10rpx 30rpx',
'margin-left': '15rpx'
},
}
},
onLoad(options) {
this.loginRole = uni.getStorageSync('login_role') || '';
if (options.id) {
this.orderId = options.id;
this.getOrderInfo(options.id);
}
},
methods: {
/** 兼容 { data } 包装与拦截器返回 false */
normalizeDetailRes(res) {
if (res === false || res == null) return null
const err = res.errcode ?? res.errCode ?? res.errorCode
if (err !== undefined && err !== null && err !== 0) return null
if (typeof res.data !== 'undefined' && res.data !== null) {
return res.data
}
return res
},
isSaveResponseOk(res) {
if (res === false || res == null) return false
const err = res.errcode ?? res.errCode ?? res.errorCode
if (err !== undefined && err !== null && err !== 0) return false
return true
},
async getOrderInfo(id) {
let res = null
if (this.loginRole === 'nurse') {
res = await this.$u.api.orderDetail({ id })
} else if (this.loginRole === 'staff') {
res = await this.$u.api.accompanyOrderDetail({ id })
} else {
res = await this.$u.api.operatorOrderShow({ id })
}
const data = this.normalizeDetailRes(res)
this.orderInfo = data || {}
},
cancel() {
uni.navigateBack();
},
async confirm() {
if (!this.form.price) {
uni.showToast({
title: '请输入修改金额',
icon: 'none'
});
return;
}
if(parseFloat(this.form.price)<parseFloat(this.orderInfo.price)){
uni.showToast({
title: '',
icon: 'none'
});
return;
}
if (!this.form.update_price_reason) {
uni.showToast({
title: '',
icon: 'none'
});
return;
}
//
let that = this
if (this.loginRole === 'nurse') {
try {
const res = await that.$u.api.saveOrder({
id: that.orderId,
price: that.form.price,
update_price_reason: that.form.update_price_reason,
status: 3
})
if (!that.isSaveResponseOk(res)) {
uni.showToast({ title: '', icon: 'none' })
return
}
that.base.toast("", 1500, function() {
setTimeout(function() {
uni.switchTab({ url: '/pages/index/index' })
}, 1500)
})
} catch (e) {
uni.showToast({ title: '', icon: 'none' })
}
} else if (this.loginRole === 'staff') {
try {
const res = await that.$u.api.staffOrderSave({
id: that.orderId,
price: that.form.price,
update_price_reason: that.form.update_price_reason,
status: 3
})
if (!that.isSaveResponseOk(res)) {
uni.showToast({ title: '', icon: 'none' })
return
}
that.base.toast("", 1500, function() {
setTimeout(function() {
uni.switchTab({ url: '/pages/index/staffIndex' })
}, 1500)
})
} catch (e) {
uni.showToast({ title: '', icon: 'none' })
}
} else {
try {
const res = await that.$u.api.operatorOrderSave({
id: that.orderId,
price: that.form.price,
update_price_reason: that.form.update_price_reason,
status: 3
})
if (!that.isSaveResponseOk(res)) {
uni.showToast({ title: '', icon: 'none' })
return
}
that.base.toast("", 1500, function() {
setTimeout(function() {
uni.switchTab({ url: '/pages/index/operatorIndex' })
}, 1500)
})
} catch (e) {
uni.showToast({ title: '', icon: 'none' })
}
}
}
}
}
</script>
<style lang="scss" scoped>
.modify-page {
min-height: 100vh;
background: #f5f5f5;
::v-deep .u-navbar-fixed{
background-color: #1479ff!important;
}
.b-border {
width: 100%;
height: 30rpx;
border-radius: 0 0 120rpx 120rpx;
background-color: #1479ff;
}
.form-card {
background: #fff;
border-radius: 20rpx;
margin: 30rpx;
box-shadow: 0 4rpx 16rpx #e6eaf1;
padding: 30rpx;
.card-title {
font-size: 28rpx;
color: #333;
margin-bottom: 30rpx;
}
.amount-input {
display: flex;
align-items: center;
justify-content: center;
.symbol {
font-size: 40rpx;
color: #333;
margin-right: 10rpx;
}
// .u-input {
// flex: 1;
// }
}
.original-price {
font-size: 24rpx;
color: #999;
margin-top: 20rpx;
text-align: center;
}
}
.bottom-btns {
// position: fixed;
// left: 0;
// right: 0;
// bottom: 0;
padding: 20rpx;
// background: #fff;
display: flex;
justify-content: flex-end;
.u-button {
width: 45%;
}
}
}
</style>