| | |
| | | // pages/m_user/base_c/c_scene-info/c_scene-info.js |
| | | import b_inputCheck from '../../behaviors/b_inputCheck' |
| | | import sceneInfo from '../../../../data/sceneInfo' |
| | | import {sceneInfo, sceneLedger} from '../../../../data/sceneInfo' |
| | | import userservice from '../../../../service/userservice' |
| | | import deviceservice from '../../../../service/deviceservice' |
| | | import ledgerservice from "../../../../service/ledgerservice" |
| | | import b_inputCheck from '../../../../base/behaviors/b_inputCheck' |
| | | import b_uploadLedger from '../../../m_ledger/behaviors/b_uploadLedger' |
| | | import b_loadingToast from '../../../../base/behaviors/b_loadingToast' |
| | | |
| | | const app = getApp() |
| | | |
| | | Component({ |
| | | behaviors: [b_inputCheck], |
| | | behaviors: [b_inputCheck, b_uploadLedger, b_loadingToast], |
| | | options: { |
| | | addGlobalClass: true, |
| | | }, |
| | |
| | | sceneType: { |
| | | type: String, |
| | | value: '1' |
| | | }, |
| | | authStatus: { |
| | | type: Boolean, |
| | | value: false |
| | | } |
| | | }, |
| | | |
| | | attached() { |
| | | |
| | | }, |
| | | |
| | | pageLifetimes: { |
| | | show: function () { |
| | | // 页面被展示 |
| | | const info = sceneInfo() |
| | | this.setData({ |
| | | msg: info.get(this.data.sceneType) |
| | | }) |
| | | }, |
| | | hide: function () { |
| | | // 页面被隐藏 |
| | | }, |
| | | resize: function (size) { |
| | | // 页面尺寸变化 |
| | | } |
| | | ready() { |
| | | this.setData({ |
| | | loadingText: '上传中', |
| | | loadCompleteText: '上传完成' |
| | | }) |
| | | const info = sceneInfo() |
| | | this.setData({ |
| | | msg: info.get(this.data.sceneType), |
| | | ledger: sceneLedger[this.data.sceneType] |
| | | }) |
| | | //获取场景信息 |
| | | this.getSceneInfo() |
| | | }, |
| | | |
| | | /** |
| | | * 组件的初始数据 |
| | | */ |
| | | data: { |
| | | |
| | | msg: [], |
| | | info: {} |
| | | }, |
| | | |
| | | /** |
| | | * 组件的方法列表 |
| | | */ |
| | | methods: { |
| | | selectChange(e) { |
| | | const index = e.currentTarget.dataset.index |
| | | const options = e.detail.options |
| | | //获取场景信息 |
| | | getSceneInfo() { |
| | | var that = this |
| | | userservice.getBaseInfo(app.globalData.accessToken.userId, { |
| | | success(data) { |
| | | const msg = that.data.msg |
| | | switch (that.data.sceneType) { |
| | | case '1': |
| | | if (data.baseInfo != null) { |
| | | msg[0].value = data.baseInfo.biName |
| | | msg[1].value = data.baseInfo.biNickName |
| | | msg[3].value = data.baseInfo.biAddress |
| | | msg[10].value = data.baseInfo.biContact |
| | | msg[11].value = data.baseInfo.biTelephone |
| | | msg[12].value = data.baseInfo.biTownName == null ? [] : [ |
| | | data.baseInfo.biProvinceName, data.baseInfo.biCityName, data.baseInfo.biDistrictName, data.baseInfo.biTownName, |
| | | data.baseInfo.biProvinceCode, data.baseInfo.biCityCode, data.baseInfo.biDistrictCode, data.baseInfo.biTownCode, |
| | | ] |
| | | msg[12].displayValue = data.baseInfo.biTownName == null ? [] : [ |
| | | data.baseInfo.biProvinceName, data.baseInfo.biCityName, data.baseInfo.biDistrictName, data.baseInfo.biTownName, |
| | | ] |
| | | } |
| | | if (data.specialInfo != null) { |
| | | msg[2].value = data.specialInfo.rbCuisine |
| | | msg[2].options.forEach(o => { |
| | | o.checked = false |
| | | }); |
| | | msg[2].value.split(';').forEach(v => { |
| | | for (let i = 0; i < msg[2].options.length; i++) { |
| | | const o = msg[2].options[i]; |
| | | if (v == o.name) { |
| | | o.checked = true |
| | | break |
| | | } else if (o.hasRemark) { |
| | | o.checked = true |
| | | o.remark += v |
| | | } |
| | | } |
| | | }); |
| | | const s = data.specialInfo.rbTotalSeating |
| | | msg[4].value = data.specialInfo.rbTotalSeating |
| | | msg[4].options.forEach(o => { |
| | | o.checked = false |
| | | }); |
| | | if (s == 0) { |
| | | msg[4].options[0].checked = true |
| | | } else if (s > 0 && s <= 20) { |
| | | msg[4].options[1].checked = true |
| | | } else if (s > 20 && s <= 50) { |
| | | msg[4].options[2].checked = true |
| | | } else if (s > 50 && s <= 100) { |
| | | msg[4].options[3].checked = true |
| | | } else { |
| | | msg[4].options[4].checked = true |
| | | } |
| | | msg[7].value = data.specialInfo.rbCookingRangeNum |
| | | msg[8].value = parseInt(data.specialInfo.rbCookingOilCapacity) * 12 |
| | | msg[9].value = data.specialInfo.rbCookingOilType |
| | | msg[9].options.forEach(o => { |
| | | o.checked = false |
| | | }); |
| | | msg[9].value.split(';').forEach(v => { |
| | | for (let i = 0; i < msg[9].options.length; i++) { |
| | | const o = msg[9].options[i]; |
| | | if (v == o.name) { |
| | | o.checked = true |
| | | break |
| | | } else if (o.hasRemark) { |
| | | o.checked = true |
| | | o.remark += v |
| | | } |
| | | } |
| | | }); |
| | | msg[13].value = data.specialInfo.rbConcentrationArea |
| | | msg[14].value = data.specialInfo.rbOutfallCount |
| | | msg[15].value = data.specialInfo.rbOutfallLocation |
| | | msg[16].value = data.specialInfo.rbOutfallNum |
| | | } |
| | | deviceservice.getPurifyDeviceInfo(app.globalData.accessToken.userId, { |
| | | success(res) { |
| | | if (res.length > 0) { |
| | | that.setData({ |
| | | ['msg[5].value']: res[0].fpNum |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | deviceservice.getMoniterDeviceInfo(app.globalData.accessToken.userId, { |
| | | success(res) { |
| | | if (res.length > 0) { |
| | | that.setData({ |
| | | ['msg[6].value']: res[0].mdNum |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | ledgerservice.getLedgerDetail( |
| | | app.globalData.accessToken.userId, that.data.ledger.ledgerSubTypeId, that.data.ledger.sceneType, undefined, { |
| | | success(res) { |
| | | if (res.length > 0) { |
| | | let detail = res[0] |
| | | if (detail.upLoad) { |
| | | let imgFiles = [{ |
| | | url: detail.path1[0], |
| | | loading: false |
| | | }] |
| | | that.setData({ |
| | | imgFiles |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | break; |
| | | case '2': |
| | | |
| | | break; |
| | | case '3': |
| | | |
| | | break; |
| | | case '4': |
| | | |
| | | break; |
| | | case '5': |
| | | |
| | | break; |
| | | case '6': |
| | | |
| | | break; |
| | | case '7': |
| | | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | console.log(msg); |
| | | that.setData({ |
| | | msg |
| | | }) |
| | | } |
| | | }, app.globalData.accessToken.openId) |
| | | }, |
| | | |
| | | //提交场景信息 |
| | | _submit() { |
| | | var that = this |
| | | this.setData({ |
| | | [`msg[${index}].options`]: options |
| | | loading: true |
| | | }) |
| | | //针对不同场景,数据结构会有不同的定制需求 |
| | | switch (this.data.sceneType) { |
| | | case '1': |
| | | const m = this.data.msg[4] |
| | | for (let i = 0; i < m.options.length; i++) { |
| | | const o = m.options[i]; |
| | | if (o.checked) { |
| | | this.setData({ |
| | | [`info.${m.id}`]: o.value |
| | | }) |
| | | break |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | const sceneInfoStr = JSON.stringify(this.data.info) |
| | | userservice.authScene(app.globalData.accessToken.openId, app.globalData.userInfo.extension2, sceneInfoStr, { |
| | | success(res) { |
| | | that.submintLedger() |
| | | }, |
| | | }) |
| | | }, |
| | | |
| | | pickerChange(e) { |
| | | console.log(e); |
| | | const { |
| | | index, |
| | | mode |
| | | } = e.currentTarget.dataset |
| | | let i = e.detail.value |
| | | if (mode == 'region') { |
| | | //提交图片信息 |
| | | submintLedger() { |
| | | if (this.data.imgFiles.length == 0) { |
| | | this.setData({ |
| | | [`msg[${index}].value`]: i |
| | | loading: false |
| | | }) |
| | | } else if (mode == 'selector') { |
| | | this.setData({ |
| | | [`msg[${index}].selectIndex`]: i, |
| | | [`msg[${index}].value`]: this.data.msg[index].options[i].value |
| | | wx.navigateBack({ |
| | | delta: 1, |
| | | }) |
| | | return |
| | | } |
| | | if (this.data.imgFiles[0].url.indexOf('http') != -1) { |
| | | wx.downloadFile({ |
| | | url: this.data.imgFiles[0].url, |
| | | success: (res) => { |
| | | const imgPath = res.tempFilePath |
| | | this.data.imgFiles[0].url = imgPath |
| | | this._uploadLedger() |
| | | } |
| | | }) |
| | | } else { |
| | | this._uploadLedger() |
| | | } |
| | | }, |
| | | |
| | | //上传完成后,回退 |
| | | _success(res) { |
| | | wx.navigateBack({ |
| | | delta: 1, |
| | | }) |
| | | } |
| | | } |
| | | }) |