import WxValidate from '../../utils/WxValidate.js'; const app = require('../../utils/util.js'); const request = require('../../utils/request.js'); const COS = require('../../utils/cos.js'); const tool = require('../../utils/tool.js'); Page({ data: { form: { tel: '', height: '', weight: '', education: '', income: '', marriage: '', children: '', assetHouse: '', assetHouseArea: '', assetHouseLoan: '', assetCar: '', assetCarValue: '', assetCarLoan: '', isCommon: '', controlTime: '', workStatus: '', companyNature: '', company: '', parents: '', fatherWork: '', matherWork: '', parentAssets: '', composition: '', motionState: '', hobby: '' }, heightArr: [], weightArr: [], educationArr: [], incomeArr: [], marriageList: [], childrenArr: [], assetHouseArr: [], assetAreaArr: [], assetHouseLoanArr: [], assetCarArr: [], assetCarValueArr: [], assetCarLoanArr: [], isCommonArr: ['没有', '一起'], controlTimeArr: [], workStatusArr: [], companyNatureArr: [], parentsArr: [], fatherWorkArr: [], matherWorkArr: [], parentAssetsArr: [], compositionArr: [], motionStateArr: [], hobbyArr: [] }, phoneChange(e) { let tel = 'form.tel' this.setData({ [tel]: e.detail.value }) }, heightPicker(e) { let height = 'form.height' this.setData({ heightLabel: this.data.heightArr[e.detail.value], [height]: this.data.heightArrValue[e.detail.value] }) }, weightPicker(e) { let weight = 'form.weight' this.setData({ weightLabel: this.data.weightArr[e.detail.value], [weight]: this.data.weightArrValue[e.detail.value] }) }, educationPicker(e) { let education = 'form.education' this.setData({ educationLabel: this.data.educationArr[e.detail.value], [education]: this.data.educationArrValue[e.detail.value] }) }, incomePicker(e) { let income = 'form.income' this.setData({ incomeLabel: this.data.incomeArr[e.detail.value], [income]: this.data.incomeArrValue[e.detail.value] }) }, marriageChange(e) { let marriage = 'form.marriage' this.setData({ marriageLabel: this.data.marriageList[e.detail.value], [marriage]: this.data.marriageListValue[e.detail.value] }) }, childrenChange(e) { let children = 'form.children' this.setData({ childrenLabel: this.data.childrenArr[e.detail.value], [children]: this.data.childrenArrValue[e.detail.value] }) }, assetHousePickerChange(e) { console.log(e) let assetHouse = 'form.assetHouse' this.setData({ assetHouseLabel: this.data.assetHouseArr[e.detail.value], [assetHouse]: this.data.assetHouseArrValue[e.detail.value] }) }, assetAreaPickerChange(e) { console.log(e) let assetHouseArea = 'form.assetHouseArea' this.setData({ assetAreaLabel: this.data.assetAreaArr[e.detail.value], [assetHouseArea]: this.data.assetAreaArrValue[e.detail.value] }) }, assetHouseLoanPickerChange(e) { console.log(this.data.assetHouseLoanArr) console.log(this.data.assetHouseLoanArrValue) let assetHouseLoan = 'form.assetHouseLoan' this.setData({ assetHouseLoanLabel: this.data.assetHouseLoanArr[e.detail.value], [assetHouseLoan]: this.data.assetHouseLoanArrValue[e.detail.value] }) }, assetCarPickerChange(e) { console.log(e) let assetCar = 'form.assetCar' this.setData({ assetCarLabel: this.data.assetCarArr[e.detail.value], [assetCar]: this.data.assetCarArrValue[e.detail.value] }) }, assetCarValuePickerChange(e) { console.log(e) let assetCarValue = 'form.assetCarValue' this.setData({ assetCarValueLabel: this.data.assetCarValueArr[e.detail.value], [assetCarValue]: this.data.assetCarValueArrValue[e.detail.value] }) }, assetCarLoanPickerChange(e) { console.log(e) let assetCarLoan = 'form.assetCarLoan' this.setData({ assetCarLoanLabel: this.data.assetCarLoanArr[e.detail.value], [assetCarLoan]: this.data.assetCarLoanArrValue[e.detail.value] }) }, isCommonChange(e) { let isCommon = 'form.isCommon' this.setData({ [isCommon]: e.detail.value, isCommonLabel: this.data.isCommonArr[e.detail.value], }) }, controlTimeChange(e) { const items = this.data.controlTimeArr; const values = e.detail.value; let controlTime = 'form.controlTime' for (let i = 0, lenI = items.length; i < lenI; ++i) { items[i].checked = false for (let j = 0, lenJ = values.length; j < lenJ; ++j) { if (items[i].value === values[j]) { items[i].checked = true break } } } this.setData({ controlTimeArr: this.data.controlTimeArr, [controlTime]: e.detail.value }) }, workStatusChange(e) { console.log(e.detail.value) const items = this.data.workStatusArr; const values = e.detail.value; for (let i = 0, lenI = items.length; i < lenI; ++i) { items[i].checked = false for (let j = 0, lenJ = values.length; j < lenJ; ++j) { if (items[i].value === values[j]) { items[i].checked = true break } } } let workStatus = 'form.workStatus' this.setData({ [workStatus]: e.detail.value, workStatusArr: this.data.workStatusArr }) }, companyNaturePicker(e) { let companyNature = 'form.companyNature' this.setData({ companyNatureLabel: this.data.companyNatureArr[e.detail.value], [companyNature]: this.data.companyNatureArrValue[e.detail.value] }) }, companyChange(e) { let company = 'form.company' this.setData({ [company]: e.detail.value }) }, parentsPicker(e) { let parents = 'form.parents' this.setData({ parentsLabel: this.data.parentsArr[e.detail.value], [parents]: this.data.parentsArrValue[e.detail.value] }) }, fatherworkPicker(e) { let fatherWork = 'form.fatherWork' this.setData({ fatherWorkLabel: this.data.fatherWorkArr[e.detail.value], [fatherWork]: this.data.fatherWorkArrValue[e.detail.value] }) }, matherworkPicker(e) { let matherWork = 'form.matherWork' this.setData({ matherWorkLabel: this.data.matherWorkArr[e.detail.value], [matherWork]: this.data.matherWorkArrValue[e.detail.value] }) }, parentAssetsPicker(e) { let parentAssets = 'form.parentAssets' this.setData({ parentAssetsLabel: this.data.parentAssetsArr[e.detail.value], [parentAssets]: this.data.parentAssetsArrValue[e.detail.value] }) }, compositionChange(e) { console.log(e.detail.value) const items = this.data.compositionArr; const values = e.detail.value; for (let i = 0, lenI = items.length; i < lenI; ++i) { items[i].checked = false for (let j = 0, lenJ = values.length; j < lenJ; ++j) { if (items[i].value === values[j]) { items[i].checked = true break } } } let composition = 'form.composition' this.setData({ compositionArr: this.data.compositionArr, [composition]: e.detail.value }) }, figurePicker(e) { let motionState = 'form.motionState' this.setData({ motionStateLabel: this.data.motionStateArr[e.detail.value], [motionState]: this.data.motionStateArrValue[e.detail.value] }) }, hobbyChange(e) { console.log(e.detail.value) const items = this.data.hobbyArr; const values = e.detail.value; for (let i = 0, lenI = items.length; i < lenI; ++i) { items[i].checked = false for (let j = 0, lenJ = values.length; j < lenJ; ++j) { if (items[i].value === values[j]) { items[i].checked = true break } } } console.log(this.data.hobbyArrLabel) let indexArr = []; for (let i = 0; i < e.detail.value.length; i++) { indexArr.push(this.data.hobbyArrLabel.indexOf(e.detail.value[i])) } let value = []; for (let i = 0; i < indexArr.length; i++) { value.push(this.data.hobbyArrValue[indexArr[i]]) } let str = ''; for (let i = 0; i < value.length; i++) { str += value[i] + ',' } let hobby = 'form.hobby' this.setData({ hobbyArr: this.data.hobbyArr, [hobby]: str.slice(0, str.length - 1) // [hobby]: e.detail.value }) }, // 获取手机号 getPhoneNumber(e) { tool.isLogin().then(res => { console.log(res) if (e.detail.errMsg == "getPhoneNumber:ok") { wx.request({ url: app.globalData.publicUrl + '/wx/user/wxbfa171fdd4000e03/phone', header: { 'content-type': 'application/x-www-form-urlencoded', }, data: { sessionKey: this.data.sessionkey, signature: res.signature, rawData: res.rawData, encryptedData: e.detail.encryptedData, iv: e.detail.iv }, method: "POST", success: (res) => { console.log(res, '我是解析的手号'); let tel = 'form.tel' if (res.data.phoneNumber) { this.setData({ [tel]: res.data.phoneNumber }) } else { this.setData({ [tel]: 0 }) } } }) } }).catch(err => { wx.showModal({ title: '您还未登录', showCancel: false, success(res) { if (res.confirm) { wx.redirectTo({ url: '/pages/personal/personal', }) } } }); }) }, getInfos() { wx.showLoading(); wx.request({ url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info', method: "get", success: (res) => { console.log(res, '我是获取的信息') let tel = 'form.tel' let height = 'form.height' let weight = 'form.weight' let education = 'form.education' let income = 'form.income' let marriage = 'form.marriage' let children = 'form.children' let assetHouse = 'form.assetHouse' let assetHouseArea = 'form.assetHouseArea' let assetHouseLoan = 'form.assetHouseLoan' let assetCar = 'form.assetCar' let assetCarValue = 'form.assetCarValue' let assetCarLoan = 'form.assetCarLoan' let isCommon = 'form.isCommon' let controlTime = 'form.controlTime' let workStatus = 'form.workStatus' let companyNature = 'form.companyNature' let company = 'form.company' let parents = 'form.parents' let fatherWork = 'form.fatherWork' let matherWork = 'form.matherWork' let parentAssets = 'form.parentAssets' let composition = 'form.composition' let motionState = 'form.motionState' let hobby = 'form.hobby' tool.formDetails('he_body_height').then(result => { this.setData({ heightArr: result[0], heightArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.height) { this.setData({ heightLabel: result[0][i], [height]: result[1][i], }) } } } }) tool.formDetails('he_body_weight').then(result => { this.setData({ weightArr: result[0], weightArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.weight) { this.setData({ weightLabel: result[0][i], [weight]: result[1][i], }) } } } }) tool.formDetails('he_education').then(result => { this.setData({ educationArr: result[0], educationArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.education) { this.setData({ educationLabel: result[0][i], [education]: result[1][i], }) } } } }) tool.formDetails('he_income').then(result => { this.setData({ incomeArr: result[0], incomeArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.income) { this.setData({ incomeLabel: result[0][i], [income]: result[1][i], }) } } } }) tool.formDetails('he_marriage').then(result => { this.setData({ marriageList: result[0], marriageListValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.marriage) { this.setData({ marriageLabel: result[0][i], [marriage]: result[1][i] }) } } } }) tool.formDetails('he_children').then(result => { this.setData({ childrenArr: result[0], childrenArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.children) { this.setData({ childrenLabel: result[0][i], [children]: result[1][i] }) } } } }) tool.formDetails('he_asset_house').then(result => { this.setData({ assetHouseArr: result[0], assetHouseArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.assetHouse) { this.setData({ assetHouseLabel: result[0][i], [assetHouse]: result[1][i], }) } } } }) tool.formDetails('he_asset_house_area').then(result => { this.setData({ assetAreaArr: result[0], assetAreaArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.assetHouseArea) { this.setData({ assetAreaLabel: result[0][i], [assetHouseArea]: result[1][i], }) } } } }) tool.formDetails('he_asset_house_loan').then(result => { this.setData({ assetHouseLoanArr: result[0], assetHouseLoanArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.assetHouseLoan) { this.setData({ assetHouseLoanLabel: result[0][i], [assetHouseLoan]: result[1][i], }) } } } }) tool.formDetails('he_asset_car').then(result => { this.setData({ assetCarArr: result[0], assetCarArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.assetCar) { this.setData({ assetCarLabel: result[0][i], [assetCar]: result[1][i], }) } } } }) tool.formDetails('he_asset_car_value').then(result => { this.setData({ assetCarValueArr: result[0], assetCarValueArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.assetCarValue) { this.setData({ assetCarValueLabel: result[0][i], [assetCarValue]: result[1][i], }) } } } }) tool.formDetails('he_asset_car_loan').then(result => { this.setData({ assetCarLoanArr: result[0], assetCarLoanArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.assetCarLoan) { this.setData({ assetCarLoanLabel: result[0][i], [assetCarLoan]: result[1][i], }) } } } }) tool.formDetails('he_control_time').then(result => { let controlTimeArr = result[0].map((item, index) => { return Object.assign({}, { 'name': item, 'value': item, 'checked': false }) }) if (res.data.code == 0 && res.data.info.controlTime) { let resControlTime = res.data.info.controlTime.split(","); let resControlTimeIndexArr = []; for (let i = 0; i < resControlTime.length; i++) { for (let j = 0; j < result[1].length; j++) { if (resControlTime[i] == result[1][j]) { resControlTimeIndexArr.push(j) } } } let resControlTimeLabel = []; for (let i = 0; i < resControlTimeIndexArr.length; i++) { resControlTimeLabel.push(result[0][resControlTimeIndexArr[i]]) } for (let i = 0; i < resControlTimeLabel.length; i++) { for (let j = 0; j < controlTimeArr.length; j++) { if (resControlTimeLabel[i] == controlTimeArr[j].value) { controlTimeArr[j].checked = true; } } } this.setData({ [controlTime]: resControlTimeLabel }) } this.setData({ controlTimeArr: controlTimeArr, controlTimeArrLabel: result[0], controlTimeArrValue: result[1], }) console.log(this.data.controlTimeArr, '1111111111111') }) tool.formDetails('he_work_status').then(result => { let workStatusArr = result[0].map((item, index) => { return Object.assign({}, { 'name': item, 'value': item, 'checked': false }) }) if (res.data.code == 0 && res.data.info.workStatus) { let resWorkStatus = res.data.info.workStatus.split(","); let resWorkStatusIndexArr = []; for (let i = 0; i < resWorkStatus.length; i++) { for (let j = 0; j < result[1].length; j++) { if (resWorkStatus[i] == result[1][j]) { resWorkStatusIndexArr.push(j) } } } let resWorkStatusLabel = []; for (let i = 0; i < resWorkStatusIndexArr.length; i++) { resWorkStatusLabel.push(result[0][resWorkStatusIndexArr[i]]) } for (let i = 0; i < resWorkStatusLabel.length; i++) { for (let j = 0; j< workStatusArr.length; j++) { if (resWorkStatusLabel[i] == workStatusArr[j].value) { workStatusArr[j].checked = true; } } } this.setData({ [workStatus]: resWorkStatusLabel }) } this.setData({ workStatusArr: workStatusArr, workStatusArrLabel: result[0], workStatusArrValue: result[1] }) }) tool.formDetails('he_company_nature').then(result => { if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.companyNature) { this.setData({ companyNatureLabel: result[0][i], [companyNature]: result[1][i] }) } } } if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.fatherWork) { this.setData({ fatherWorkLabel: result[0][i], [fatherWork]: result[1][i] }) } } } if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.matherWork) { this.setData({ matherWorkLabel: result[0][i], [matherWork]: result[1][i] }) } } } this.setData({ companyNatureArr: result[0], companyNatureArrValue: result[1], fatherWorkArr: result[0], fatherWorkArrValue: result[1], matherWorkArr: result[0], matherWorkArrValue: result[1] }) }) if (res.data.code == 0) { this.setData({ [tel]: res.data.info.tel, [company]: res.data.info.company, [hobby]: res.data.info.hobby, [isCommon]: res.data.info.isCommon, isCommonLabel: this.data.isCommonArr[res.data.info.isCommon], }) } tool.formDetails('he_parents').then(result => { this.setData({ parentsArr: result[0], parentsArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.parents) { this.setData({ parentsLabel: result[0][i], [parents]: result[1][i], }) } } } }) tool.formDetails('he_parent_assets').then(result => { this.setData({ parentAssetsArr: result[0], parentAssetsArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.parentAssets) { this.setData({ parentAssetsLabel: result[0][i], [parentAssets]: result[1][i], }) } } } }) tool.formDetails('he_composition').then(result => { let compositionArr = result[0].map((item, index) => { return Object.assign({}, { 'name': item, 'value': item, 'checked': false }) }) if (res.data.code == 0 && res.data.info.composition) { let resComposition = res.data.info.composition.split(","); let resCompositionIndexArr = []; for (let i = 0; i < resComposition.length; i++) { for (let j = 0; j < result[1].length; j++) { if (resComposition[i] == result[1][j]) { resCompositionIndexArr.push(j) } } } let resCompositionLabel = []; for (let i = 0; i < resCompositionIndexArr.length; i++) { resCompositionLabel.push(result[0][resCompositionIndexArr[i]]) } for (let i = 0; i < resCompositionLabel.length; i++) { for (let j = 0; j < compositionArr.length; j++) { if (resCompositionLabel[i] == compositionArr[j].value) { compositionArr[j].checked = true; } } } this.setData({ [composition]: resCompositionLabel }) } this.setData({ compositionArr: compositionArr, compositionArrLabel: result[0], compositionArrValue: result[1], }) }) tool.formDetails('he_sports').then(result => { console.log(result) this.setData({ motionStateArr: result[0], motionStateArrValue: result[1] }) if (res.data.code == 0) { for (let i = 0; i < result[0].length; i++) { if (result[1][i] == res.data.info.motionState) { console.log(i) this.setData({ motionStateLabel: result[0][i], [motionState]: result[1][i], }) } } } }) tool.formDetails('he_hobby').then(result => { let hobbyArr = result[0].map((item, index) => { return Object.assign({}, { 'name': item, 'value': item, 'checked': false }) }) if (res.data.code == 0 && res.data.info.hobby) { let reshobby = res.data.info.hobby.split(","); let reshobbyIndexArr = []; for (let i = 0; i < reshobby.length; i++) { for (let j = 0; j < result[1].length; j++) { if (reshobby[i] == result[1][j]) { reshobbyIndexArr.push(j) } } } let reshobbyLabel = []; for (let i = 0; i < reshobbyIndexArr.length; i++) { reshobbyLabel.push(result[0][reshobbyIndexArr[i]]) } for (let i = 0; i < reshobbyLabel.length; i++) { for (let j = 0; j < hobbyArr.length; j++) { if (reshobbyLabel[i] == hobbyArr[j].value) { hobbyArr[j].checked = true; } } } this.setData({ [hobby]: reshobbyLabel }) } this.setData({ hobbyArr: hobbyArr, hobbyArrLabel: result[0], hobbyArrValue: result[1] }) }) }, complete: () => { wx.hideLoading() } }) }, // 提交 formSubmit(e) { console.log(e) console.log(this.data.HobbyLabel) const params = e.detail.value let controlTime = 'form.controlTime'; let workStatus = 'form.workStatus'; let composition = 'form.composition' let indexArr = []; for (let i = 0; i < params.controlTime.length; i++) { indexArr.push(this.data.controlTimeArrLabel.indexOf(params.controlTime[i])) } let value = []; for (let i = 0; i < indexArr.length; i++) { value.push(this.data.controlTimeArrValue[indexArr[i]]) } let str = ''; for (let i = 0; i < value.length; i++) { str += value[i] + ',' } let indexArr2 = []; for (let i = 0; i < params.workStatus.length; i++) { indexArr2.push(this.data.workStatusArrLabel.indexOf(params.workStatus[i])) } let value2 = []; for (let i = 0; i < indexArr2.length; i++) { value2.push(this.data.workStatusArrValue[indexArr2[i]]) } let str2 = ''; for (let i = 0; i < value2.length; i++) { str2 += value2[i] + ',' } console.log(this.data.compositionArrLabel) let indexArr3 = []; for (let i = 0; i < params.composition.length; i++) { indexArr3.push(this.data.compositionArrLabel.indexOf(params.composition[i])) } let value3 = []; for (let i = 0; i < indexArr3.length; i++) { value3.push(this.data.compositionArrValue[indexArr3[i]]) } let str3 = ''; for (let i = 0; i < value3.length; i++) { str3 += value3[i] + ',' } this.setData({ [controlTime]: str.slice(0, str.length - 1), [workStatus]: str2.slice(0, str2.length - 1), [composition]: str3.slice(0, str3.length - 1), // [hobby]: str4.slice(0, str4.length - 1) }) console.log(this.data.form) //校验表单 if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0] this.showModal(error) return false } wx.request({ url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info', method: "POST", header: { 'content-type': 'application/x-www-form-urlencoded', }, data: this.data.form, success: (res) => { console.log(res) if (res.data.code == 0) { wx.showModal({ title: '上传成功', showCancel: false, success:(res)=> { if (res.confirm) { if(this.data.targetStatus){ wx.redirectTo({ url: '/pages/index/index', }) }else{ wx.redirectTo({ url: '/pages/targetInfo/targetInfo', }) } } } }); } } }) }, //报错 showModal(error) { wx.showModal({ content: error.msg, showCancel: false, }) }, //验证函数 initValidate() { const rules = { tel: { required: false }, height: { required: true }, weight: { required: true }, education: { required: true }, income: { required: true }, marriage: { required: true }, children: { required: true }, assetHouse: { required: true }, // assetHouseArea: { // required: true // }, // assetHouseLoan: { // required: true // }, assetCar: { required: true }, // assetCarValue: { // required: true // }, // assetCarLoan: { // required: true // }, isCommon: { required: true }, controlTime: { required: true }, workStatus: { required: true }, companyNature: { required: true }, company: { required: true }, parents: { required: true }, composition: { required: true }, motionState: { required: true }, hobby: { required: true } // photoUrl: { // required: true // } } const messages = { tel: { required: '请输入联系方式呦' }, height: { required: '请选择身高呦' }, weight: { required: '请选择体重呦' }, education: { required: '请选择教育程度呦' }, income: { required: '请选择收入呦' }, marriage: { required: '请选择婚姻状态呦' }, children: { required: '请选择您有没有孩子呦' }, assetHouse: { required: '请选择是否买房子呦' }, // assetHouseArea: { // required: '请选择房子多大面积' // }, // assetHouseLoan: { // required: '请选择房子贷款了没' // }, assetCar: { required: '请选择车子情况呦' }, // assetCarValue: { // required: '请选择车子的价值' // }, // assetCarLoan: { // required: '请选择车子贷款了没' // }, isCommon: { required: '请选择是否与父母同住呦' }, controlTime: { required: '请选择您的空闲时间呦' }, workStatus: { required: '请选择您的工作状态呦' }, companyNature: { required: '请选择您的单位性质呦' }, company: { required: '请输入您的单位具体名称呦' }, parents: { required: '请选择您的父母情况呦' }, composition: { required: '请选择有没有兄弟姐妹呦' }, motionState: { required: '请选择您是否喜欢运动呦' }, hobby: { required: '请选择您的爱好呦' } // photoUrl: { // required: '请上传您的照片' // } } this.WxValidate = new WxValidate(rules, messages) }, async onLoad(options) { this.initValidate(); tool.openidStatus().then(result => { this.setData({ openid: result[0], sessionkey: result[1] }) this.getInfos(); tool.isFinishTargetInfo().then(res => { console.log(res) this.setData({ targetStatus: true }) }).catch(err=>{ console.log(err) this.setData({ targetStatus: false }) }) }) }, // 上传头像 uploadPhoto() { wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['', 'camera'], success: (res) => { console.log(res) let path = res.tempFilePaths[0]; console.log(path) this.setData({ carWin_img: path }) this.toCos(); } }) }, // 传cos toCos() { var Bucket = 'yuehe-1257653330'; var Region = 'ap-beijing'; var ForcePathStyle = false; var prefix = 'https://' + Bucket + '.cos.' + Region + '.myqcloud.com/'; if (ForcePathStyle) { prefix = 'https://cos.' + Region + '.myqcloud.com/' + Bucket + '/'; } var stsCache; var getCredentials = (callback) => { if (stsCache && Date.now() / 1000 + 30 < stsCache.expiredTime) { callback(data.credentials); return; } wx.request({ method: 'POST', url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/getCosSts', // dataType: 'json', success: function (result) { console.log(result, '222222222222') var credentials = result.data.credential.credentials; if (credentials) { stsCache = result.data.credential } else { wx.hideLoading() wx.showModal({ title: '临时密钥获取失败', content: JSON.stringify(data), showCancel: false }); } callback(stsCache && stsCache.credentials); }, error: function (err) { wx.hideLoading() wx.showModal({ title: '临时密钥获取失败', content: JSON.stringify(err), showCancel: false }); } }); }; // 计算签名 var getAuthorization = function (options, callback) { getCredentials(function (credentials) { callback({ XCosSecurityToken: credentials.sessionToken, Authorization: COS({ SecretId: credentials.tmpSecretId, SecretKey: credentials.tmpSecretKey, Method: options.Method, Pathname: options.Pathname, }) }); }); }; // 上传文件 var Key = this.data.carWin_img.substr(this.data.carWin_img.lastIndexOf('/') + 1); // 这里指定上传的文件名 var signPathname = '/'; if (ForcePathStyle) { signPathname = '/' + Bucket + '/'; } getAuthorization({ Method: 'POST', Pathname: signPathname }, (AuthData) => { var requestTask = wx.uploadFile({ url: prefix, name: 'file', filePath: this.data.carWin_img, formData: { 'key': "face/" + Key, 'success_action_status': 200, 'Signature': AuthData.Authorization, 'x-cos-security-token': AuthData.XCosSecurityToken, 'Content-Type': '', }, success: (res) => { console.log(res.header.Location) let photoUrl = 'form.photoUrl' this.setData({ [photoUrl]: res.header.Location }) // this.tj(params, res.header.Location) }, fail: function () { wx.hideLoading() wx.showModal({ title: '上传失败', showCancel: false }); } }); requestTask.onProgressUpdate(function (res) { console.log('进度:', res.progress); }); }); } })