wlzboy
3 天以前 40a8157440e3b906da8f52e07d939d78c3f4c313
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span class="card-title">审核发票申请</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="goBack">返回</el-button>
      </div>
 
      <!-- 申请信息(只读) -->
      <el-form ref="viewForm" :model="invoice" label-width="120px" disabled>
        <el-divider content-position="left">申请信息</el-divider>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="服务单号">
              <el-input v-model="invoice.serviceCode" placeholder="暂无" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开票类型">
              <el-radio-group v-model="invoice.invoiceType">
                <el-radio :label="1">个人</el-radio>
                <el-radio :label="2">企业</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="发票抬头">
              <el-input v-model="invoice.invoiceName" />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="发票金额">
              <el-input v-model="invoice.invoiceMoney">
                <template slot="prepend">¥</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话">
              <el-input v-model="invoice.contactPhone" />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20" v-if="invoice.invoiceType === 2">
          <el-col :span="24">
            <el-form-item label="注册地址">
              <el-input v-model="invoice.companyAddress" />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20" v-if="invoice.invoiceType === 2">
          <el-col :span="12">
            <el-form-item label="开户银行">
              <el-input v-model="invoice.companyBank" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行账号">
              <el-input v-model="invoice.companyBankNo" />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="邮寄地址">
              <el-input v-model="invoice.mailAddress" />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input type="textarea" v-model="invoice.invoiceRemarks" :rows="3" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
 
      <!-- 审核信息 -->
      <el-form ref="auditForm" :model="auditForm" :rules="rules" label-width="120px">
        <el-divider content-position="left">审核信息</el-divider>
        
        <el-form-item label="审核结果" prop="status">
          <el-radio-group v-model="auditForm.status" @change="handleStatusChange">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
 
        <!-- 审核通过时上传发票 -->
        <el-form-item 
          v-if="auditForm.status === 1" 
          label="发票文件" 
          prop="invoiceUrl"
          :rules="[{ required: true, message: '请上传发票文件', trigger: 'change' }]"
        >
          <el-upload
            class="upload-demo"
            :action="uploadAction"
            :headers="uploadHeaders"
            :on-success="handleUploadSuccess"
            :on-error="handleUploadError"
            :before-upload="beforeUpload"
            :file-list="fileList"
            :limit="1"
            accept=".pdf,.jpg,.jpeg,.png"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">支持PDF、JPG、PNG格式,且不超过10MB</div>
          </el-upload>
          <div v-if="auditForm.invoiceUrl" style="margin-top: 10px;">
            <el-link type="primary" :href="auditForm.invoiceUrl" target="_blank">查看已上传发票</el-link>
          </div>
        </el-form-item>
 
        <el-form-item v-if="auditForm.status === 1" label="发票编号" prop="invoiceNo">
          <el-input v-model="auditForm.invoiceNo" placeholder="请输入发票编号" />
        </el-form-item>
 
        <!-- 驳回时必填驳回原因 -->
        <el-form-item 
          label="审核备注" 
          prop="auditRemarks"
          :rules="auditForm.status === 2 ? [{ required: true, message: '请输入驳回原因', trigger: 'blur' }] : []"
        >
          <el-input 
            type="textarea" 
            v-model="auditForm.auditRemarks" 
            :rows="4"
            :placeholder="auditForm.status === 2 ? '请输入驳回原因(必填)' : '请输入审核意见(可选)'" 
          />
        </el-form-item>
      </el-form>
 
      <!-- 操作按钮 -->
      <div class="action-bar">
        <el-button @click="goBack">取 消</el-button>
        <el-button type="primary" @click="submitAudit" :loading="submitting">提交审核</el-button>
      </div>
    </el-card>
  </div>
</template>
 
<script>
import { getInvoice, updateInvoice } from "@/api/system/invoice";
import { getToken } from "@/utils/auth";
import { Message } from 'element-ui';
 
export default {
  name: "InvoiceAudit",
  data() {
    return {
      // 发票信息
      invoice: {},
      // 审核表单
      auditForm: {
        invoiceId: null,
        status: 1,
        invoiceNo: null,
        invoiceUrl: null,
        auditRemarks: null
      },
      // 上传相关
      uploadAction: process.env.VUE_APP_BASE_API + "/common/upload",
      uploadHeaders: { Authorization: "Bearer " + getToken() },
      fileList: [],
      // 提交状态
      submitting: false,
      // 表单验证
      rules: {
        status: [{ required: true, message: "请选择审核结果", trigger: "change" }]
      }
    };
  },
  created() {
    const invoiceId = this.$route.query.invoiceId;
    if (invoiceId) {
      this.getDetail(invoiceId);
    } else {
      this.$modal.msgError("缺少发票ID参数");
      this.goBack();
    }
  },
  methods: {
    /** 获取发票详情 */
    getDetail(invoiceId) {
      getInvoice(invoiceId).then(response => {
        this.invoice = response.data;
        this.auditForm.invoiceId = response.data.invoiceId;
        
        // 如果已有发票文件,显示在文件列表中
        if (response.data.invoiceUrl) {
          this.auditForm.invoiceUrl = response.data.invoiceUrl;
          this.fileList = [{
            name: '已上传发票',
            url: response.data.invoiceUrl
          }];
        }
      }).catch(() => {
        this.$modal.msgError("获取发票详情失败");
        this.goBack();
      });
    },
 
    /** 状态变化处理 */
    handleStatusChange(value) {
      // 切换状态时清空审核备注
      this.auditForm.auditRemarks = '';
    },
 
    /** 文件上传前验证 */
    beforeUpload(file) {
      const isLt10M = file.size / 1024 / 1024 < 10;
      if (!isLt10M) {
        Message.error('上传文件大小不能超过 10MB!');
        return false;
      }
      const fileType = file.type;
      const isPDF = fileType === 'application/pdf';
      const isImage = fileType.startsWith('image/');
      if (!isPDF && !isImage) {
        Message.error('只能上传PDF或图片文件!');
        return false;
      }
      return true;
    },
 
    /** 文件上传成功 */
    handleUploadSuccess(response, file, fileList) {
      if (response.code === 200) {
        this.auditForm.invoiceUrl = response.url || response.fileName;
        this.fileList = fileList;
        Message.success('上传成功');
      } else {
        Message.error(response.msg || '上传失败');
      }
    },
 
    /** 文件上传失败 */
    handleUploadError(err, file, fileList) {
      Message.error('上传失败,请重试');
      console.error(err);
    },
 
    /** 提交审核 */
    submitAudit() {
      this.$refs["auditForm"].validate(valid => {
        if (valid) {
          // 审核通过时必须上传发票
          if (this.auditForm.status === 1 && !this.auditForm.invoiceUrl) {
            this.$modal.msgError('审核通过时必须上传发票文件');
            return;
          }
          // 驳回时必须填写驳回原因
          if (this.auditForm.status === 2 && !this.auditForm.auditRemarks) {
            this.$modal.msgError('驳回时必须填写驳回原因');
            return;
          }
 
          this.submitting = true;
          updateInvoice(this.auditForm).then(response => {
            this.$modal.msgSuccess("审核成功");
            this.goBack();
          }).catch(() => {
            this.submitting = false;
          });
        }
      });
    },
 
    /** 返回列表 */
    goBack() {
      this.$tab.closePage();
    }
  }
};
</script>
 
<style scoped lang="scss">
.card-title {
  font-size: 18px;
  font-weight: bold;
  color: #303133;
}
 
.action-bar {
  border-top: 1px solid #EBEEF5;
  padding-top: 20px;
  text-align: center;
}
 
::v-deep .el-form-item__label {
  font-weight: 500;
}
 
::v-deep .el-divider__text {
  font-size: 16px;
  font-weight: bold;
  color: #409EFF;
}
</style>