wlzboy
2026-02-05 57e98ac3f59e9ca12d3fdbc6f89c9c0b1f86be4d
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
<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-descriptions :column="2" border>
        <!-- 基本信息 -->
        <el-descriptions-item label="发票ID">{{ invoice.invoiceId }}</el-descriptions-item>
        <el-descriptions-item label="服务单号">{{ invoice.serviceCode || invoice.legacyServiceOrderId || '-' }}</el-descriptions-item>
        
        <el-descriptions-item label="开票类型">
          <el-tag :type="invoice.invoiceType === 2 ? 'success' : 'info'" size="small">
            {{ invoice.invoiceType === 2 ? '企业' : '个人' }}
          </el-tag>
        </el-descriptions-item>
        
        <el-descriptions-item label="申请状态">
          <el-tag :type="invoice.status === 1 ? 'success' : (invoice.status === 2 ? 'danger' : 'warning')" size="small">
            {{ statusFormat(invoice.status) }}
          </el-tag>
        </el-descriptions-item>
 
        <!-- 发票信息 -->
        <el-descriptions-item label="发票抬头" :span="2">{{ invoice.invoiceName }}</el-descriptions-item>
        <el-descriptions-item label="发票金额">
          <span class="text-price">¥{{ formatMoney(invoice.invoiceMoney) }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="发票编号">{{ invoice.invoiceNo || '-' }}</el-descriptions-item>
 
        <!-- 联系信息 -->
        <el-descriptions-item label="联系人">{{ invoice.contactName || '-' }}</el-descriptions-item>
        <el-descriptions-item label="联系电话">{{ invoice.contactPhone || '-' }}</el-descriptions-item>
        <el-descriptions-item label="联系邮箱" :span="2">{{ invoice.contactEmail || '-' }}</el-descriptions-item>
 
        <!-- 企业信息(仅企业类型显示) -->
        <template v-if="invoice.invoiceType === 2">
          <el-descriptions-item label="注册地址" :span="2">{{ invoice.companyAddress || '-' }}</el-descriptions-item>
          <el-descriptions-item label="开户银行">{{ invoice.companyBank || '-' }}</el-descriptions-item>
          <el-descriptions-item label="银行账号">{{ invoice.companyBankNo || '-' }}</el-descriptions-item>
        </template>
 
        <!-- 邮寄信息 -->
        <el-descriptions-item label="邮寄地址" :span="2">{{ invoice.mailAddress || '-' }}</el-descriptions-item>
        <el-descriptions-item label="邮编">{{ invoice.zipCode || '-' }}</el-descriptions-item>
        <el-descriptions-item label="备注" :span="2">{{ invoice.invoiceRemarks || '-' }}</el-descriptions-item>
 
        <!-- 时间信息 -->
        <el-descriptions-item label="申请时间">{{ parseTime(invoice.applyTime) }}</el-descriptions-item>
        <el-descriptions-item label="审核时间">{{ parseTime(invoice.auditTime) || '-' }}</el-descriptions-item>
        
        <!-- 审核信息 -->
        <el-descriptions-item label="审核备注" :span="2">
          <span :class="invoice.status === 2 ? 'text-danger' : ''">{{ invoice.auditRemarks || '-' }}</span>
        </el-descriptions-item>
 
        <!-- 同步状态 -->
        <el-descriptions-item label="同步状态">
          <el-tag 
            :type="invoice.syncStatus === 1 ? 'success' : (invoice.syncStatus === 2 ? 'danger' : 'info')" 
            size="small"
          >
            {{ syncStatusFormat(invoice.syncStatus) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="旧系统发票ID">
          <span v-if="invoice.legacyInvoiceId">{{ invoice.legacyInvoiceId }}</span>
          <span v-else class="text-gray">未同步</span>
        </el-descriptions-item>
 
        <!-- 发票文件 -->
        <el-descriptions-item label="发票文件" :span="2" v-if="invoice.invoiceUrl">
          <el-link type="primary" :href="getFullUrl(invoice.invoiceUrl)" target="_blank" icon="el-icon-view">
            查看发票文件
          </el-link>
          <el-link type="success" :href="getFullUrl(invoice.invoiceUrl)" :download="getFileName(invoice.invoiceUrl)" icon="el-icon-download" style="margin-left: 10px;">
            下载发票
          </el-link>
        </el-descriptions-item>
      </el-descriptions>
 
      <!-- 操作按钮 -->
      <div class="action-bar" style="margin-top: 20px; text-align: center;">
        <el-button @click="goBack">返回列表</el-button>
        <el-button 
          type="primary" 
          v-if="invoice.status === 0" 
          @click="handleAudit"
          v-hasPermi="['system:invoice:edit']"
        >
          审核
        </el-button>
        <el-button 
          type="success" 
          v-if="invoice.invoiceUrl" 
          @click="handleDownload"
          icon="el-icon-download"
        >
          下载发票
        </el-button>
        <!-- 同步按钮:只有已通过且未同步或同步失败时显示 -->
        <el-button 
          type="warning" 
          v-if="invoice.status === 1 && (!invoice.legacyInvoiceId || invoice.syncStatus === 2)" 
          @click="handleSync"
          :loading="syncing"
          icon="el-icon-refresh"
          v-hasPermi="['system:invoice:edit']"
        >
          {{ syncing ? '同步中...' : '同步到旧系统' }}
        </el-button>
      </div>
    </el-card>
  </div>
</template>
 
<script>
import { getInvoice, syncInvoiceToLegacy } from "@/api/system/invoice";
 
export default {
  name: "InvoiceDetail",
  data() {
    return {
      // 发票详情数据
      invoice: {
        invoiceId: null,
        serviceOrderId: null,
        legacyServiceOrderId: null,
        serviceCode: null,
        invoiceType: null,
        invoiceName: null,
        invoiceMoney: null,
        invoiceRemarks: null,
        companyAddress: null,
        companyBank: null,
        companyBankNo: null,
        zipCode: null,
        mailAddress: null,
        contactName: null,
        contactPhone: null,
        contactEmail: null,
        status: null,
        invoiceNo: null,
        invoiceUrl: null,
        applyTime: null,
        auditTime: null,
        auditRemarks: null,
        syncStatus: null,
        legacyInvoiceId: null
      },
      // 同步状态
      syncing: false
    };
  },
  created() {
    const invoiceId = this.$route.params.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;
      }).catch(() => {
        this.$modal.msgError("获取发票详情失败");
        this.goBack();
      });
    },
    
    /** 状态格式化 */
    statusFormat(status) {
      const map = { 0: "待审核", 1: "已通过", 2: "已驳回" };
      return map[status] || "未知";
    },
    
    /** 金额格式化 */
    formatMoney(money) {
      if (money === null || money === undefined) return '0.00';
      return Number(money).toFixed(2);
    },
    
    /** 同步状态格式化 */
    syncStatusFormat(status) {
      const map = { 0: "未同步", 1: "已同步", 2: "同步失败" };
      return map[status] || "未知";
    },
    
    /** 获取完整的文件URL */
    getFullUrl(url) {
      if (!url) return '';
      if (url.startsWith('http')) {
        return url;
      }
      return process.env.VUE_APP_BASE_API + url;
    },
    
    /** 获取文件名 */
    getFileName(url) {
      if (!url) return '发票文件';
      const parts = url.split('/');
      return parts[parts.length - 1] || '发票文件';
    },
    
    /** 返回列表 */
    goBack() {
      this.$tab.closePage();
    },
    
    /** 跳转到审核页面 */
    handleAudit() {
      this.$router.push({
        path: '/system/invoice/audit',
        query: { invoiceId: this.invoice.invoiceId }
      });
    },
    
    /** 下载发票 */
    handleDownload() {
      const url = this.getFullUrl(this.invoice.invoiceUrl);
      window.open(url);
    },
    
    /** 同步到旧系统 */
    handleSync() {
      this.$modal.confirm('确认将该发票申请同步到旧系统吗?').then(() => {
        this.syncing = true;
        syncInvoiceToLegacy(this.invoice.invoiceId).then(response => {
          this.$modal.msgSuccess('同步成功');
          // 重新加载详情
          this.getDetail(this.invoice.invoiceId);
        }).catch(() => {
          this.$modal.msgError('同步失败');
        }).finally(() => {
          this.syncing = false;
        });
      }).catch(() => {});
    }
  }
};
</script>
 
<style scoped lang="scss">
.card-title {
  font-size: 18px;
  font-weight: bold;
  color: #303133;
}
 
.text-price {
  color: #F56C6C;
  font-size: 16px;
  font-weight: bold;
}
 
.text-danger {
  color: #F56C6C;
}
 
.text-gray {
  color: #909399;
}
 
.action-bar {
  border-top: 1px solid #EBEEF5;
  padding-top: 20px;
}
 
::v-deep .el-descriptions-item__label {
  font-weight: bold;
  width: 120px;
}
</style>