Files
xingque/pages/gongdan/detail/detail.js

64 lines
2.1 KiB
JavaScript

import request from '../../../utils/request.js'
Page({
data: {
detail: null,
imageList: [],
shengjiList: [],
escShow: false,
escText: '',
escLoading: false,
id: '',
},
onLoad(q) {
this.setData({ id: q.id || '' })
this.load()
},
async load() {
const res = await request({ url: '/gongdan/detail/', method: 'POST', data: { gongdan_id: this.data.id } })
const body = res.data || {}
if (body.code === 200 || body.code === 0) {
const d = body.data || {}
this.setData({
detail: d,
imageList: Array.isArray(d.images) ? d.images : [],
shengjiList: Array.isArray(d.shengji_list) ? d.shengji_list : [],
})
}
},
copy(e) {
wx.setClipboardData({ data: String(e.currentTarget.dataset.t || '') })
},
preview(e) {
const urls = (this.data.imageList || []).map(i => i.url).filter(Boolean)
wx.previewImage({ current: e.currentTarget.dataset.url, urls })
},
async markBad() {
const res = await request({ url: '/gongdan/dissatisfied/', method: 'POST', data: { gongdan_id: this.data.id } })
if ((res.data || {}).code === 200) {
wx.showToast({ title: '已标记', icon: 'success' })
this.load()
} else wx.showToast({ title: (res.data || {}).message || '失败', icon: 'none' })
},
showEsc() { this.setData({ escShow: true }) },
onEsc(e) { this.setData({ escText: e.detail.value }) },
async doEsc() {
if (!this.data.escText.trim()) return wx.showToast({ title: '请填写补充说明', icon: 'none' })
this.setData({ escLoading: true })
try {
const res = await request({
url: '/gongdan/escalate/',
method: 'POST',
data: { gongdan_id: this.data.id, shuoming: this.data.escText },
})
if ((res.data || {}).code === 200) {
wx.showToast({ title: '已提交', icon: 'success' })
this.setData({ escShow: false, escText: '' })
this.load()
} else wx.showToast({ title: (res.data || {}).message || '失败', icon: 'none' })
} finally {
this.setData({ escLoading: false })
}
},
})