import { getTaskservelist } from "@/api/AiCentre/SingleTask"; import { getSfStatisticsJoyInfo } from "@/api/system/user"; // 随访统计页复用的满意度分析数据(与满意度统计页默认口径一致:离院、病区、服务类型 6) export default { data() { return { satisfactionRows: [], satisfactionRowsLoading: false, satisfactionTopics: [], satisfactionTopicsLoading: false, satisfactionMeta: { dimension: "ward", scope: "leave", dateRange: [], total: 0, }, satisfactionLoaded: false, }; }, computed: { satisfactionDetailMeta() { return { ...this.satisfactionMeta, groupLabel: "全部", }; }, }, created() { this.loadSatisfactionAnalysis(); }, methods: { loadSatisfactionAnalysis(force = false) { if (this.satisfactionLoaded && !force) return; this.satisfactionLoaded = true; this.fetchSatisfactionRows(); this.fetchSatisfactionTopics(); }, analysisScope() { const depts = (this.$store.getters.belongDepts || []) .map((dept) => dept.deptCode) .filter(Boolean); const wards = (this.$store.getters.belongWards || []) .map((ward) => ward.districtCode) .filter(Boolean); return { depts, wards }; }, fetchSatisfactionRows() { const { depts, wards } = this.analysisScope(); if (!depts.length && !wards.length) { this.satisfactionRows = []; this.satisfactionMeta = { ...this.satisfactionMeta, total: 0, }; return; } this.satisfactionRowsLoading = true; const payload = { pageNum: null, pageSize: null, sendstate: null, sendstateView: 2, sort: 2, serviceType: 6, searchscope: 3, visitCount: 1, scopetype: [], deptOrDistrict: depts.length && wards.length ? 2 : 1, leaveldeptcodes: depts, leavehospitaldistrictcodes: wards, }; getTaskservelist(payload) .then((response) => { const rows = this.pickSatisfactionRows(response); this.satisfactionRows = rows; this.satisfactionMeta = { dimension: "ward", scope: "leave", dateRange: [], total: rows.length, }; }) .catch((error) => { console.error("随访统计页获取满意度患者明细失败:", error); this.satisfactionRows = []; }) .finally(() => { this.satisfactionRowsLoading = false; }); }, fetchSatisfactionTopics() { const { wards } = this.analysisScope(); if (!wards.length) { this.satisfactionTopics = []; return; } this.satisfactionTopicsLoading = true; const payload = { configKey: "joyCount", statisticaltype: 1, serviceType: [6], pageNum: 1, pageSize: 999, leavehospitaldistrictcodes: wards, }; getSfStatisticsJoyInfo(payload) .then((response) => { this.satisfactionTopics = response.data || []; }) .catch((error) => { console.error("随访统计页获取满意度问题详情失败:", error); this.satisfactionTopics = []; }) .finally(() => { this.satisfactionTopicsLoading = false; }); }, pickSatisfactionRows(response) { if (!response) return []; const rowsWrap = response.rows || (response.data && response.data.rows); let list = []; if (Array.isArray(rowsWrap) && rowsWrap[0]) { list = rowsWrap[0].serviceSubtaskList || (rowsWrap[0].sendname ? rowsWrap : []); } else if (Array.isArray(response.data)) { list = response.data; } return (list || []) .filter(Boolean) .map((row) => this.normalizeSatisfactionRow(row)); }, normalizeSatisfactionRow(row) { const item = { ...row }; if (item.endtime) { item.endDay = this.daysBetween(item.endtime); } return item; }, }, };