import api from '../api/api'; const _Http = getApp().globalData.http; let deleteUsers = []; Page({ data: { stopClick: '', SignName: true, timerid: null, act_confirm_value: '是', form: { "sa_workorderid": 0, "sa_workorder_nodeid": 0, "remarks": "", "textcontent": "", "confirm_value": "", "amount": 0, "isconfirm": 0, "team": [], "trainers": [], "traintitem": [], }, bindNormalData: { ownertable: 'sa_workorder_node', ownerid: 0, usetype: 'default' }, bindContractData: { "ownertable": "sa_workorder_node", "ownerid": 0, "usetype": "contract", }, bindSignNameData: { "ownertable": "sa_workorder_node", "ownerid": 0, "usetype": "signature", }, addpersonBadge: {}, additemBadge: {}, addpersonLabel: '', additemLabel: '', activeTab: 0 }, onTabChange(e) { const value = parseInt(e.currentTarget.dataset.value) this.setData({ activeTab: value }) }, async nodeDetail() { const res = await api._post({ "id": "20230209091103", "version": 1, "content": { nocache: true, "sa_workorderid": this.data.sa_workorderid, "sa_workorder_nodeid": this.data.sa_workorder_nodeid } }) console.log("详情", res.data) const language = getApp().globalData.Language.getMapText('E-订单') || {} const isAddpersonRequired = res.data[0].workpresetjson.addperson == 11 const isAdditemRequired = res.data[0].workpresetjson.additem == 11 this.setData({ mainData: res.data[0], teams: res.data[0].team.map(v => v.userid), titems: res.data[0].titems, addpersonBadge: isAddpersonRequired ? { count: '*', color: '#e34d59', offset: ['20rpx', '-10rpx'], size: 'small' } : {}, additemBadge: isAdditemRequired ? { count: '*', color: '#e34d59', offset: ['20rpx', '-10rpx'], size: 'small' } : {}, addpersonLabel: language['培训人员'] || '培训人员', additemLabel: language['工单物料'] || '工单物料', activeTab: res.data[0].workpresetjson.addperson !== 0 ? 0 : 1 }) this.setDefaultData() try { this.selectComponent("#signName").fileData() } catch (error) { } }, // 是否确认 confirmValue(data) { this.data.form.confirm_value = data.currentTarget.dataset.item this.setData({ form: this.data.form }) this.updateNode() }, // 文本信息 textContent(data) { this.data.form.textcontent = data.detail.value this.setData({ form: this.data.form }) this.updateNode() }, // 是否有偿 amountPay(data) { this.data.form.amount = data.detail.value this.setData({ form: this.data.form }) this.updateNode() }, // 备 注 remarkEdit(data) { this.data.form.remarks = data.detail.value this.setData({ form: this.data.form }) this.updateNode() }, // 校验必填项 validateRequiredFields() { const workpreset = this.data.mainData.workpresetjson const errors = [] if (workpreset.confirm == 11 && !this.data.form.confirm_value) { errors.push('是否确认') } if (workpreset.fileupload == 11) { const uploadComponent = this.selectComponent('#fileUpload') if (uploadComponent && (!uploadComponent.data.originFiles || uploadComponent.data.originFiles.length === 0)) { errors.push('上传附件') } } if (workpreset.textedit == 11 && !this.data.form.textcontent) { errors.push('文本信息') } if (workpreset.contractupload == 11) { const contractUploadComponent = this.selectComponent('#contractUpload') if (contractUploadComponent && (!contractUploadComponent.data.originFiles || contractUploadComponent.data.originFiles.length === 0)) { errors.push('上传合同') } } if (workpreset.amountpay == 11 && (!this.data.form.amount || this.data.form.amount == 0)) { errors.push('是否有偿') } if (workpreset.signature == 11) { const signNameComponent = this.selectComponent('#signName') if (signNameComponent && (!signNameComponent.data.originFiles || signNameComponent.data.originFiles.length === 0)) { errors.push('客户签字') } } if (workpreset.addperson == 11 && (!this.data.mainData.trainers || this.data.mainData.trainers.length === 0)) { errors.push('培训人员') } if (workpreset.additem == 11 && (!this.data.titems || this.data.titems.length === 0)) { errors.push('工单物料') } return errors }, confirmBill() { const errors = this.validateRequiredFields() if (errors.length > 0) { wx.showToast({ title: '必填信息未完善', icon: 'none', duration: 2000 }) return } this.data.form.isconfirm = 1 this.setData({ form: this.data.form }) this.updateNode() }, // 保存节点(不校验) saveNode(e) { this.updateNode(false, e) }, // 更新节点 async updateNode(needValidate = false, e) { if (needValidate) { const errors = this.validateRequiredFields() if (errors.length > 0) { wx.showToast({ title: '必填信息未完善', icon: 'none', duration: 2000 }) return } } this.data.form.traintitem = this.data.titems this.data.form.sa_workorderid = this.data.sa_workorderid this.data.form.sa_workorder_nodeid = this.data.sa_workorder_nodeid this.data.form.team = [] const res = await api._post({ "id": "20230209094203", "content": this.data.form }); if (!this.data.form.team.some(v => v.userid == wx.getStorageSync('userMsg').userid)) { this.setData({ teams: [wx.getStorageSync('userMsg').userid] }) this.addUser(false); } if (e && e.currentTarget && e.currentTarget.dataset.info === 'needBack') { wx.navigateBack() } else { this.nodeDetail() } try { this.selectComponent("#signName").fileData() } catch (error) { } }, // 获取输入的数据 setDefaultData() { let that = this Object.keys(this.data.mainData).map((key, index) => { Object.keys(this.data.form).map((key2, index) => { if (key === key2) { that.data.form[key2] = that.data.mainData[key2] } }) }) this.setData({ form: this.data.form }) }, // 跳转到添加人员 addTrainers() { wx.navigateTo({ url: '/Eservice/addTrainers/index', }) }, // 添加人员 getAddTrainers(data) { this.data.form.trainers.push(data) this.data.mainData.trainers = this.data.form.trainers this.setData({ // form:this.data.form, mainData: this.data.mainData }) this.updateNode() }, // 删除人员 deleteMenber(data) { this.data.mainData.trainers = this.data.mainData.trainers.filter(e => { return e.sa_workorder_node_teamid !== data.detail.sa_workorder_node_teamid }) this.data.form.trainers = this.data.mainData.trainers this.setData({ form: this.data.form, mainData: this.data.mainData }) this.updateNode() }, // 跳转到物料添加 addProduct() { let itemtype = this.data.mainData.workpresetjson.itemtype; // ①若itemtype是"服务商品",则type=2:查询申请单商品 // ②若itemtype是"培训物料",则type=1:查询档案商品 let type = itemtype === '服务商品' ? 2 : 1; wx.navigateTo({ url: `/E-service/serviceBillList/product/select?params=${JSON.stringify({ "content": { "sa_workorderid": this.data.sa_workorderid, "type": type, // 1档案, 2:申请单 "pageNumber": 1, "pageSize": 20, "where": { "condition": "" } }, "id": "2026022710102502", })}` }); getApp().globalData.handleSelect = this.handleSelect.bind(this) }, /* 处理新增产品 */ handleSelect(detail) { let newItems = detail.list.map(v => { return { "itemname": v.itemname, "itemid": v.itemid, "model": v.model, "spec": v.spec, qty: v.qty || 1 } }) let existingItems = this.data.titems || [] let allItems = [...existingItems, ...newItems] this.setData({ titems: allItems }) this.updateNode() wx.navigateBack(); }, // 修改物料数量 qtyChange(data) { clearTimeout(this.data.timerid) this.data.timerid = setTimeout(() => { this.data.titems.forEach(e => { if (e.itemid == data.detail.itemid) { e.qty = data.detail.qty } }) this.setData({ titems: this.data.titems }) this.updateNode() }, 1000) this.setData({ timerid: this.data.timerid }) }, // 删除物料 deleteMaterial(data) { this.setData({ titems: this.data.titems.filter(e => { return e.itemid !== data.detail.itemid }) }) this.updateNode() }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.data.bindContractData.ownerid = options.id this.data.bindNormalData.ownerid = options.id this.data.bindSignNameData.ownerid = options.id this.setData({ bindContractData: this.data.bindContractData, bindNormalData: this.data.bindNormalData, bindSignNameData: this.data.bindSignNameData, sa_workorder_nodeid: options.id, sa_workorderid: options.wid, stopClick: options.class }) this.nodeDetail(); let page = getCurrentPages()[getCurrentPages().length - 2]; if (page.__route__ == 'E-service/workOrder/detail') this.setData({ workers: page.data.detail.team }) getApp().globalData.Language.getLanguagePackage(this, 'E-订单'); }, onShow() { this.setData({ SignName: true }) }, onHide() { this.setData({ SignName: false }) }, /** * 开始添加成员或者取消添加 */ showTeamDialog() { this.setData({ showTeams: !this.data.showTeams }) }, /** * 选择添加成员 */ selectTeams(e) { const { userid } = e.currentTarget.dataset.item; let teams = this.data.teams; if (teams.some(v => v == userid)) { teams = teams.filter(v => v != userid) deleteUsers.push(userid); } else { teams.push(userid) } this.setData({ teams }) }, addUser(init = true) { api._post({ "id": 20220930103803, "content": { ownertable: 'sa_workorder_node', ownerid: this.data.mainData.sa_workorder_nodeid, "userids": deleteUsers } }).then(s => { console.log("先删除", s) deleteUsers = []; api._post({ "id": 20220930103603, "content": { ownertable: 'sa_workorder_node', ownerid: this.data.mainData.sa_workorder_nodeid, "userids": this.data.teams } }).then(res => { console.log("添加成员", res) wx.showToast({ title: res.code == '1' ? getApp().globalData.Language.getMapText('修改成功') : res.msg, icon: "none", mask: true }); if (res.code == '1') { this.nodeDetail(); if (init) this.showTeamDialog(); } }) }) }, onUnload() { getCurrentPages().find(v => v.__route__ == 'E-service/workOrder/detail').getDetail() } })