let _Http = getApp().globalData.http, getTime = require("../../utils/getTime"); Page({ data: { loading: false, showAll: false, content: { sat_campaignid: 0 }, disabled: true, otheramount: 0, otheramount1: '0.00', trainingCost: '0.00', allCost: '0.00', list: [] }, onLoad(options) { let form = [{ label: "活动名称", error: false, errMsg: "", type: "textarea", value: "", placeholder: "活动名称", valueName: "name", checking: "base", required: true }, { label: "活动类型", error: false, errMsg: "", type: "option", optionNmae: "campaigntype", optionType: "radio", //复选 radio 单选 value: "", placeholder: "活动类型", valueName: "type", checking: "base", required: true }, { label: "承办医院", error: false, errMsg: "", type: "route", url: "/prsx/select/hospital/index", value: "", placeholder: "承办医院", valueName: "sa_customersid", checking: "base", required: true, params: { "content": { "pageNumber": 1, "pageSize": 20, "where": { "condition": "" } }, "id": 2025102814083902, }, query: "&radio=true", required: false, interrupt: true }, { label: "科室", error: false, errMsg: "", type: "route", url: "/prsx/select/department/index", value: "", placeholder: "请先选择承办医院", valueName: "sa_hospitaldepid", checking: "base", disabled: true, params: { "content": { "pageNumber": 1, "pageSize": 20, "where": { "condition": "" } }, "id": 2025102310143002, }, query: "&radio=true", required: false }, { label: "开始日期", error: false, errMsg: "", type: "date", start: '', value: '', placeholder: "开始日期", valueName: "begdate", checking: "base", required: true, interrupt: true }, { label: "结束日期", error: false, errMsg: "", type: "date", start: '', value: "", placeholder: "结束时间", valueName: "enddate", checking: "base", required: false }, { label: "活动性质", error: false, errMsg: "", type: "option", optionNmae: "activitytype", optionType: "radio", //复选 radio 单选 value: "", placeholder: "活动性质", valueName: "activitytype", checking: "base", required: false }, { label: "活动形式", error: false, errMsg: "", type: "option", optionNmae: "activityformat", optionType: "radio", //复选 radio 单选 value: "", placeholder: "活动形式", valueName: "activityformat", checking: "base", required: true }, { label: "申请金额", error: false, errMsg: "", type: "digit", value: "", placeholder: "申请金额", valueName: "amount", checking: "base", required: false }, { label: "备注", error: false, errMsg: "", type: "textarea", value: "", placeholder: "请填写", valueName: "remarks", required: false, checking: "base" }, { label: "其他费用", error: false, errMsg: "", type: "digit", value: "", placeholder: "其他费用", valueName: "otheramount", checking: "base", required: false, interrupt: true }] if (options.data) { let data = JSON.parse(options.data); let sa_customersid = data.sa_customersid; data.sa_hospitaldepid = data.sa_hospitaldepid ? [data.hospitaldepname, [data.sa_hospitaldepid]] : '' data.sa_customersid = data.sa_hospitaldepid ? [data.hospitalname, [data.sa_customersid]] : '' form = form.map(v => { v.value = data[v.valueName] || ""; console.log("v.valueName", v.label) if (v.label == '科室' && sa_customersid) { v.params.content.sa_customersid = sa_customersid; v.disabled = false; v.placeholder = '选择科室'; } return v }) this.setData({ disabled: false, content: { sat_campaignid: data.sat_campaignid, }, form }) } this.setData({ form }) getApp().globalData.Language.getLanguagePackage(this, options.data ? '编辑市场活动' : '新建市场活动'); }, interrupt({ detail }) { let index = '' switch (detail.temporary.item.label) { case '承办医院': index = detail.form.findIndex(v => v.label == '承办医院') if (index != -1) { detail.form[index].value = detail.data.value; detail.form[index + 1].params.content.sa_customersid = detail.data.id[0]; detail.form[index + 1].disabled = false; detail.form[index + 1].placeholder = '选择科室'; } wx.navigateBack() break; case '开始日期': index = detail.form.findIndex(v => v.label == '开始日期') if (index != -1) { detail.form[index + 1].start = detail.data.value; if (new Date(detail.form[index + 1].value) < new Date(detail.data.value)) { detail.form[index + 1].value = ''; } } break; case '其他费用': this.data.otheramount = detail.data.value; this.calculatePrice() break; } this.setData({ form: detail.form }) }, calculatePrice() { const otheramount = this.data.otheramount, trainingCost = this.data.list.reduce((sum, item) => { return sum + (parseFloat(item.amount) || 0); }, 0); this.setData({ otheramount1: _Http.formatMoney(otheramount, 2, '', false), trainingCost: _Http.formatMoney(trainingCost, 2, '', false), allCost: _Http.formatMoney(((trainingCost - 0) + (otheramount - 0)), 2, '', false) }); }, /* 表单必填项是否完成 */ onConfirm({ detail }) { this.setData({ disabled: detail }) }, // 是否显示全部 onChange({ detail }) { this.setData({ showAll: detail, }) }, async submit() { this.setData({ loading: true }) let data = this.selectComponent("#Form").submit(), content = this.data.content data.sa_customersid = data.sa_customersid.length ? data.sa_customersid[1][0] : 0; data.sa_hospitaldepid = data.sa_hospitaldepid.length ? data.sa_hospitaldepid[1][0] : 0; data.doctors = this.data.list.map(v => { return { "sat_campaign_doctorid": 0, "sa_doctorid": v.sa_doctorid, "amount": v.amount } }); _Http.basic({ "classname": "webmanage.saletool.orderclue.ordercluecampaign", "method": "insertormodify_campaign", "content": { ...content, ...data, } }).then(res => { this.setData({ loading: false }) wx.showToast({ title: res.code != '1' ? res.msg : '保存成功', icon: "none", mask: res.code == '1' }) if (res.code != '1') return; getCurrentPages().forEach(v => { if (v.route == 'prsx/activity/detail') v.getDetail() }) setTimeout(() => { if (content.sat_campaignid == 0) { wx.redirectTo({ url: '/prsx/activity/detail?id=' + res.data.sat_campaignid, }) } else { wx.navigateBack() } }, 300) }) }, insetr() { let params = { "id": 2025103013523102, "content": { "sat_campaignid": 0, pageNumber: 1, pageSize: 20, "where": { "condition": "" } } }; wx.navigateTo({ url: '/prsx/select/docter/index?params=' + JSON.stringify(params) + '&radio=true', }) let that = this; getApp().globalData.handleSelect = function ({ item }) { wx.showModal({ content: `是否确定添加“${item.doctorname}”`, complete: ({ confirm }) => { if (confirm) { if (!this.data.list.some(v => v.sa_doctorid == item.sa_doctorid)) { item.amount = 0 that.setData({ list: this.data.list.concat([item]) }) } wx.showToast({ title: '添加成功', icon: "none" }) } } }) }.bind(this) }, deleteItem(e) { const { item } = e.currentTarget.dataset, that = this; wx.showModal({ content: `是否确定删除“${item.doctorname}”`, complete: ({ confirm }) => { if (confirm) { that.setData({ list: that.data.list.filter(v => v.sa_doctorid != item.sa_doctorid) }) this.calculatePrice(); } } }) }, toSearch() { if (this.data.showSearch && this.data.content.where.condition) { this.data.content.where.condition = ''; this.getList("", true); } else if (this.data.condition) { this.data.content.where.condition = this.data.condition; this.setData({ condition: this.data.condition }) this.getList("", true); } this.setData({ showSearch: !this.data.showSearch }) setTimeout(() => { this.setData({ focus: this.data.showSearch }) }, 300) }, // onChange({ // detail // }) { // this.data.condition = detail; // }, onSearch({ detail }) { this.data.content.where.condition = detail; this.getList("", true) }, changeAmount(e) { let value = e.detail.value, index = e.currentTarget.dataset.index; this.data.list[index].amount = value; this.calculatePrice(); } })