From ec37ed0f518eb5f225e028e7ef60008e29bc4b01 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期三, 28 十月 2026 12:16:42 +0800
Subject: [PATCH] feat(企业台账抽查): 完成2026年9月台账核查、轨迹落库及结果报告

---
 traffic-audit-web/src/views/DataImport.vue |  128 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 118 insertions(+), 10 deletions(-)

diff --git a/traffic-audit-web/src/views/DataImport.vue b/traffic-audit-web/src/views/DataImport.vue
index 82abc05..8585aba 100644
--- a/traffic-audit-web/src/views/DataImport.vue
+++ b/traffic-audit-web/src/views/DataImport.vue
@@ -26,7 +26,8 @@
             <div class="import-main">          <el-card shadow="hover" class="import-card" style="margin-bottom:15px">
             <div class="card-head">鎶ヨ〃鏈�</div>
             <el-date-picker v-model="period" type="month" placeholder="閫夋嫨鏈堜唤" value-format="yyyy-MM"
-                            style="width:240px" @change="onPeriodChange"></el-date-picker>
+                            style="width:240px" :picker-options="periodPickerOptions" @change="onPeriodChange"></el-date-picker>
+            <div v-if="periodHint" class="tip" style="margin-top:6px">{{ periodHint }}</div>
           </el-card>
 
                     
@@ -81,6 +82,7 @@
               瀵煎叆缁撴灉锛坽{ period || '鍏ㄩ儴鎶ヨ〃鏈�' }}锛�
               <el-button type="text" icon="el-icon-refresh" style="float:right" @click="loadData">鍒锋柊</el-button>
             </div>
+            <div v-if="period" class="tip" style="margin-bottom:6px">浠呮樉绀哄綋鍓嶆姤琛ㄦ湡锛坽{ period }}锛夌殑瀵煎叆璁板綍锛涙妸涓婃柟鎶ヨ〃鏈熸竻绌哄彲鏌ョ湅鍏ㄩ儴鏈熸銆�</div>
             <div v-if="failBatches.length" class="tip" style="margin-bottom:6px">鍏� {{ failBatches.length }} 涓壒娆″瓨鍦ㄥけ璐ユ暟鎹紝澶辫触鏄庣粏鍏� {{ failRowsFlat.length }} 鏉★細</div>
             <el-table v-if="failBatches.length" :data="failRowsFlat" border size="small" v-loading="batchLoading" style="width:100%">
               <el-table-column label="瀵煎叆绫诲瀷" width="140">
@@ -98,6 +100,24 @@
               </el-table-column>
             </el-table>
             <div v-else class="empty-tip">鏆傛棤瀵煎叆澶辫触璁板綍</div>
+            <div v-if="warnRowsFlat.length" class="tip" style="margin:12px 0 6px">
+              鍏� {{ warnBatches.length }} 涓壒娆″惈鎻愰啋锛屽叡 {{ warnRowsFlat.length }} 鏉★紙涓嶉樆鏂鍏ワ紝渚涙牳瀵癸級锛�
+            </div>
+            <el-table v-if="warnRowsFlat.length" :data="warnRowsFlat" border size="small" style="width:100%">
+              <el-table-column label="瀵煎叆绫诲瀷" width="140">
+                <template slot-scope="s">{{ typeLabel(s.row.importType) }}</template>
+              </el-table-column>
+              <el-table-column prop="reportPeriod" label="鎶ヨ〃鏈�" width="90"></el-table-column>
+              <el-table-column label="鏂囦欢鍚�" min-width="200" show-overflow-tooltip>
+                <template slot-scope="s">{{ s.row.fileName }}</template>
+              </el-table-column>
+              <el-table-column label="浣嶇疆" width="230">
+                <template slot-scope="s"><span v-if="s.row.position">{{ s.row.position }}</span><span v-else>鈥�</span></template>
+              </el-table-column>
+              <el-table-column label="鎻愰啋鍐呭" min-width="300">
+                <template slot-scope="s">{{ s.row.reason }}</template>
+              </el-table-column>
+            </el-table>
           </el-card>
             </div>
                         <div class="import-side" :class="{ 'side-open': sideOpen }">
@@ -157,7 +177,8 @@
         </el-dialog>
         <!-- 瀵煎叆缁撴灉寮圭獥锛氬彲鎷栧姩銆佸唴瀹瑰尯婊氬姩銆佸簳閮ㄦ寜閽浐瀹氬彲瑙侊紙鍘� $alert 鍐呭闀挎椂搴曢儴鎸夐挳浼氳鎸ゅ嚭灞忓箷锛� -->
         <el-dialog :title="resultDialog.title" :visible.sync="resultDialog.visible" width="860px" top="5vh"
-                   append-to-body :close-on-click-modal="false" custom-class="import-result-dialog" v-dialog-drag>
+                   append-to-body :close-on-click-modal="true" :close-on-press-escape="true"
+                   custom-class="import-result-dialog" v-dialog-drag>
           <div v-if="resultDialog.level" class="ird-level" :class="'ird-' + resultDialog.level">
             {{ resultDialog.level === 'error' ? '瀵煎叆澶辫触' : (resultDialog.level === 'warning' ? '瀛樺湪闇�瑕佺‘璁ょ殑鍐呭' : '瀵煎叆鎴愬姛') }}
           </div>
@@ -175,6 +196,7 @@
 <script>
 import AppHeader from '@/components/AppHeader.vue'
 import api from '@/api'
+import { granularityOfMany, disabledDateFor, granularityHint, snapPeriod } from '@/utils/periodGranularity'
 const TYPE_LABELS = {
   h2032: 'H203-2鏈堟姤', transportAuth: '杩愭斂杞﹁締', trackMileage: '杞ㄨ抗閲岀▼', scaleSplit: '瑙勪笂瑙勪笅鎷嗗垎',
   freightTurnover: '璐ц繍閲忓懆杞噺', passengerMonthly: 'H203-1鏃呭鏈堟姤', passengerIndividual: '涓綋瀹㈣繍閲�/鍛ㄨ浆閲�',
@@ -283,15 +305,41 @@
     }
   },
   computed: {
+    selectedImportTypes() {
+      const out = []
+      if (this.importType) out.push(this.importType)
+      Object.keys(this.moduleSel || {}).forEach(k => { if (this.moduleSel[k]) out.push(this.moduleSel[k]) })
+      return out
+    },
+    periodGranularity() { return granularityOfMany(this.selectedImportTypes) },
+    periodPickerOptions() {
+      const d = disabledDateFor(this.periodGranularity)
+      return d ? { disabledDate: d } : {}
+    },
+    periodHint() { return granularityHint(this.periodGranularity) },
     // 骞存姤鏆備笉寮�鏀撅細闅愯棌鍏ュ彛锛堟暟鎹繚鐣欙紝鍚庣瀹炵幇鍚庡彲绉婚櫎 hidden锛�
     visibleGroups() { return this.groups.filter(g => !g.hidden) },
     failBatches() { return this.batches.filter(b => b.failRows > 0) },
+    // 鍚彁閱掔殑鎵规锛歟rrorDetail 閲屾湁銆屻�愭彁閱� N 澶勩�戙�嶆锛堟湭鐭ョ爜绛夛紝涓嶉樆鏂鍏ワ級
+    warnBatches() { return this.batches.filter(b => b.errorDetail && String(b.errorDetail).indexOf('銆愭彁閱� ') >= 0) },
     failRowsFlat() {
       const out = []
       for (const b of this.failBatches) {
-        const rows = this.parseFailDetails(b)
+        const rows = this.parseFailDetails({ errorDetail: this.failDetailText(b) })
         if (!rows.length) {
-          out.push({ importType: b.importType, reportPeriod: b.reportPeriod, fileName: b.fileName, position: '', reason: b.errorDetail || '璇ユ壒娆℃棤澶辫触鏄庣粏' })
+          out.push({ importType: b.importType, reportPeriod: b.reportPeriod, fileName: b.fileName, position: '', reason: this.failDetailText(b) || '璇ユ壒娆℃棤澶辫触鏄庣粏' })
+        } else {
+          rows.forEach(r => out.push({ importType: b.importType, reportPeriod: b.reportPeriod, fileName: b.fileName, position: r.position, reason: r.reason }))
+        }
+      }
+      return out
+    },
+    warnRowsFlat() {
+      const out = []
+      for (const b of this.warnBatches) {
+        const rows = this.parseFailDetails({ errorDetail: this.warnDetailText(b) })
+        if (!rows.length) {
+          out.push({ importType: b.importType, reportPeriod: b.reportPeriod, fileName: b.fileName, position: '', reason: this.warnDetailText(b) || '璇ユ壒娆″惈鎻愰啋' })
         } else {
           rows.forEach(r => out.push({ importType: b.importType, reportPeriod: b.reportPeriod, fileName: b.fileName, position: r.position, reason: r.reason }))
         }
@@ -347,6 +395,17 @@
         investmentSystem: '鎶曡祫/妯℃澘_鏌ヨ缁撴灉(鎶曡祫绯荤粺-瀹㈣繍+鐗╂祦 2026.7).xls'
       }
       return map[this.importType] || ''
+    }
+  },
+  watch: {
+    // 鏈熸绮掑害璺熺潃鏁版嵁绫诲瀷璧帮細閫夊埌鑳借�楀鎶ユ椂鑷姩鎶婃姤琛ㄦ湡瀵归綈鍒板搴︽湯鏈�
+    periodGranularity() {
+      const snapped = snapPeriod(this.period, this.periodGranularity)
+      if (snapped && snapped !== this.period) {
+        this.period = snapped
+        const hint = granularityHint(this.periodGranularity)
+        if (hint) this.$message.warning(hint + '锛堝凡鑷姩璋冩暣涓� ' + snapped + '锛�')
+      }
     }
   },
   methods: {
@@ -550,16 +609,42 @@
     showImportResult(row) {
       if (!row || !row.status) return
       const msg = (row.message || '').toString()
-      if (row.status === 'success') {
-        const text = (msg && msg.indexOf('瀵煎叆') !== -1) ? msg : '鏁版嵁瀵煎叆鎴愬姛'
-        this.$message({ message: text, type: 'success', duration: 5000 })
-      } else {
+      if (row.status !== 'success') {
         this.showResultDialog({
           title: '鏁版嵁瀵煎叆澶辫触',
-          html: (msg || '鏁版嵁瀵煎叆澶辫触锛岃瑙佷笅鏂瑰け璐ヨ褰�').replace(/\n/g, '<br>'),
+          html: this.escapeHtml(msg || '鏁版嵁瀵煎叆澶辫触锛岃瑙佷笅鏂瑰け璐ヨ褰�').replace(/\n/g, '<br>'),
           level: 'error'
         })
+        return
       }
+      const lines = msg.split('\n').map(s => s.trim()).filter(s => s)
+      const head = lines.length ? lines[0] : '鏁版嵁瀵煎叆鎴愬姛'
+      // 鍏ㄩ儴鎴愬姛锛氬彧缁欎竴鏉$煭鎻愮ず锛屼笉寮圭獥锛堣兘鑰楃瓑鎴愬姛瀵煎叆涓嶈鎵撴壈锛夛紱
+      // 闀挎枃鏈杩� el-message 浼氳鎾戞垚妯疮灞忓箷鐨勯暱鏉★紝鎵�浠ヨ繖閲屼篃鍙彇棣栬銆�
+      const failMatch = msg.match(/澶辫触\s*(\d+)\s*鏉�/)
+      const failCount = failMatch ? Number(failMatch[1]) : 0
+      if (failCount > 0) {
+        // 鏈夊け璐ヨ锛氫繚鐣欒鎯呭脊绐楋紙鍚鍙凤級锛屾弧瓒�"瀵煎叆澶辫触瑕佸湪椤甸潰鏄剧ず琛屽彿"
+        this.showResultDialog({
+          title: '瀵煎叆瀹屾垚锛堥儴鍒嗗け璐ワ紝瑙佹槑缁嗭級',
+          html: lines.map(l => this.escapeHtml(l)).join('<br>'),
+          level: 'warning'
+        })
+        return
+      }
+      const warnMatch = msg.match(/浠ヤ笅\s*(\d+)\s*澶勪负鎻愰啋/)
+      let text = head
+      if (warnMatch) text += '锛涘彟鏈� ' + warnMatch[1] + ' 澶勬彁閱�'
+      this.$message({ message: text, type: warnMatch ? 'warning' : 'success', duration: 4000 })
+    },
+    /** 寮圭獥鍐呭鐢� v-html 娓叉煋锛岀粺涓�杞箟锛岄伩鍏嶆秷鎭噷鐨� < > & 鐮村潖 DOM */
+    escapeHtml(v) {
+      return String(v === null || v === undefined ? '' : v)
+        .replace(/&/g, '&amp;')
+        .replace(/</g, '&lt;')
+        .replace(/>/g, '&gt;')
+        .replace(/"/g, '&quot;')
+        .replace(/'/g, '&#39;')
     },
     importOne(row) {
       if (!this.period) { this.$message.warning('璇峰厛閫夋嫨鎶ヨ〃鏈�'); return Promise.resolve() }
@@ -572,7 +657,17 @@
         fd.append('category', row.type === 'investment' ? '瀹㈣繍绔欏満' : '鐗╂祦鍥尯')
       }
       return api.post(this.endpoint(row.type), fd, { headers: { 'Content-Type': 'multipart/form-data' }, timeout: 600000 })
-        .then(res => { row.status = 'success'; row.message = res.data || '瀵煎叆鎴愬姛' })
+        .then(res => {
+          // axios 鎷︽埅鍣ㄥ彧鎷嗗嚭 response.data锛堜笟鍔″寘 Result锛夛紝蹇呴』鑷鍒� code锛�
+          // 鍚庣瑙f瀽/鏍¢獙寮傚父鏃惰繑鍥� code=500 涓斿師鍥犲湪 message 閲岋紝鏃у啓娉曚細鎶婂け璐ユ樉绀烘垚銆屽鍏ユ垚鍔熴�嶃��
+          if (res && res.code !== undefined && res.code !== 200) {
+            row.status = 'fail'
+            row.message = res.message || '瀵煎叆澶辫触'
+          } else {
+            row.status = 'success'
+            row.message = (res && res.data) || '瀵煎叆鎴愬姛'
+          }
+        })
         .catch(e => { row.status = 'fail'; row.message = (e.response && e.response.data && e.response.data.message) || '瀵煎叆澶辫触' })
         .finally(() => {})
     },
@@ -723,6 +818,19 @@
       document.body.removeChild(a)
       URL.revokeObjectURL(url)
     },
+  /** 澶辫触鏄庣粏鏂囨湰锛堝幓鎺夈�屻�愭彁閱� N 澶勩�戙�嶅強鍏跺悗鐨勬彁閱掓锛� */
+    failDetailText(b) {
+      const t = String((b && b.errorDetail) || '')
+      const i = t.indexOf('銆愭彁閱� ')
+      return (i >= 0 ? t.slice(0, i) : t).trim()
+    },
+    /** 鎻愰啋鏄庣粏鏂囨湰锛堛�屻�愭彁閱� N 澶勩�戙�嶄箣鍚庣殑閮ㄥ垎锛� */
+    warnDetailText(b) {
+      const t = String((b && b.errorDetail) || '')
+      const i = t.indexOf('銆愭彁閱� ')
+      if (i < 0) return ''
+      return t.slice(i).replace(/^銆愭彁閱抃s*\d+\s*澶勩�慭s*/, '').trim()
+    },
   parseFailDetails(row) {
     if (!row || !row.errorDetail) return []
     const lines = String(row.errorDetail).split(/\r?\n/)

--
Gitblit v1.9.1