公寓小程序端前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

163 lines
3.8 KiB

// subpages/mine/evaluate/evaluate.js
import {evaluateAdd,evaluateInfo} from '../../../api/index'
var config = require('../../../utils/config')
Page({
/**
* 页面的初始数据
*/
data: {
satisfiedZt: null,
satisfiedHj: null,
satisfiedFw: null,
satisfiedTy: null,
fileList: [],
releaseMethod: 0,
evaluateContent: '',
info:{}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (options.id) {
this.getInfo(options.id)
console.log(options.obj);
this.setData({
info:JSON.parse(options.obj)
})
}
},
getInfo(id){
evaluateInfo(id).then(res=>{
if(res.code === 200){
this.setData({
// info:res.data
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
onChangeSwitch(e) {
this.setData({
releaseMethod: e.detail
})
},
handelChangTextarea(e){
this.setData({
evaluateContent:e.detail.value
})
},
onButtonTap(){
const {evaluateContent,releaseMethod,satisfiedZt,satisfiedHj,satisfiedFw,satisfiedTy,fileList} = this.data
evaluateAdd({evaluateContent,releaseMethod,satisfiedZt,satisfiedHj,satisfiedFw,satisfiedTy,checkInRecId:this.data.info.checkInRecId,images:fileList}).then(res=>{
console.log(res);
if(res.data.code === 200){
wx.showToast({
title: '评价成功',
duration:2000,
success:()=>{
setTimeout(()=>{
wx.navigateBack({
delta: 1 // 返回上一个页面
});
},2000)
}
})
}
}).catch(err=>{
console.log(err);
})
},
deleteData(event) {
// 删除
console.log(event.detail.index)
let newFileList = this.data.fileList.slice();
newFileList.splice(event.detail.index, 1);
this.setData({
fileList: newFileList
});
},
afterRead(event) {
const that = this
const {
file
} = event.detail;
const fileName = file.url.match(/\/([^\/]+\.\w+)$/)[1];
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
wx.uploadFile({
url:`${config.BASEURL()}/common/upload`, // 仅为示例,非真实的接口地址
filePath: file.url,
name: 'file',
header: {
"Content-type": "multipart/form-data",
'Authorization': wx.getStorageSync('token')
},
success(res) {
// 上传完成需要更新 fileList
const images = {url:JSON.parse(res.data).url,name:fileName,type:'image'}
that.setData({
fileList:that.data.fileList.concat(images)
});
},
});
},
beforeRead(event) {
const {
file,
callback
} = event.detail;
callback(file.type === 'image');
},
})