feat: support indefinite borrow period for long-term asset allocation
This commit is contained in:
@ -97,10 +97,17 @@
|
|||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
size="large"
|
size="large"
|
||||||
value-format="YYYY-MM-DD"
|
value-format="YYYY-MM-DD"
|
||||||
|
:disabled="isIndefinite"
|
||||||
:disabled-date="disabledDate"
|
:disabled-date="disabledDate"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :span="24">
|
||||||
|
<el-checkbox v-model="isIndefinite" @change="handleIndefiniteChange">
|
||||||
|
无限期/长期借用(不设归还期限)
|
||||||
|
</el-checkbox>
|
||||||
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-form-item label="备注说明" prop="remark">
|
<el-form-item label="备注说明" prop="remark">
|
||||||
@ -192,7 +199,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, nextTick, onUnmounted } from 'vue'
|
import { ref, reactive, nextTick, onUnmounted, computed } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { Scissor, EditPen, Delete, CameraFilled, Close, Refresh, Select } from '@element-plus/icons-vue'
|
import { Scissor, EditPen, Delete, CameraFilled, Close, Refresh, Select } from '@element-plus/icons-vue'
|
||||||
import QrScanner from '@/components/QrScanner/index.vue'
|
import QrScanner from '@/components/QrScanner/index.vue'
|
||||||
@ -246,13 +253,21 @@ const form = reactive({
|
|||||||
remark: ''
|
remark: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const rules = {
|
const rules = computed(() => ({
|
||||||
borrower_name: [
|
borrower_name: [
|
||||||
{ required: true, message: '请输入借用人姓名', trigger: 'blur' }
|
{ required: true, message: '请输入借用人姓名', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
expected_return_time: [
|
expected_return_time: [
|
||||||
{ required: true, message: '请选择预计归还日期', trigger: 'change' }
|
{ required: !isIndefinite.value, message: '请选择预计归还日期', trigger: 'change' }
|
||||||
]
|
]
|
||||||
|
}))
|
||||||
|
|
||||||
|
const isIndefinite = ref(false)
|
||||||
|
|
||||||
|
const handleIndefiniteChange = (val: boolean) => {
|
||||||
|
if (val) {
|
||||||
|
form.expected_return_time = ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const disabledDate = (time: Date) => {
|
const disabledDate = (time: Date) => {
|
||||||
@ -352,6 +367,7 @@ const clearAll = () => {
|
|||||||
signatureFile.value = null
|
signatureFile.value = null
|
||||||
signaturePreviewUrl.value = ''
|
signaturePreviewUrl.value = ''
|
||||||
barcodeInput.value = ''
|
barcodeInput.value = ''
|
||||||
|
isIndefinite.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,7 +378,8 @@ const submitForm = async () => {
|
|||||||
|
|
||||||
await formRef.value.validate(async (valid: boolean) => {
|
await formRef.value.validate(async (valid: boolean) => {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
ElMessage.error('请填写完整的必填项(姓名、归还日期)')
|
const requiredMsg = isIndefinite.value ? '请填写完整的必填项(姓名)' : '请填写完整的必填项(姓名、归还日期)'
|
||||||
|
ElMessage.error(requiredMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,12 +395,18 @@ const submitForm = async () => {
|
|||||||
const uploadRes = await uploadFile(signatureFile.value)
|
const uploadRes = await uploadFile(signatureFile.value)
|
||||||
const signatureUrl = uploadRes.data.url
|
const signatureUrl = uploadRes.data.url
|
||||||
|
|
||||||
|
// 处理无限期借用:如果选择了无限期,将预计归还时间置为空
|
||||||
|
const submitData = {
|
||||||
|
...form,
|
||||||
|
expected_return_time: isIndefinite.value ? null : form.expected_return_time
|
||||||
|
}
|
||||||
|
|
||||||
await request({
|
await request({
|
||||||
url: '/v1/transactions/borrow',
|
url: '/v1/transactions/borrow',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {
|
data: {
|
||||||
items: cartItems.value,
|
items: cartItems.value,
|
||||||
...form,
|
...submitData,
|
||||||
signature_path: signatureUrl
|
signature_path: signatureUrl
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -396,6 +419,7 @@ const submitForm = async () => {
|
|||||||
signatureFile.value = null
|
signatureFile.value = null
|
||||||
signaturePreviewUrl.value = ''
|
signaturePreviewUrl.value = ''
|
||||||
showCamera.value = false
|
showCamera.value = false
|
||||||
|
isIndefinite.value = false
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|||||||
@ -46,6 +46,9 @@
|
|||||||
<el-tag type="success" size="small">实际</el-tag>
|
<el-tag type="success" size="small">实际</el-tag>
|
||||||
{{ row.return_time || '-' }}
|
{{ row.return_time || '-' }}
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else-if="!row.expected_return_time">
|
||||||
|
<el-tag type="primary" size="small">无限期</el-tag>
|
||||||
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<el-tag type="info" size="small">预计</el-tag>
|
<el-tag type="info" size="small">预计</el-tag>
|
||||||
{{ formatExpectedTime(row.expected_return_time).text }}
|
{{ formatExpectedTime(row.expected_return_time).text }}
|
||||||
@ -163,7 +166,7 @@ const handlePage = (val: number) => {
|
|||||||
|
|
||||||
// ★ 新增:格式化预计归还时间及倒计时逻辑
|
// ★ 新增:格式化预计归还时间及倒计时逻辑
|
||||||
const formatExpectedTime = (timeStr: string) => {
|
const formatExpectedTime = (timeStr: string) => {
|
||||||
if (!timeStr) return { text: '-', diffText: '', cssClass: '' }
|
if (!timeStr) return { text: '无限期', diffText: '', cssClass: '' }
|
||||||
|
|
||||||
// 后端返回的可能是 YYYY-MM-DD HH:mm:ss,我们只取日期部分比较
|
// 后端返回的可能是 YYYY-MM-DD HH:mm:ss,我们只取日期部分比较
|
||||||
const expected = dayjs(timeStr).startOf('day')
|
const expected = dayjs(timeStr).startOf('day')
|
||||||
|
|||||||
Reference in New Issue
Block a user