|
|
<template>
|
|
|
<Modal v-model="visible" :title="title" @on-ok="ok" @on-cancel="cancel">
|
|
|
<Modal v-model="visible" :title="title" :loading="inLoading">
|
|
|
<Form ref="modal" :model="formItem" :label-width="80" :rules="rules">
|
|
|
<FormItem label="订单编号">
|
|
|
<i-input v-model="formItem.orderCode" readonly></i-input>
|
|
|
<span>{{ formItem.orderCode }}</span>
|
|
|
</FormItem>
|
|
|
<FormItem label="发票类型">
|
|
|
<RadioGroup v-model="formItem.type">
|
|
|
<Radio :label="ELECTRONIC">电子发票</Radio>
|
|
|
<Radio :label="PAPER">纸质发票</Radio>
|
|
|
<Radio v-if="formItem.status !== UNOPEN" :label="CANCELLED">作废</Radio>
|
|
|
<Radio :label="CANCELLED">作废</Radio>
|
|
|
</RadioGroup>
|
|
|
</FormItem>
|
|
|
<template v-if="formItem.status !== CANCELLED">
|
|
|
<template v-if="formItem.type == ELECTRONIC">
|
|
|
<FormItem label="上传PDF" prop="pdfUrl">
|
|
|
<!-- TODO: 设置文件类型,文件大小,及提示信息 -->
|
|
|
<drag-file-upload
|
|
|
upload-icon-title="上传发票"
|
|
|
bucket="invoice"
|
|
|
:format="['pdf']"
|
|
|
:format-err-msg="formatPdfFileTypeMsg"
|
|
|
:max-size="5 * 1024"
|
|
|
:format-max-size-msg="formatMaxSizeMsg"
|
|
|
@success="uploadPDFSuccess"
|
|
|
@remove="uploadPDFRemove"
|
|
|
>
|
|
|
</drag-file-upload>
|
|
|
</FormItem>
|
|
|
</template>
|
|
|
<template v-else>
|
|
|
<template v-if="formItem.type !== CANCELLED">
|
|
|
<FormItem v-show="formItem.type === ELECTRONIC" label="上传PDF" prop="pdfUrl">
|
|
|
<PDFUpload v-model="formItem.pdfUrl" @input="onPDFUrlChang" />
|
|
|
</FormItem>
|
|
|
<FormItem v-show="formItem.type === PAPER" label="物流信息">
|
|
|
<RadioGroup v-model="formItem.logisticsSwitch">
|
|
|
<Radio :label="LOGISTICS_YES">需要物流</Radio>
|
|
|
<Radio :label="LOGISTICS_NO">不需要物流</Radio>
|
|
|
</RadioGroup>
|
|
|
<template v-if="formItem.logisticsSwitch === LOGISTICS_YES">
|
|
|
<FormItem v-model="formItem.logisticsId" prop="logisticsId">
|
|
|
<Select>
|
|
|
<Option v-for="(item, idx) in expressList" :key="idx" :value="item.id">
|
|
|
{item.companyName}
|
|
|
</Option>
|
|
|
</Select>
|
|
|
</FormItem>
|
|
|
<FormItem prop="expressNumber">
|
|
|
<i-input v-model="formItem.expressNumber" type="text" placeholder="物流单号"></i-input>
|
|
|
</FormItem>
|
|
|
</template>
|
|
|
</FormItem>
|
|
|
<template v-if="formItem.logisticsSwitch === LOGISTICS_YES && formItem.type === PAPER">
|
|
|
<FormItem prop="logisticsId" class="logistics-company">
|
|
|
<Select v-model="formItem.logisticsId">
|
|
|
<Option v-for="(item, idx) in expressList" :key="idx" :value="item.id">
|
|
|
{{ item.companyName }}
|
|
|
</Option>
|
|
|
</Select>
|
|
|
</FormItem>
|
|
|
<FormItem prop="expressNumber" class="express-number">
|
|
|
<i-input v-model="formItem.expressNumber" type="text" placeholder="物流单号"></i-input>
|
|
|
</FormItem>
|
|
|
</template>
|
|
|
</template>
|
|
|
</Form>
|
|
|
<div slot="footer" class="modal-footer">
|
|
|
<span v-if="formItem.status !== UNOPEN"><i>*</i>在第三方开票系统冲红或作废后更新保存发票信息</span>
|
|
|
<Button type="primary" long :loading="inLoading" @click="update">保存</Button>
|
|
|
<Button long @click="close">关闭</Button>
|
|
|
<Button type="primary" :loading="inLoading" @click="update">保存</Button>
|
|
|
<Button @click="close">关闭</Button>
|
|
|
</div>
|
|
|
</Modal>
|
|
|
</template>
|
...
|
...
|
@@ -61,14 +48,17 @@ import _ from 'lodash'; |
|
|
import { InvoiceStatusName2Id, InvoiceTypeName2Id, LogisticsTypeName2Id } from '../store/constant';
|
|
|
import InvoiceService from 'services/finance/invoice-service';
|
|
|
import TradeService from 'services/trade/trade-service';
|
|
|
// TODO: move to vuex
|
|
|
let ExpressCompanyList = [];
|
|
|
import PDFUpload from './pdf-upload';
|
|
|
|
|
|
export default {
|
|
|
name: 'UpdateInvoice',
|
|
|
components: {
|
|
|
PDFUpload,
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
visible: false,
|
|
|
inLoading: false,
|
|
|
title: '',
|
|
|
// constants
|
|
|
UNOPEN: InvoiceStatusName2Id.UNOPEN,
|
...
|
...
|
@@ -77,44 +67,49 @@ export default { |
|
|
LOGISTICS_NO: LogisticsTypeName2Id.NO,
|
|
|
LOGISTICS_YES: LogisticsTypeName2Id.YES,
|
|
|
// api result data
|
|
|
expressList: ExpressCompanyList,
|
|
|
expressList: [],
|
|
|
formItem: {},
|
|
|
|
|
|
// rules
|
|
|
rules: {
|
|
|
pdfUrl: {
|
|
|
trigger: 'blur',
|
|
|
validator(rule, value, data) {
|
|
|
if (data.type === InvoiceTypeName2Id.ELECTRONIC) {
|
|
|
trigger: 'change',
|
|
|
validator: (rule, value, callback) => {
|
|
|
if (this.formItem.type === InvoiceTypeName2Id.ELECTRONIC) {
|
|
|
if (!value) {
|
|
|
return new Error('请上传发票PDF文件');
|
|
|
return callback(new Error('请上传发票PDF文件'));
|
|
|
}
|
|
|
}
|
|
|
callback();
|
|
|
},
|
|
|
},
|
|
|
logisticsId: {
|
|
|
trigger: 'blur',
|
|
|
validator(rule, value, data) {
|
|
|
if (data.type === InvoiceTypeName2Id.PAPER) {
|
|
|
trigger: 'change',
|
|
|
validator: (rule, value, callback) => {
|
|
|
if (this.formItem.type === InvoiceTypeName2Id.PAPER) {
|
|
|
if (!value) {
|
|
|
return new Error('请选择物流公司');
|
|
|
return callback(new Error('请选择物流公司'));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
callback();
|
|
|
},
|
|
|
},
|
|
|
expressNumber: {
|
|
|
trigger: 'blur',
|
|
|
validator(rule, value, data) {
|
|
|
if (data.type === InvoiceTypeName2Id.PAPER) {
|
|
|
validator: (rule, value, callback) => {
|
|
|
if (this.formItem.type === InvoiceTypeName2Id.PAPER) {
|
|
|
if (!value) {
|
|
|
return new Error('请输入物流单号');
|
|
|
return callback(new Error('请输入物流单号'));
|
|
|
}
|
|
|
|
|
|
if (!/^[\w\d_-]{5,+}$/.test(value)) {
|
|
|
if (!/^[\w\d_-]{5,}$/.test(value)) {
|
|
|
// TODO: refs https://www.cnblogs.com/Jerseyblog/p/10077136.html
|
|
|
return new Error('请输入有效的物流单号'); // TODO: 描述下什么是有效的?
|
|
|
return callback(new Error('请输入有效的物流单号')); // TODO: 描述下什么是有效的?
|
|
|
}
|
|
|
}
|
|
|
|
|
|
callback();
|
|
|
},
|
|
|
},
|
|
|
},
|
...
|
...
|
@@ -124,8 +119,8 @@ export default { |
|
|
this.invoiceAPI = new InvoiceService();
|
|
|
this.tradeAPI = new TradeService();
|
|
|
if (this.expressList.length === 0) {
|
|
|
this.tradeAPI.allotExpressCompList().then(({ data }) => {
|
|
|
this.expressList = ExpressCompanyList = data;
|
|
|
this.tradeAPI.allotExpressCompList().then(data => {
|
|
|
this.expressList = data;
|
|
|
});
|
|
|
}
|
|
|
},
|
...
|
...
|
@@ -138,11 +133,17 @@ export default { |
|
|
}
|
|
|
},
|
|
|
show(invoice) {
|
|
|
this.$refs.modal.resetFields();
|
|
|
// this.$refs.modal.resetFields();
|
|
|
this.setTitle(invoice);
|
|
|
// initial data
|
|
|
this.invoiceData = invoice;
|
|
|
this.formItem = { ...invoice };
|
|
|
this.formItem = {
|
|
|
pdfUrl: null,
|
|
|
logisticsId: null,
|
|
|
expressNumber: null,
|
|
|
logisticsSwitch: this.LOGISTICS_YES,
|
|
|
...invoice,
|
|
|
};
|
|
|
this.visible = true;
|
|
|
},
|
|
|
/**
|
...
|
...
|
@@ -176,7 +177,7 @@ export default { |
|
|
*/
|
|
|
updateState(invoice) {
|
|
|
const { status: currentStatus } = this.invoiceData;
|
|
|
const isCancled = (invoice.status = InvoiceStatusName2Id.CANCELLED);
|
|
|
const isCancled = invoice.status === InvoiceStatusName2Id.CANCELLED;
|
|
|
|
|
|
if (isCancled) {
|
|
|
if (currentStatus === isCancled) {
|
...
|
...
|
@@ -225,44 +226,60 @@ export default { |
|
|
this.close(true);
|
|
|
return;
|
|
|
}
|
|
|
this.inLoading = true;
|
|
|
this.invoiceAPI
|
|
|
.update(params)
|
|
|
.then(() => {
|
|
|
this.inLoading = false;
|
|
|
this.$Message.success('更新成功');
|
|
|
this.$emit('updated', params);
|
|
|
this.close();
|
|
|
})
|
|
|
.catch(() => {
|
|
|
this.$methods.warn('更新失败');
|
|
|
this.inLoading = false;
|
|
|
this.$Message.warning('更新失败');
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
// TODO:
|
|
|
// update status
|
|
|
},
|
|
|
ok() {
|
|
|
debugger;
|
|
|
},
|
|
|
cancel() {
|
|
|
debugger;
|
|
|
},
|
|
|
close(force) {
|
|
|
if (!force) {
|
|
|
// dirty check
|
|
|
}
|
|
|
this.visible = false;
|
|
|
},
|
|
|
uploadPDFSuccess(attach, res) {
|
|
|
this.formItem.pdfUrl = res.url;
|
|
|
},
|
|
|
uploadPDFRemove() {
|
|
|
this.formItem.pdfUrl = '';
|
|
|
},
|
|
|
formatPdfFileTypeMsg(file) {
|
|
|
return `文件${file.name}格式不正确, 请上传pdf文件`;
|
|
|
},
|
|
|
formatMaxSizeMsg(file) {
|
|
|
return `文件${file.name}太大,不能超过5M`;
|
|
|
onPDFUrlChang() {
|
|
|
this.$refs.modal.validateField('pdfUrl');
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
.modal-footer {
|
|
|
& > span {
|
|
|
float: left;
|
|
|
line-height: 32px;
|
|
|
}
|
|
|
i {
|
|
|
color: red;
|
|
|
}
|
|
|
}
|
|
|
.file-upload {
|
|
|
display: inline-block;
|
|
|
}
|
|
|
|
|
|
.logistics-company {
|
|
|
display: inline-block;
|
|
|
min-width: 20em;
|
|
|
}
|
|
|
|
|
|
.express-number {
|
|
|
display: inline-block;
|
|
|
/deep/ .ivu-form-item-content {
|
|
|
margin-left: 20px !important;
|
|
|
}
|
|
|
}
|
|
|
</style> |
...
|
...
|
|