import { conclusionForm } from '../clue-item.js'; import { uploadConclusion } from '../../../services/clue/fetchClue'; Page({ /** * 页面的初始数据 */ data: { formArray: [], // 模式,add: 新增;update:更新 mode: 'add', submitText: '保存', }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getOpenerEventChannel().on('acceptConclusionData', data => { const { conclusion, clue, isInternal } = data; const formArray = conclusionForm(conclusion); const mode = conclusion ? 'update' : 'add'; this.setData({ formArray, mode, clue, isInternal }); }); }, // 提交表单 submit(e) { const { mode, clue, isInternal } = this.data; const formObj = e.detail; formObj.cid = clue.cid; formObj.ccInternal = isInternal; if (mode == 'add') { this.create(formObj); } else { this.update(formObj); } }, // 取消表单 cancel() { wx.navigateBack({ delta: 1, }); }, // 新增 create(formObj) { uploadConclusion(formObj).then(res => { if (res.success) { this.getOpenerEventChannel().emit('uploadOver'); wx.navigateBack({ delta: 1, success: () => { wx.showToast({ title: '结论提交成功', duration: 2000, icon: 'success', mask: true, }); }, }); } else { wx.showToast({ title: res.message, duration: 2000, icon: 'error', mask: true, }); } }); }, // 更新 update(formObj) { this.create(formObj); }, });