ZN
7 天以前 dd630fede0cc46500fe898c75464e3e04ce82b0f
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
312
313
314
315
316
317
318
319
320
321
322
323
<template>
  <view class="after-sales-registration">
    <!-- 使用通用页面头部组件 -->
    <PageHeader title="售后登记" @back="goBack" />
 
    <!-- 统计卡片区域 -->
    <view class="stats-container">
      <view v-for="(item, index) in statsList" :key="index" class="stat-card">
        <view class="stat-icon" :style="{ backgroundColor: item.bgColor }">
          <up-icon :name="item.icon" :color="item.color" size="20"></up-icon>
        </view>
        <view class="stat-info">
          <text class="stat-number">{{ item.count }}</text>
          <text class="stat-label">{{ item.label }}</text>
        </view>
      </view>
    </view>
 
    <!-- 搜索和筛选区域 -->
    <view class="search-section">
      <view class="search-bar">
        <view class="search-input">
          <up-input class="search-text" placeholder="请输入工单编号搜索" v-model="searchForm.afterSalesServiceNo" @change="handleQuery" clearable />
        </view>
        <view class="filter-button" @click="handleQuery">
          <up-icon name="search" size="24" color="#999"></up-icon>
        </view>
      </view>
    </view>
 
    <!-- 售后单列表 -->
    <view class="ledger-list" v-if="tableData.length > 0">
      <view v-for="(item, index) in tableData" :key="index" class="ledger-item" @click="handleRowClick(item)">
        <view class="item-header">
          <view class="item-left">
            <view class="document-icon">
              <up-icon name="file-text" size="16" color="#ffffff"></up-icon>
            </view>
            <text class="item-id">{{ item.afterSalesServiceNo }}</text>
          </view>
          <view class="item-tag">
            <up-tag :text="getStatusLabel(item.status)" :type="getStatusType(item.status)" size="mini"></up-tag>
          </view>
        </view>
        <up-divider></up-divider>
        <view class="item-details">
          <view class="detail-row">
            <text class="detail-label">销售单号</text>
            <text class="detail-value">{{ item.salesContractNo }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">客户名称</text>
            <text class="detail-value">{{ item.customerName }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">反馈日期</text>
            <text class="detail-value">{{ item.feedbackDate }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">售后类型</text>
            <text class="detail-value">{{ getDictLabel(post_sale_waiting_list, item.serviceType) }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">紧急程度</text>
            <text class="detail-value">{{ getDictLabel(degree_of_urgency, item.urgency) }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">登记人</text>
            <text class="detail-value">{{ item.checkNickName }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">问题描述</text>
            <text class="detail-value">{{ item.disRes }}</text>
          </view>
        </view>
        <up-divider v-if="canEdit(item)"></up-divider>
        <view class="detail-buttons" v-if="canEdit(item)">
          <up-button size="small" type="primary" plain @click.stop="openForm('edit', item)">编辑</up-button>
          <up-button size="small" type="error" plain @click.stop="handleDelete(item)">删除</up-button>
        </view>
      </view>
    </view>
    <view v-else class="no-data">
      <text>暂无售后登记数据</text>
    </view>
 
    <!-- 浮动操作按钮 -->
    <view class="fab-button" @click="openForm('add')">
      <up-icon name="plus" size="24" color="#ffffff"></up-icon>
    </view>
  </view>
</template>
 
<script setup>
import { ref, reactive, computed, onMounted } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import { afterSalesServiceListPage, afterSalesServiceDelete, getSalesLedgerDetail } from '@/api/customerService/index';
import useUserStore from '@/store/modules/user';
import PageHeader from '@/components/PageHeader.vue';
import { useDict } from '@/utils/dict';
 
const userStore = useUserStore();
 
// 字典
const { post_sale_waiting_list, degree_of_urgency, work_order_status } = useDict(
  'post_sale_waiting_list',
  'degree_of_urgency',
  'work_order_status'
);
 
const statsList = ref([
  {
    icon: 'file-text',
    count: 0,
    label: '全部工单',
    color: '#4080ff',
    bgColor: '#eaf2ff'
  },
  {
    icon: 'file-text',
    count: 0,
    label: '已处理',
    color: '#ff9a2e',
    bgColor: '#fff5e6'
  },
  {
    icon: 'account',
    count: 0,
    label: '已完成',
    color: '#00b42a',
    bgColor: '#e6f7ed'
  },
]);
 
const searchForm = reactive({
  afterSalesServiceNo: '',
  status: '',
  urgency: '',
  serviceType: '',
  orderNo: '',
});
 
const tableData = ref([]);
const loading = ref(false);
const page = reactive({
  current: 1,
  size: 20,
  total: 0,
});
 
const goBack = () => {
  uni.navigateBack();
};
 
const handleQuery = () => {
  page.current = 1;
  getList();
};
 
const getList = () => {
  loading.value = true;
  uni.showLoading({ title: '加载中...' });
  
  getStats();
  
  afterSalesServiceListPage({ ...searchForm, ...page })
    .then((res) => {
      const records = res?.data?.records ?? res?.records ?? [];
      const total = res?.data?.total ?? res?.total ?? 0;
      tableData.value = Array.isArray(records) ? records : [];
      page.total = Number.isFinite(Number(total)) ? Number(total) : 0;
    })
    .finally(() => {
      loading.value = false;
      uni.hideLoading();
    });
};
 
const getStats = () => {
  getSalesLedgerDetail({}).then((res) => {
    if (res.code === 200) {
      const statsData = Array.isArray(res.data) ? res.data : [];
      statsList.value[0].count = getStatsCountByStatus(statsData, 3);
      statsList.value[1].count = getStatsCountByStatus(statsData, 2);
      statsList.value[2].count = getStatsCountByStatus(statsData, 1);
    }
  });
};
 
const getStatsCountByStatus = (list, status) => {
  if (!Array.isArray(list)) return 0;
  return list.find((item) => item?.status === status)?.count || 0;
};
 
const getStatusLabel = (status) => {
  if (status === 1) return '待处理';
  if (status === 2) return '已处理';
  return '未知';
};
 
const getStatusType = (status) => {
  if (status === 1) return 'error';
  if (status === 2) return 'success';
  return 'info';
};
 
const getDictLabel = (dict, value) => {
  if (!dict || !dict.value) return value;
  const item = dict.value.find(i => i.value == value);
  return item ? item.label : value;
};
 
const canEdit = (row) => {
  if (!row) return false;
  return row.status === 1 && String(row.checkUserId) === String(userStore.id);
}
 
const handleRowClick = (row) => {
  if (canEdit(row)) {
    openForm('edit', row)
    return
  }
  openForm('view', row)
}
 
const openForm = (type, row) => {
  uni.setStorageSync('afterSalesOperationType', type);
  if (row) {
    uni.setStorageSync('afterSalesEditData', JSON.stringify(row));
  } else {
    uni.removeStorageSync('afterSalesEditData');
  }
  uni.navigateTo({
    url: '/pages/customerService/feedbackRegistration/edit'
  });
};
 
const handleDelete = (row) => {
  if (row.checkUserId !== userStore.id) {
    uni.showToast({ title: '不可删除他人维护的数据', icon: 'none' });
    return;
  }
  
  uni.showModal({
    title: '提示',
    content: '选中的内容将被删除,是否确认删除?',
    success: (res) => {
      if (res.confirm) {
        afterSalesServiceDelete([row.id]).then(() => {
          uni.showToast({ title: '删除成功', icon: 'success' });
          getList();
        });
      }
    }
  });
};
 
onShow(() => {
  getList();
});
</script>
 
<style scoped lang="scss">
@import "@/styles/sales-common.scss";
 
.after-sales-registration {
  min-height: 100vh;
  background: #f8f9fa;
}
 
.stats-container {
  display: flex;
  gap: 10px;
  padding: 15px 20px;
  background: #ffffff;
}
 
.stat-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px;
  background-color: #f8f9fa;
  border-radius: 8px;
}
 
.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
}
 
.stat-info {
  display: flex;
  flex-direction: column;
}
 
.stat-number {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}
 
.stat-label {
  font-size: 10px;
  color: #909399;
}
 
.detail-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px 0;
}
 
.ledger-item {
  padding: 0 16px;
}
</style>