2023-02-15 16:46:08 +08:00

266 lines
5.0 KiB
JavaScript

// pages/home/session/session.js
import {
sessionQuery,
sessionAdditiveQuery,
sessionChangeStandard
} from '../../../services/api/session';
import {
sessionUpload
} from '../../../services/api/session';
Page({
/**
* 页面的初始数据
*/
data: {
sessionId: 0,
headerImage: '',
pageData: {
additives: {
count: 3,
kinds: []
},
address: [],
company: [],
images: [],
licenseCode: [],
sessionId: 0,
standard: "",
standardType: "",
tags: [],
typeCode: "",
typeName: "",
rate: {
level: 4,
text: '',
type: ''
}
},
visibleImages: false,
additives: [],
inter: '',
standardPopupVisible: false,
standardDialogVisible: false,
changeStandard: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.sessionId = options?.sessionId;
// this.sessionId = 76
this.init();
},
onChangeStandard() {
this.setData({
standardDialogVisible: true
})
},
onChangeStandardInput(e) {
this.setData({
changeStandard: e.detail.value
});
},
confirmStandardDialog() {
sessionChangeStandard({
id: this.sessionId,
standard: this.data.changeStandard
}).then(respose => {
if (respose.code == 10000) {
this.setData({
standardDialogVisible: false,
changeStandard: ''
});
this.init();
}
})
},
closeStandardDialog() {
this.setData({
standardDialogVisible: false
})
},
onOpenStandard() {
if (this.data.pageData.standardInfo.isFound != 1) {
return
}
this.setData({
standardPopupVisible: true
})
},
onVisibleChange(e) {
this.setData({
standardPopupVisible: e.detail.visible,
});
},
init() {
sessionQuery({
id: this.sessionId
}).then(respose => {
if (respose.code == 10000) {
console.log(respose.content);
this.setData({
pageData: respose.content
})
console.log(this.data.pageData);
if (respose.content.standardInfo.isFound == 2) {
this.startInter();
}
}
})
sessionAdditiveQuery({
id: this.sessionId
}).then(respose => {
this.setData({
additives: respose.content?.additives
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 启动定时器
*/
startInter: function () {
var that = this;
that.data.inter = setInterval(
function () {
// TODO 你需要无限循环执行的任务
console.log('setInterval 每过500毫秒执行一次任务')
sessionQuery({
id: that.sessionId
}).then(respose => {
if (respose.code == 10000) {
console.log(respose.content);
if (respose.content.standardInfo.isFound != 2) {
that.setData({
pageData: respose.content
})
console.log(this.data.pageData);
this.endInter();
}
}
})
}, 3000);
},
/**
* 结束定时器
*/
endInter: function () {
var that = this;
clearInterval(that.data.inter);
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
this.endInter()
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
onTabsClick(event) {
// console.log(`Click tab, tab-panel value is ${event.detail.value}.`);
},
onShowImages() {
console.log(this.data.visibleImages);
this.setData({
visibleImages: true
})
},
onCloseImages() {
this.setData({
visibleImages: false
})
},
onAddImage() {
if (this.sessionId == 0) {
return
}
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
success: (res) => {
if (res.tempFiles.length >= 1) {
sessionUpload({
urls: res.tempFiles,
session: this.sessionId
}).then(tmp => {
console.log(tmp);
if (tmp.code == 10000) {
this.init();
}
})
} else {}
}
})
},
onGoAdditive(event) {
const additiveId = event.currentTarget.dataset.additive;
wx.navigateTo({
url: `/pages/home/additive/additive?additiveId=${additiveId}`,
});
},
onGoChemical(event) {
const chemicalId = event.currentTarget.dataset.chemical;
wx.navigateTo({
url: `/pages/home/chemical/chemical?chemicalId=${chemicalId}`,
});
}
})