import WxValidate from '../../utils/WxValidate.js'; const app = require('../../utils/util.js'); const tool = require('../../utils/tool.js'); Page({ data: { form: { ageMin: '', ageMax: '', heightMin: '', heightMax: '', education: '', income: '', nativePlace: '', marriage: '', assetHouse: '', assetHouseArea: '', // assetHouseLoan: '', assetCar: '', assetCarValue: '', // assetCarLoan: '', constellation: '', workStatus: '', companyNature: '', parentAssets: '', composition: '', isCommon: '', id: '' }, educationArr: [], incomeArr: [], nativePlaceArr: [], marriageArr: [], constellationArr: [], workStatusArr: [], assetHouseArr: ['咋的都行', '租房', '购房'], assetHouseAreaArr: [], // assetHouseLoanArr: ['有', '没有', '咋的都行'], assetCarArr: ['咋的都行', '有', '没有'], assetCarValueArr: [], // assetCarLoanArr: ['不行', '行', '咋的都行'], companyNatureArr: [], parentAssetsArr: [], compositionArr: [], isCommonArr: ['咋的都行','愿意', '不愿意',] }, ageMinChange(e) { let ageMin = 'form.ageMin' this.setData({ [ageMin]: e.detail.value }) }, ageMaxChange(e) { let ageMax = 'form.ageMax' this.setData({ [ageMax]: e.detail.value }) }, heightMinChange(e) { let heightMin = 'form.heightMin' this.setData({ [heightMin]: e.detail.value }) }, heightMaxChange(e) { let heightMax = 'form.heightMax' this.setData({ [heightMax]: 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] }) }, nativePlacePicker(e) { let nativePlace = 'form.nativePlace'; this.setData({ nativePlaceLabel: this.data.nativePlaceArr[e.detail.value], [nativePlace]: this.data.nativePlaceArrValue[e.detail.value], }) }, marriageChange(e) { let marriage = 'form.marriage'; this.setData({ marriageLabel: this.data.marriageArr[e.detail.value], [marriage]: this.data.marriageArrValue[e.detail.value] }) }, assetHousePickerChange(e) { let assetHouse = 'form.assetHouse' this.setData({ assetHouseLabel: this.data.assetHouseArr[e.detail.value], [assetHouse]: this.data.assetHouseArrValue[e.detail.value] }) // let assetHouse = 'form.assetHouse'; // this.setData({ // assetHouseLabel: this.data.assetHouseArr[e.detail.value] // }) // if (e.detail.value != 2) { // this.setData({ // [assetHouse]: e.detail.value // }) // } }, assetHouseAreaPickerChange(e) { let assetHouseArea = 'form.assetHouseArea' this.setData({ assetHouseAreaLabel: this.data.assetHouseAreaArr[e.detail.value], [assetHouseArea]: this.data.assetHouseAreaArrValue[e.detail.value] }) }, // assetHouseLoanPickerChange(e) { // let assetHouseLoan = 'form.assetHouseLoan'; // this.setData({ // assetHouseLoanLabel: this.data.assetHouseLoanArr[e.detail.value] // }) // if (e.detail.value != 2) { // this.setData({ // [assetHouseLoan]: e.detail.value // }) // } // }, assetCarPickerChange(e) { console.log(e.detail.value) console.log(this.data.assetCarArr[e.detail.value]) let assetCar = 'form.assetCar'; this.setData({ assetCarLabel: this.data.assetCarArr[e.detail.value], [assetCar]: e.detail.value }) // if (e.detail.value != 2) { // this.setData({ // [assetCar]: e.detail.value // }) // } }, assetCarValuePickerChange(e) { let assetCarValue = 'form.assetCarValue' this.setData({ assetCarValueLabel: this.data.assetCarValueArr[e.detail.value], [assetCarValue]: this.data.assetCarValueArrValue[e.detail.value] }) }, // assetCarLoanPickerChange(e) { // let assetCarLoan = 'form.assetCarLoan'; // this.setData({ // assetCarLoanLabel: this.data.assetCarLoanArr[e.detail.value] // }) // if (e.detail.value != 2) { // this.setData({ // [assetCarLoan]: e.detail.value // }) // } // }, constellationPicker(e) { console.log(e.detail.value) const items = this.data.constellationArr; 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 constellation = 'form.constellation' this.setData({ constellationArr: this.data.constellationArr, [constellation]: 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({ workStatusArr: this.data.workStatusArr, [workStatus]: e.detail.value }) }, companyNaturePicker: function (e) { // let companyNature = 'form.companyNature' // this.setData({ // companyNatureLabel: this.data.companyNatureArr[e.detail.value], // [companyNature]: this.data.companyNatureArrValue[e.detail.value] // }) console.log(e.detail.value) const items = this.data.companyNatureArr; 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 companyNature = 'form.companyNature' this.setData({ companyNatureArr: this.data.companyNatureArr, [companyNature]: 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] }) }, compositionPicker(e) { let composition = 'form.composition' this.setData({ [composition]: this.data.compositionArrValue[e.detail.value], compositionLabel: this.data.compositionArr[e.detail.value] }) }, isCommonPicker(e) { console.log(e) let isCommon = 'form.isCommon' this.setData({ [isCommon]: e.detail.value, isCommonLabel: this.data.isCommonArr[e.detail.value] }) }, getInfos() { wx.showLoading(); wx.request({ url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/standard', method: "get", success: (res) => { console.log(res, '我是获取的信息') let ageMin = 'form.ageMin'; let ageMax = 'form.ageMax'; let heightMin = 'form.heightMin'; let heightMax = 'form.heightMax'; let income = 'form.income'; let nativePlace = 'form.nativePlace'; let education = 'form.education'; let marriage = 'form.marriage'; 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 constellation = 'form.constellation'; let workStatus = 'form.workStatus'; let companyNature = 'form.companyNature'; let composition = 'form.composition'; let parentAssets = 'form.parentAssets'; let isCommon = 'form.isCommon'; let id = 'form.id' if (res.data.code == 0) { this.setData({ [ageMin]: res.data.standard.ageMin, [ageMax]: res.data.standard.ageMax, [heightMin]: res.data.standard.heightMin, [heightMax]: res.data.standard.heightMax, // nativePlaceLabel: this.data.nativePlaceArr[res.data.standard.nativePlace], // [nativePlace]: res.data.standard.nativePlace, // marriageLabel: this.data.marriageArr[res.data.standard.marriage], // [marriage]: res.data.standard.marriage, // assetHouseLabel: this.data.assetHouseArr[res.data.standard.assetHouse], // [assetHouse]: res.data.standard.assetHouse, assetHouseAreaLabel: this.data.assetHouseAreaArr[res.data.standard.assetHouseArea], [assetHouseArea]: res.data.standard.assetHouseArea, // assetHouseLoanLabel: this.data.assetHouseLoanArr[res.data.standard.assetHouseLoan], // [assetHouseLoan]: res.data.standard.assetHouseLoan, assetCarLabel: this.data.assetCarArr[res.data.standard.assetCar], [assetCar]: res.data.standard.assetCar, // assetCarLoanLabel: this.data.assetCarLoanArr[res.data.standard.assetCarLoan], // [assetCarLoan]: res.data.standard.assetCarLoan, compositionLabel: this.data.compositionArr[res.data.standard.composition], [composition]: res.data.standard.composition, isCommonLabel: this.data.isCommonArr[res.data.standard.isCommon], [isCommon]: res.data.standard.isCommon, [id]: res.data.standard.id }) } tool.formDetails('he_is_no').then(result => { this.setData({ nativePlaceArr: ['咋的都行'].concat(result[0]), nativePlaceArrValue: ['0'].concat(result[1]), }) if (res.data.code == 0) { for (let i = 0; i < ['0'].concat(result[1]).length; i++) { if (res.data.standard.nativePlace == ['0'].concat(result[1])[i]) { this.setData({ nativePlaceLabel: ['咋的都行'].concat(result[0])[i], [nativePlace]: res.data.standard.nativePlace }) } } } }) tool.formDetails('he_divorce').then(result => { console.log(result) this.setData({ marriageArr: ['咋的都行'].concat(result[0]), marriageArrValue: ['0'].concat(result[1]), }) if (res.data.code == 0) { for (let i = 0; i < [''].concat(result[1]).length; i++) { if (res.data.standard.marriage == ['0'].concat(result[1])[i]) { this.setData({ marriageLabel: ['咋的都行'].concat(result[0])[i], [marriage]: res.data.standard.marriage }) } } } }) tool.formDetails('he_education').then(result => { let oArr = []; for (let i = 0; i < result[0].length; i++) { oArr.push(result[0][i].concat('以上')) } this.setData({ educationArr: ['咋的都行'].concat(oArr), educationArrValue: ['0'].concat(result[1]), }) if (res.data.code == 0) { for (let i = 0; i < ['0'].concat(result[1]).length; i++) { if (res.data.standard.education == ['0'].concat(result[1])[i]) { this.setData({ educationLabel: ['咋的都行'].concat(oArr)[i], [education]: res.data.standard.education }) } } } }) tool.formDetails('he_income').then(result => { this.setData({ incomeArr: ['咋的都行'].concat(result[0]), incomeArrValue: ['0'].concat(result[1]) }) if (res.data.code == 0) { for (let i = 0; i < [''].concat(result[1]).length; i++) { if (res.data.standard.income == ['0'].concat(result[1])[i]) { this.setData({ incomeLabel: ['咋的都行'].concat(result[0])[i], [income]: res.data.standard.income }) } } } }) tool.formDetails('he_asset_house').then(result => { this.setData({ assetHouseArr: ['咋的都行'].concat(result[0]), assetHouseArrValue: ['0'].concat(result[1]) }) if (res.data.code == 0) { for (let i = 0; i < [''].concat(result[1]).length; i++) { if (res.data.standard.assetHouse == ['0'].concat(result[1])[i]) { this.setData({ assetHouseLabel: ['咋的都行'].concat(result[0])[i], [assetHouse]: res.data.standard.assetHouse }) } } } // 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({ assetHouseAreaArr: ['咋的都行'].concat(result[0]), assetHouseAreaArrValue: ['0'].concat(result[1]) }) if (res.data.code == 0) { for (let i = 0; i < [''].concat(result[1]).length; i++) { if (res.data.standard.assetHouseArea == ['0'].concat(result[1])[i]) { this.setData({ assetHouseAreaLabel: ['咋的都行'].concat(result[0])[i], [assetHouseArea]: res.data.standard.assetHouseArea }) } } } }) tool.formDetails('he_asset_car_value').then(result => { this.setData({ assetCarValueArr: ['咋的都行'].concat(result[0]), assetCarValueArrValue: ['0'].concat(result[1]) }) if (res.data.code == 0) { for (let i = 0; i < [''].concat(result[1]).length; i++) { if (res.data.standard.assetCarValue == ['0'].concat(result[1])[i]) { this.setData({ assetCarValueLabel: ['咋的都行'].concat(result[0])[i], [assetCarValue]: res.data.standard.assetCarValue }) } } } }) tool.formDetails('he_astrology').then(result => { let constellationArr = result[0].map((item, index) => { return Object.assign({}, { 'name': item, 'value': item, 'checked': false }) }) console.log(result); if (res.data.code == 0 && res.data.standard.constellation) { let resComposition = res.data.standard.constellation.split(","); console.log(resComposition, '我是拆分完的星座值') 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]) { console.log(i) console.log(j) resCompositionIndexArr.push(j) } } } console.log(resCompositionIndexArr) let resCompositionLabel = []; for (let i = 0; i < resCompositionIndexArr.length; i++) { resCompositionLabel.push(result[0][resCompositionIndexArr[i]]) } console.log(constellationArr) for (let i = 0; i < resCompositionLabel.length; i++) { for (let j = 0; j < constellationArr.length; j++) { if (resCompositionLabel[i] == constellationArr[j].name) { constellationArr[j].checked = true; } } } this.setData({ [constellation]: resCompositionLabel }) } this.setData({ constellationArr: constellationArr, constellationArrLabel: result[0], constellationArrValue: result[1], }) }) 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.standard.workStatus) { let resWorkStatus = res.data.standard.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 => { let companyNatureArr = result[0].map((item, index) => { return Object.assign({}, { 'name': item, 'value': item, 'checked': false }) }) if (res.data.code == 0 && res.data.standard.companyNature) { let rescompanyNature = res.data.standard.companyNature.split(","); let recompanyNatureIndexArr = []; for (let i = 0; i < rescompanyNature.length; i++) { for (let j = 0; j < result[1].length; j++) { if (rescompanyNature[i] == result[1][j]) { recompanyNatureIndexArr.push(j) } } } let rescompanyNatureLabel = []; for (let i = 0; i < recompanyNatureIndexArr.length; i++) { rescompanyNatureLabel.push(result[0][recompanyNatureIndexArr[i]]) } for (let i = 0; i < rescompanyNatureLabel.length; i++) { for (let j = 0; j < companyNatureArr.length; j++) { if (rescompanyNatureLabel[i] == companyNatureArr[j].value) { companyNatureArr[j].checked = true; } } } this.setData({ [companyNature]: rescompanyNatureLabel }) } this.setData({ companyNatureArr: companyNatureArr, companyNatureArrLabel: result[0], companyNatureArrValue: result[1], }) }) tool.formDetails('he_composition_agree').then(result => { this.setData({ compositionArr: ['咋的都行'].concat(result[0]), compositionArrValue: ['0'].concat(result[1]) }) if (res.data.code == 0) { for (let i = 0; i < [''].concat(result[1]).length; i++) { if (res.data.standard.composition == ['0'].concat(result[1])[i]) { this.setData({ compositionLabel: ['咋的都行'].concat(result[0])[i], [composition]: res.data.standard.composition }) } } } }) tool.formDetails('he_parent_assets').then(result => { this.setData({ parentAssetsArr: ['咋的都行'].concat(result[0]), parentAssetsArrValue: ['0'].concat(result[1]) }) if (res.data.code == 0) { for (let i = 0; i < [''].concat(result[1]).length; i++) { if (res.data.standard.parentAssets == ['0'].concat(result[1])[i]) { this.setData({ parentAssetsLabel: ['咋的都行'].concat(result[0])[i], [parentAssets]: res.data.standard.parentAssets }) } } } }) }, complete: () => { wx.hideLoading() } }) }, formSubmit(e) { const params = e.detail.value //校验表单 if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0] this.showModal(error) return false } let constellation = 'form.constellation' let workStatus = 'form.workStatus' let companyNature = 'form.companyNature' let indexArr = []; for (let i = 0; i < params.constellation.length; i++) { indexArr.push(this.data.constellationArrLabel.indexOf(params.constellation[i])) } let value = []; for (let i = 0; i < indexArr.length; i++) { value.push(this.data.constellationArrValue[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] + ',' } let indexArr3 = []; for (let i = 0; i < params.companyNature.length; i++) { indexArr3.push(this.data.companyNatureArrLabel.indexOf(params.companyNature[i])) } let value3 = []; for (let i = 0; i < indexArr3.length; i++) { value3.push(this.data.companyNatureArrValue[indexArr3[i]]) } let str3 = ''; for (let i = 0; i < value3.length; i++) { str3 += value3[i] + ',' } this.setData({ [constellation]: str.slice(0, str.length - 1), [workStatus]: str2.slice(0, str2.length - 1), [companyNature]: str3.slice(0, str3.length - 1) }) console.log(this.data.form) wx.request({ url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/standard', 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) { wx.redirectTo({ url: '/pages/index/index', }) } } }); } } }) }, showModal(error) { wx.showModal({ content: error.msg, showCancel: false, }) }, //验证函数 initValidate() { const rules = { ageMin: { required: true }, ageMax: { required: true }, heightMin: { required: true }, heightMax: { required: true }, education: { required: true }, income: { required: true }, nativePlace: { required: true }, marriage: { required: true }, assetHouse: { required: true }, // assetHouseArea: { // required: true // }, assetCar: { required: true }, // assetCarValue: { // required: true // }, constellation: { required: true }, workStatus: { required: true }, companyNature: { required: true }, parentAssets: { required: true }, composition: { required: true }, isCommon: { required: true } } const messages = { ageMin: { required: '请输入您能接受的最小年纪呦' }, ageMax: { required: '请输入您能接受的最大年纪呦' }, heightMin: { required: '请输入您能接受的最低身高呦' }, heightMax: { required: '请输入您能接受的最高身高呦' }, education: { required: '请输入您能接受的教育程度呦' }, income: { required: '请选择您能接受的收入呦' }, nativePlace: { required: '请选择本地或者外地呦' }, marriage: { required: '请选择您能接受的婚姻状态呦' }, assetHouse: { required: '请选择您可以接受的房子状态呦' }, // assetHouseArea: { // required: '请选择您可以接受的房子面积呦' // }, // assetHouseLoan: { // required: '请选择您可以接受的房子是否有贷款' // }, assetCar: { required: '请选择您可以接受的车子状态呦' }, // assetCarValue: { // required: '请选择您可以接受的车子价值呦' // }, // assetCarLoan: { // required: '请选择您是否可以接受的车子有贷款' // }, constellation: { required: '请选择您的优先选择星座呦' }, workStatus: { required: '请选择您能接受的工作状态呦' }, companyNature: { required: '请选择您能接受的单位性质呦' }, parentAssets: { required: '请选择您能接受的父母经济状态呦' }, composition: { required: '请选择您可以接受的家庭构成呦' }, isCommon: { required: '请选择您是否接受与父母同住呦' } } this.WxValidate = new WxValidate(rules, messages) }, async onLoad(options) { // tool.formDetails('he_composition_agree').then(result => { // console.log(result) // }) this.initValidate() tool.openidStatus().then(result => { this.setData({ openid: result[0], sessionkey: result[1] }) // this.getForm(); this.getInfos(); }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })