import request from '~/api/request' import uploadFileToOSS from '~/api/upload'; Page({ /** * 页面的初始数据 */ data: { form: { username: '', mmp_7: '', day: '', mobile: '', gallbladder_image: '', portal_vein_branch_image: '', portal_vein_cross_image: '' }, isName: true, isMmp: true, isDay: true, isMobile: true, isGallbladder: true, isPortalVeinBranch: true, isPortalVeinCross: true, imageVisible: false, imageList: [], imageIndex: 1, visible: false, msg: '' }, formKey: '', getUserinfo(e) { console.log(e) }, handleUpload(e) { const { mode } = e.currentTarget.dataset; uploadFileToOSS().then((imageUrl) => { wx.showToast({ title: '上传成功!', icon: 'success' }); this.setData({ [`form.${mode}`]: imageUrl }, () => { this.validateForm(mode); }) }) }, handleDelete(e) { const { mode } = e.currentTarget.dataset; this.setData({ [`form.${mode}`]: '' }) }, handleImagePreview(e) { const { mode } = e.currentTarget.dataset; this.setData({ imageList: [this.data.form[mode]], imageIndex: 1, imageVisible: true }) }, onInput(e) { const { mode } = e.currentTarget.dataset; this.setData({ [`form.${mode}`]: e.detail.value }, () => { this.validateForm(mode); }); }, validateForm(mode) { let update = {}; let form = this.data.form; if (!mode || mode === 'username') { update.isName = !!form.username.trim(); } if (!mode || mode === 'mmp_7') { update.isMmp = !!form.mmp_7.trim(); } if (!mode || mode === 'day') { update.isDay = !!form.day.trim(); } if (!mode || mode === 'mobile') { update.isMobile = /^1[3-9]\d{9}$/.test(form.mobile.trim()); } if (!mode || mode === 'gallbladder_image') { update.isGallbladder = !!form.gallbladder_image.trim(); } if (!mode || mode === 'portal_vein_branch_image') { update.isPortalVeinBranch = !!form.portal_vein_branch_image.trim(); } if (!mode || mode === 'portal_vein_cross_image') { update.isPortalVeinCross = !!form.portal_vein_cross_image.trim(); } this.setData(update); // 全量校验时返回整体结果 if (!mode) { return update.isName && update.isMmp && update.isDay && update.isMobile && update.isGallbladder && update.isPortalVeinBranch && update.isPortalVeinCross; } }, async toQuestionnaire() { if (!this.validateForm()) { wx.showToast({ title: '请完善表单信息', icon: 'none' }); return; } wx.showLoading({ title: '正在提交...', }) const body = { username: this.data.form.username, mmp_7: this.data.form.mmp_7, day: Number(this.data.form.day), mobile: this.data.form.mobile, gallbladder_image: this.data.form.gallbladder_image, portal_vein_branch_image: this.data.form.portal_vein_branch_image, portal_vein_cross_image: this.data.form.portal_vein_cross_image } try{ const res = await request('patient/diagnostic', 'post', body) wx.hideLoading() wx.showLoading({ title: '正在查询结果...', }) setTimeout(() => { this.searchDiagnostic(res) }, 1000) } catch(e) { wx.hideLoading() } }, async searchDiagnostic(data) { const resd = await request('patient/diagnostic/search', 'post', { mobile: this.data.form.mobile, user_id: data.user_id, username: this.data.form.username }) if(resd.success == true){ wx.hideLoading() this.setData({ msg: resd.message, visible: true }) } else { this.searchDiagnostic(data) } }, onClose(){ this.setData({ imageVisible: false }) }, confirm() { this.setData({ visible: false }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { // return { // path: '/pages/mmp-7/index', // imageUrl: '' // } } })