import { getClassifyList, changeToIssue } from '../../utils/api' Page({ data: { textareaValue: '', cascaderVisible: false, selectedClassify: { value: '', label: '' }, cascaderOptions: [], topicId: '', timer: '' }, onShow () { }, onLoad (options) { this.getClassifyList() this.setData({ topicId: options.topicId }) }, // textarea v-model bindTextareaValue (e) { this.setData({ textareaValue: e.detail.value }) }, // 选择分类 chooseClassify () { this.setData({ cascaderVisible: true }) }, // cascader 关闭回调 onClose (e) { this.setData({ cascaderVisible: false }) }, // cascader change回调 onChange (e) { const selectedClassify = { value: e.detail.options[e.detail.options.length - 1].value || '', label: e.detail.options[e.detail.options.length - 1].label || '' } this.setData({ selectedClassify }) }, // 获取分类列表 getClassifyList () { getClassifyList().then(res => { console.log('分类列表', res) this.filterClassifyList(res.data) this.setData({ cascaderOptions: res.data }) }).catch(err => { console.log(err) }) }, // 递归分类列表 filterClassifyList (classifyList) { classifyList.forEach(item => { item.label = item.categoryName item.value = item.id if (item.children && item.children.length > 0) { this.filterClassifyList(item.children) } }) }, debounceChangeToIssue () { clearTimeout(this.data.timer) this.data.timer = setTimeout(() => { this.changeToIssue() }, 500) }, // 话题转议题 changeToIssue () { if (this.data.textareaValue === '') { wx.showToast({ title: '请输入处理意见', icon: 'none', duration: 2000 }) return false } else if (this.data.selectedClassify.label === '') { wx.showToast({ title: '请选择分类', icon: 'none', duration: 2000 }) return false } const para = { id: this.data.topicId, categoryId: this.data.selectedClassify.value, advice: this.data.textareaValue } wx.showLoading({ title: '加载中' }) changeToIssue(para).then(res => { wx.hideLoading() console.log('话题转议题', res) wx.showToast({ title: '话题已转为议题', icon: 'none', duration: 2000 }) const pages = getCurrentPages() const page = pages[pages.length - 3] page.pullRefreshGetTopicList() wx.navigateBack({ delta: 2 }) }).catch(err => { console.log(err) }) } })