|
|
@@ -1,5 +1,6 @@
|
|
|
const {
|
|
|
TABS, REPORT_CATEGORIES, authContext, listTickets, listConversations, listReplies, submitTicket,
|
|
|
+ pickerChoices, selectedPickerIndex, submitErrorMessage,
|
|
|
} = require('../../../utils/service-desk');
|
|
|
const { restrictionMessage, restrictionMessageForUser } = require('../../../utils/login-restrictions');
|
|
|
|
|
|
@@ -7,11 +8,12 @@ const emptyForm = () => ({ name: '', organization: '', phone: '', content: '' })
|
|
|
|
|
|
Page({
|
|
|
data: {
|
|
|
- tabs: TABS, categories: REPORT_CATEGORIES, active: 'cooperation',
|
|
|
+ tabs: TABS, categories: REPORT_CATEGORIES,
|
|
|
+ categoryChoices: pickerChoices(REPORT_CATEGORIES, '选择举报类型'), active: 'cooperation',
|
|
|
signedIn: false, signingIn: false, loading: false, loadFailed: false,
|
|
|
form: emptyForm(), records: [], submitting: false, notice: '',
|
|
|
- conversations: [], conversationsLoading: false, conversationsFailed: false, sessionIndex: -1,
|
|
|
- replies: [], repliesLoading: false, repliesFailed: false, replyIndex: -1, categoryIndex: -1,
|
|
|
+ conversations: [], conversationChoices: [], conversationsLoading: false, conversationsFailed: false, sessionIndex: -1,
|
|
|
+ replies: [], replyPickerChoices: [], repliesLoading: false, repliesFailed: false, replyIndex: -1, categoryIndex: -1,
|
|
|
includePrevious: false,
|
|
|
},
|
|
|
|
|
|
@@ -21,7 +23,7 @@ Page({
|
|
|
if (this.owner !== owner) {
|
|
|
this.owner = owner;
|
|
|
this.setData({ signedIn: !!scope, records: [], notice: '', form: emptyForm(),
|
|
|
- conversations: [], replies: [], sessionIndex: -1, replyIndex: -1,
|
|
|
+ conversations: [], conversationChoices: [], replies: [], replyPickerChoices: [], sessionIndex: -1, replyIndex: -1,
|
|
|
categoryIndex: -1, includePrevious: false, conversationsLoading: false, repliesLoading: false,
|
|
|
conversationsFailed: false, repliesFailed: false, loading: false, loadFailed: false });
|
|
|
}
|
|
|
@@ -62,7 +64,7 @@ Page({
|
|
|
const active = event.currentTarget.dataset.key;
|
|
|
if (this.data.submitting || active === this.data.active || !TABS.some(item => item.key === active)) return;
|
|
|
this.setData({ active, records: [], notice: '', loadFailed: false, form: emptyForm(),
|
|
|
- sessionIndex: -1, replies: [], replyIndex: -1, categoryIndex: -1, includePrevious: false, repliesLoading: false, repliesFailed: false });
|
|
|
+ sessionIndex: -1, replies: [], replyPickerChoices: [], replyIndex: -1, categoryIndex: -1, includePrevious: false, repliesLoading: false, repliesFailed: false });
|
|
|
this.onShow();
|
|
|
},
|
|
|
|
|
|
@@ -89,7 +91,9 @@ Page({
|
|
|
this.setData({ conversationsLoading: true, conversationsFailed: false });
|
|
|
try {
|
|
|
const conversations = await listConversations(scope);
|
|
|
- if (this.matches(scope)) this.setData({ conversations });
|
|
|
+ if (this.matches(scope)) this.setData({
|
|
|
+ conversations, conversationChoices: pickerChoices(conversations, '选择自己的近期对话'),
|
|
|
+ });
|
|
|
} catch {
|
|
|
if (this.matches(scope)) this.setData({ conversationsFailed: true });
|
|
|
} finally {
|
|
|
@@ -97,17 +101,22 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- async selectConversation(event) {
|
|
|
+ selectConversation(event) {
|
|
|
+ return this.loadReplies(selectedPickerIndex(event.detail.value, this.data.conversations));
|
|
|
+ },
|
|
|
+
|
|
|
+ async loadReplies(sessionIndex) {
|
|
|
const scope = authContext(getApp());
|
|
|
- const sessionIndex = Number(event.detail.value);
|
|
|
+ if (!scope) return;
|
|
|
const selected = this.data.conversations[sessionIndex];
|
|
|
- if (!scope || !selected) return;
|
|
|
const request = this.repliesRequest = (this.repliesRequest || 0) + 1;
|
|
|
const current = () => this.matches(scope) && request === this.repliesRequest && sessionIndex === this.data.sessionIndex;
|
|
|
- this.setData({ sessionIndex, replies: [], replyIndex: -1, includePrevious: false, repliesLoading: true, repliesFailed: false });
|
|
|
+ this.setData({ sessionIndex, replies: [], replyPickerChoices: [], replyIndex: -1, includePrevious: false,
|
|
|
+ repliesLoading: !!selected, repliesFailed: false });
|
|
|
+ if (!selected) return;
|
|
|
try {
|
|
|
const replies = await listReplies(scope, selected.id);
|
|
|
- if (current()) this.setData({ replies });
|
|
|
+ if (current()) this.setData({ replies, replyPickerChoices: pickerChoices(replies, '选择要举报的回复') });
|
|
|
} catch {
|
|
|
if (current()) this.setData({ repliesFailed: true });
|
|
|
} finally {
|
|
|
@@ -115,9 +124,13 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- retryReplies() { void this.selectConversation({ detail: { value: this.data.sessionIndex } }); },
|
|
|
- selectReply(event) { this.setData({ replyIndex: Number(event.detail.value), includePrevious: false }); },
|
|
|
- selectCategory(event) { this.setData({ categoryIndex: Number(event.detail.value) }); },
|
|
|
+ retryReplies() { void this.loadReplies(this.data.sessionIndex); },
|
|
|
+ selectReply(event) {
|
|
|
+ this.setData({ replyIndex: selectedPickerIndex(event.detail.value, this.data.replies), includePrevious: false });
|
|
|
+ },
|
|
|
+ selectCategory(event) {
|
|
|
+ this.setData({ categoryIndex: selectedPickerIndex(event.detail.value, REPORT_CATEGORIES) });
|
|
|
+ },
|
|
|
togglePrevious(event) { this.setData({ includePrevious: event.detail.value.includes('previous') }); },
|
|
|
|
|
|
editField(event) {
|
|
|
@@ -127,7 +140,12 @@ Page({
|
|
|
|
|
|
async submit() {
|
|
|
const scope = authContext(getApp());
|
|
|
- if (!scope || this.data.submitting) return;
|
|
|
+ if (this.data.submitting) return;
|
|
|
+ if (!scope) {
|
|
|
+ this.onShow();
|
|
|
+ this.setData({ notice: '登录已失效,请重新登录后提交。' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
const { active, form, sessionIndex, conversations, replies, replyIndex, categoryIndex, includePrevious } = this.data;
|
|
|
this.setData({ submitting: true, notice: '' });
|
|
|
try {
|
|
|
@@ -138,11 +156,15 @@ Page({
|
|
|
if (!this.matches(scope)) return;
|
|
|
this.setData({ form: emptyForm(), replyIndex: -1, categoryIndex: -1, includePrevious: false,
|
|
|
notice: '提交成功,工单号 ' + ticketNo + '。处理结果可在本页查看。' });
|
|
|
- await this.refreshRecords();
|
|
|
+ void this.refreshRecords();
|
|
|
} catch (error) {
|
|
|
- const message = ['请填写有效联系电话', '请填写联系人姓名', '请填写问题描述', '请选择 AI 回复和举报类型'].includes(error?.message)
|
|
|
- ? error.message : '提交结果待核对,请先刷新处理记录。';
|
|
|
- if (this.matches(scope)) this.setData({ notice: message });
|
|
|
+ if (this.closed) return;
|
|
|
+ if (!authContext(getApp())) {
|
|
|
+ this.onShow();
|
|
|
+ this.setData({ notice: '登录已失效,请重新登录后提交。' });
|
|
|
+ } else if (this.matches(scope)) {
|
|
|
+ this.setData({ notice: submitErrorMessage(error, active) });
|
|
|
+ }
|
|
|
} finally {
|
|
|
if (!this.closed) this.setData({ submitting: false });
|
|
|
}
|