155 lines
4.8 KiB
JavaScript
155 lines
4.8 KiB
JavaScript
import request from '../../../utils/request.js'
|
|
import { openCustomerServiceChat } from '../../../utils/kefu-nav.js'
|
|
|
|
const TYPES = [
|
|
{ value: 1, label: '订单投诉' },
|
|
{ value: 2, label: '充值投诉' },
|
|
{ value: 3, label: '罚款投诉' },
|
|
{ value: 4, label: '管事投诉' },
|
|
{ value: 5, label: '被骗投诉' },
|
|
]
|
|
|
|
Page({
|
|
data: {
|
|
types: TYPES,
|
|
leixing: 1,
|
|
order_id: '',
|
|
chongzhi_id: '',
|
|
fadan_id: '',
|
|
guanshi_id: '',
|
|
shuoming: '',
|
|
images: [],
|
|
maxImages: 9,
|
|
submitting: false,
|
|
},
|
|
|
|
onLoad(q) {
|
|
const patch = {}
|
|
if (q.leixing) patch.leixing = Number(q.leixing) || 1
|
|
if (q.order_id) patch.order_id = decodeURIComponent(q.order_id)
|
|
if (q.chongzhi_id) patch.chongzhi_id = decodeURIComponent(q.chongzhi_id)
|
|
if (q.fadan_id) patch.fadan_id = decodeURIComponent(q.fadan_id)
|
|
if (Object.keys(patch).length) this.setData(patch)
|
|
},
|
|
|
|
onPickType(e) { this.setData({ leixing: Number(e.currentTarget.dataset.v) }) },
|
|
onOrderId(e) { this.setData({ order_id: e.detail.value }) },
|
|
onChongzhiId(e) { this.setData({ chongzhi_id: e.detail.value }) },
|
|
onFadanId(e) { this.setData({ fadan_id: e.detail.value }) },
|
|
onGuanshiId(e) { this.setData({ guanshi_id: e.detail.value }) },
|
|
onShuoming(e) { this.setData({ shuoming: e.detail.value }) },
|
|
|
|
openMiniKefu() { openCustomerServiceChat() },
|
|
openWxKefu() {
|
|
const app = getApp()
|
|
const cfg = app.globalData.kefuConfig || {}
|
|
if (!cfg.link || !cfg.enterpriseId) {
|
|
wx.showToast({ title: '微信客服未配置', icon: 'none' })
|
|
return
|
|
}
|
|
wx.openCustomerServiceChat({
|
|
extInfo: { url: cfg.link },
|
|
corpId: cfg.enterpriseId,
|
|
fail: () => wx.showToast({ title: '打开微信客服失败', icon: 'none' }),
|
|
})
|
|
},
|
|
|
|
goChongzhiList() { wx.navigateTo({ url: '/pages/gongdan/chongzhi-list/chongzhi-list' }) },
|
|
goPenalty() { wx.navigateTo({ url: '/pages/penalty/penalty/penalty' }) },
|
|
goMyList() { wx.navigateTo({ url: '/pages/gongdan/list/list' }) },
|
|
|
|
chooseImg() {
|
|
const left = this.data.maxImages - this.data.images.length
|
|
wx.chooseMedia({
|
|
count: left,
|
|
mediaType: ['image'],
|
|
success: async (res) => {
|
|
wx.showLoading({ title: '上传中' })
|
|
try {
|
|
const urls = [...this.data.images]
|
|
for (const f of res.tempFiles || []) {
|
|
const url = await this.uploadOne(f.tempFilePath)
|
|
if (url) urls.push(url)
|
|
}
|
|
this.setData({ images: urls.slice(0, this.data.maxImages) })
|
|
} catch (e) {
|
|
wx.showToast({ title: '上传失败', icon: 'none' })
|
|
} finally {
|
|
wx.hideLoading()
|
|
}
|
|
},
|
|
})
|
|
},
|
|
|
|
uploadOne(filePath) {
|
|
const app = getApp()
|
|
const base = (app.globalData.apiBaseUrl || '').replace(/\/$/, '')
|
|
const token = wx.getStorageSync('token') || ''
|
|
return new Promise((resolve, reject) => {
|
|
wx.uploadFile({
|
|
url: `${base}/gongdan/upload-image/`,
|
|
filePath,
|
|
name: 'file',
|
|
header: { Authorization: token ? `Bearer ${token}` : '' },
|
|
success: (res) => {
|
|
try {
|
|
const body = JSON.parse(res.data || '{}')
|
|
if ((body.code === 200 || body.code === 0) && body.data && body.data.url) {
|
|
resolve(body.data.url)
|
|
} else reject(new Error(body.message || '上传失败'))
|
|
} catch (e) { reject(e) }
|
|
},
|
|
fail: reject,
|
|
})
|
|
})
|
|
},
|
|
|
|
delImg(e) {
|
|
const i = e.currentTarget.dataset.i
|
|
const images = this.data.images.slice()
|
|
images.splice(i, 1)
|
|
this.setData({ images })
|
|
},
|
|
|
|
preview(e) {
|
|
wx.previewImage({ current: e.currentTarget.dataset.url, urls: this.data.images })
|
|
},
|
|
|
|
async submit() {
|
|
if (this.data.submitting) return
|
|
if (!(this.data.shuoming || '').trim()) {
|
|
wx.showToast({ title: '请填写投诉说明', icon: 'none' })
|
|
return
|
|
}
|
|
this.setData({ submitting: true })
|
|
try {
|
|
const res = await request({
|
|
url: '/gongdan/create/',
|
|
method: 'POST',
|
|
data: {
|
|
leixing: this.data.leixing,
|
|
shuoming: this.data.shuoming,
|
|
order_id: this.data.order_id,
|
|
chongzhi_id: this.data.chongzhi_id,
|
|
fadan_id: this.data.fadan_id,
|
|
guanshi_id: this.data.guanshi_id,
|
|
images: this.data.images,
|
|
},
|
|
})
|
|
const body = res.data || {}
|
|
if (body.code === 200 || body.code === 0) {
|
|
wx.showToast({ title: '提交成功', icon: 'success' })
|
|
setTimeout(() => {
|
|
wx.redirectTo({ url: '/pages/gongdan/list/list' })
|
|
}, 500)
|
|
} else {
|
|
wx.showToast({ title: body.message || body.msg || '提交失败', icon: 'none' })
|
|
}
|
|
} catch (e) {
|
|
wx.showToast({ title: '网络错误', icon: 'none' })
|
|
} finally {
|
|
this.setData({ submitting: false })
|
|
}
|
|
},
|
|
})
|