const _Http = getApp().globalData.http; Page({ data: { loading: false, disabled: true, showAll: false, form: [{ label: "年度", error: false, errMsg: "", type: "selector", value: "", placeholder: "请选择年份", valueName: "year", required: true, range: [], rangeKey: "name", rangeIndex: 0 }, { label: "任务名称", error: false, errMsg: "", type: "text", value: "", placeholder: "请输入任务名称", valueName: "taskname", required: true, checking: "base" }, { label: "合同模版", error: false, errMsg: "", type: "radio", value: "", radioList: [], valueName: "sa_esign_contract_templateid", required: true, checking: "base", direction: "horizontal" }, { label: "备注", error: false, errMsg: "", type: "textarea", value: "", placeholder: "请输入备注信息", valueName: "remarks", required: false, checking: "base" }], content: { sa_esign_contract_taskid: 0 } }, onLoad(options) { this.getYearList(); this.getTemplateList(); }, /* 生成年份列表 */ getYearList() { const currentYear = new Date().getFullYear(); const years = []; for (let i = currentYear - 5; i <= currentYear + 5; i++) { years.push({ id: i.toString(), name: i.toString() }); } let form = this.data.form; let yearField = form.find(v => v.valueName === 'year'); yearField.range = years; yearField.rangeIndex = 5; yearField.value = currentYear.toString(); this.setData({ form }); }, /* 获取合同模版列表 */ getTemplateList() { _Http.basic({ id: '2026042013062102', content: { pageNumber: 1, pageSize: 100 } }).then(res => { if (res.code == 1 && res.data && res.data.length) { let form = this.data.form; let templateField = form.find(v => v.valueName === 'sa_esign_contract_templateid'); templateField.radioList = res.data.map(item => ({ id: item.sa_esign_contract_templateid, name: item.name })); templateField.value = res.data[0].sa_esign_contract_templateid; this.setData({ form }); this.selectComponent("#Form").confirm(); } }); }, /* 表单必填项是否完成 */ onConfirm({ detail }) { this.setData({ disabled: detail }); }, /* 表单中断回调 */ interrupt({ detail }) { // 处理条件变化 }, /* 提交表单 */ submit() { this.setData({ loading: true }); let formData = this.selectComponent("#Form").submit(); if (!formData) { this.setData({ loading: false }); return; } let content = { ...this.data.content, ...formData }; _Http.basic({ id: '2026041309401702', content }).then(res => { this.setData({ loading: false }); if (res.code == 1) { const listPage = getCurrentPages().find(v => v.__route__ == 'CRM/contract/index'); if (listPage) { listPage.getList(true); } wx.redirectTo({ url: '/CRM/contract/detail?id=' + res.data.sa_esign_contract_taskid, success: () => { wx.showToast({ title: '创建成功', icon: 'none' }); } }); } else { wx.showToast({ title: res.msg || '创建失败', icon: 'none' }); } }).catch(() => { this.setData({ loading: false }); wx.showToast({ title: '创建失败', icon: 'none' }); }); }, /* 是否显示全部 */ onChange({ detail }) { this.setData({ showAll: detail }); }, closePage() { wx.navigateBack({ delta: 1 }); } });