const app = getApp() import Notify from '@vant/weapp/notify/notify'; import { repairAttachUpload, } from "../../../../utils/util.js" import { repairEvalRq, } from "../../../../api/repair/repair.js" Page({ /** * 页面的初始数据 */ data: { IMG_NAME: app.IMG_NAME, id: null, form: { "evalService": 0, "feedback": "" }, fileList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let _this = this _this.setData({ ...options }) }, // 选择评价 selectStar(e) { console.log('selectStar', e); let _this = this let form = _this.data.form form.evalService = e.currentTarget.dataset.index + 1 _this.setData({ form }) }, // input输入内容监听 fieldInput(e) { console.log('fieldInput', e); let _this = this; let form = _this.data.form; form[e.currentTarget.dataset.name] = e.detail _this.setData({ form }) }, // 图片-上传前校验 beforeRead(event) { // const { // file, // callback // } = event.detail; // callback(file.type === 'image'); }, // 文件-上传后 async fileAfterRead(event) { let _this = this; console.log('fileAfterRead', event); // 上传完成需要更新 fileList let fileList = _this.data.fileList; // const { file } = event.detail; // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式 for (let i = 0; i < file.length; i++) { let url = file[i].url; await repairAttachUpload({ url, repairId: _this.data.id, operate: 'eval' }).then(res => { console.log('upload file ', res); fileList.push({ id: res.id, relativeUrl: res.url, url: app.IMG_NAME + res.url, deletable: true, }) }) } _this.setData({ fileList }) }, // 删除图片 deleteImg(event) { console.log('deleteImg', event); let _this = this; let fileList = _this.data.fileList; fileList.splice(event.detail.index, 1); _this.setData({ fileList }) }, // 提交数据 submitData() { let _this = this; // 数据 let form = _this.data.form; // // 校验数据 // // 报修名称 if (!form.evalService) { app.vantNotifyErr(Notify, '请选择服务评价!') return; } // // 评价 repairEvalRq({ repair: { "id": _this.data.id, ..._this.data.form }, }).then(res => { console.log('repairEvalRq', res); // if (res.code == 0) { app.vantNotifySuccess(Notify, res.msg) app.selfBackPage(2) } else { app.vantNotifyErr(Notify, res.msg) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })