const app = getApp(); Page({ data: { multiArray: [], // 地址-数据 step: 0, // 地址 multiIndex: [0, 0, 0], // 地址-下标 CityRecord: '', //城市记录 areaRecord: '', //区域记录 CityRecordid: [], //下标记录 UsedRecord: false, //是否初次 provincename: '', // 省 cityname: '', // 市 areaname: '', // 区 Ageid: 0, AgeArray: [], // 年龄-数据 AgeIndex: [0, 0], // 年龄-下标 heightid: 0, heightArray: [], // 身高-数据 heightindex: [0, 0], // 身高-下标 EducationArray: [], // 学历-数据 Educationindex: '', // 学历-下标 MarriageArray: [], // 婚史-数据 Marriageindex: '', // 婚史-下标 incomeid: 0, incomeArray: [], // 收入-数据 incomeindex: [0, 0], // 收入-下标 inputValue: '', // id province: '', // 市 city: '', // 市 area: '', // 区 age: '', // 年龄 height: '', // 身高 marry: '', // 婚史 education: '', // 学历 income: 0, // 收入 }, onLoad: function (option) { var that = this getApp().showLoading(); //提示加载中 //先清空要传的数据 app.globalData.Selection = 0; // 是否选中 app.globalData.age = 0; // 年龄 app.globalData.height = 0; // 身高 app.globalData.marry = 0 // 婚史 app.globalData.education = 0 // 学历 app.globalData.income = 0; // 收入 console.log(option) var _province = option.province // 省 var _city = option.city // 市 var _area = option.area // 区 var _provincename = option.provincename // 省 var _cityname = option.cityname // 市 var _areaname = option.areaname // 区 // console.log(_province) // console.log(_city) // console.log(_area) that.setData({ province: _province, city: _city, area: _area, provincename: _provincename, // 省 cityname: _cityname , // 市 areaname: _areaname , // 区 }) // // 获取区域ID // var _openid = 0; // try { // var value = wx.getStorageSync('openid'); // if (value) { // _openid = value // that.setData({ // openid: _openid // }) // } // console.log(_openid); // } catch (e) { // // Do something when catch error // } // 年龄 ajax let Age_url = 'public/paramsgather?type=age'; let Age_data = { // pid: '0' }; var _age = option.age // 年龄 var agenewArry = _age.split("-"); //转成数组 var _age_min = agenewArry[0] var _age_max = agenewArry[1] // console.log(_age_min) // console.log(_age_max) that.setData({ age: _age }) app.postRequest(Age_url, Age_data, function (res) { // 年龄 ajax if (res.code == 201) { for (let i = 0; i < res.data.length; i++) { //已选中的数据处理 if (res.data[i] == _age_min) { var _min = i; } if (res.data[i] == _age_max) { var _max = i; } that.setData({ AgeIndex: [_min, _max] }) } let dictObject = res.data; //对象不能直接使用 以下转成数组 // 对象转成数组 var createArr = [] for (let i in dictObject) { createArr.push(dictObject[i] + "岁"); } that.setData({ AgeArray: [createArr, createArr], }) // console.log(createArr); } }) // 身高 ajax let height_url = 'public/paramsgather?type=height'; let height_data = { pid: '0' }; var _height = option.height // 身高 var heightnewArry = _height.split("-"); //转成数组 var heightSmall = heightnewArry[0] var heightlarge = heightnewArry[1] // console.log(heightSmall) // console.log(heightlarge) that.setData({ height: _height }) app.postRequest(height_url, height_data, function (res) { // 身高 ajax if (res.code == 201) { for (let i = 0; i < res.data.length; i++) { //已选中的数据处理 // console.log(res.data[i]) if (res.data[i] == heightSmall) { var _min = i; } if (res.data[i] == heightlarge) { var _max = i; } that.setData({ heightindex: [_min, _max] }) } let dictObject = res.data; //对象不能直接使用 以下转成数组 // 对象转成数组 var createArr = [] for (let i in dictObject) { createArr.push(dictObject[i] + "cm"); } that.setData({ heightArray: [createArr, createArr], }) } }) // 婚史 ajax let Marriage_url = 'public/paramsgather?type=marriage'; let Marriage_data = { pid: '0' }; var _marry = option.marry // 婚史 // console.log(_marry) that.setData({ marry: _marry }) app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax if (res.code == 201) { // console.log(res.data); for (let i = 0; i < res.data.length; i++) { //已选中的数据处理 if (i == _marry) { that.setData({ Marriageindex: i, }) } } that.setData({ MarriageArray: res.data }) } }) // 学历 ajax let Education_url = 'public/paramsgather?type=xueli'; let Education_data = { // pid: '0' }; var _education = option.education // 学历 // console.log(_education) that.setData({ education: _education }) app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax if (res.code == 201) { // console.log(res.data); for (let i = 0; i < res.data.length; i++) { //已选中的数据处理 if (res.data[i].id == _education) { that.setData({ Educationindex: i, }) } } that.setData({ EducationArray: res.data }) } }) // 收入 ajax let income_url = 'public/paramsgather?type=shouru'; let income_data = { // pid: '0' }; var _income = option.income // 身高 var incomenewArry = _income.split("-"); //转成数组 var incomemin = incomenewArry[0] var incomemax = incomenewArry[1] // console.log(incomemin) // console.log(heightlarge) that.setData({ income: _income }) app.postRequest(income_url, income_data, function (res) { // 收入 ajax if (res.code == 201) { for (let i = 0; i < res.data.length; i++) { //已选中的数据处理 // console.log(res.data[i]) if (res.data[i].min == incomemin) { var _min = i; } if (res.data[i].max == incomemax) { var _max = i; } that.setData({ incomeindex: [_min, _max] }) } let dictObject = res.data; //对象不能直接使用 以下转成数组 // 对象转成数组 var createArr = [] var createArr1 = [] for (let i in dictObject) { createArr.push(dictObject[i].min); createArr1.push(dictObject[i].max); } that.setData({ incomeArray: [createArr, createArr1], }) } }) // 允许有意者联系我 ajax // let contact_url = 'public/citypid'; // let contact_data = { // pid: '0' // }; // app.postRequest(contact_url, contact_data, function (res) { // 允许有意者联系我 ajax // // console.log(res); // that.setData({ // contactArray: res.data // }) // }) this.getProvince(); //地址 ajax }, // 年龄双选 AgeEvent: function (e) { // console.log('picker发送选择改变,携带值为', e.detail.value) var Small = this.data.AgeArray[0][e.detail.value[0]].substring(0, 2); var large = this.data.AgeArray[1][e.detail.value[1]].substring(0, 2); var Agedata = Small + '-' + large; // console.log(Agedata); this.setData({ AgeIndex: e.detail.value, age: Agedata, Ageid: 1, }) }, heightEvent: function (e) { // 身高 // console.log(this); // console.log(e); // console.log(this.data.heightArray[e.detail.value]); // console.log('picker发送选择改变,携带值为', e.detail.value) var heightSmall = this.data.heightArray[0][e.detail.value[0]].substring(0, 3); var heightlarge = this.data.heightArray[1][e.detail.value[1]].substring(0, 3); var heightdata = heightSmall + '-' + heightlarge; this.setData({ heightindex: e.detail.value, height: heightdata, heightid: 1, }) }, MarriageEvent: function (e) { // 婚史 单项选择器 // console.log(this); // console.log(e); // console.log(this.data.MarriageArray[e.detail.value]); // console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ Marriageindex: e.detail.value, marry: e.detail.value }) }, EducationEvent: function (e) { // 学历 单项选择器 // console.log(this); // console.log(e); // console.log(this.data.EducationArray[e.detail.value].id); // console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ Educationindex: e.detail.value, education: this.data.EducationArray[e.detail.value].id }) }, incomeEvent: function (e) { // 收入 单项选择器 // console.log(this); // console.log(e); // console.log(this.data.incomeArray[e.detail.value].id); // console.log('picker发送选择改变,携带值为', e.detail.value) var srSmall = this.data.incomeArray[0][e.detail.value[0]]; var srlarge = this.data.incomeArray[1][e.detail.value[1]]; var srdata = srSmall + '-' + srlarge; // console.log(srdata); this.setData({ incomeindex: e.detail.value, income: srdata, incomeid: 1, }) }, // contactEvent: function (e) { // 允许有意者联系我 单项选择器 // // console.log(this.data.selectArray[e.detail.value].area_name) // // console.log('picker发送选择改变,携带值为', e.detail.value) // console.log(this); // console.log(e); // console.log(this.data.contactArray[e.detail.value]); // console.log('picker发送选择改变,携带值为', e.detail.value) // this.setData({ // contactindex: e.detail.value // }) // }, getProvince() { // 多项选择器 let _this = this; let d_url = 'public/citypid'; app.postRequest(d_url, { pid: '0' }, function (res) { if (res.code == '201') { var provinceList = res.data; var provinceArr = []; provinceArr = _this.mapArray(res.data); _this.setData({ multiArray: [provinceArr, [], []], provinceList, provinceArr, }) // console.log(provinceList); // console.log(provinceArr); // console.log(_this.data.CityRecord) // 方便取消事件调用 getProvince 判断 如果选择过城市 传选择过的城市 if (_this.data.CityRecord){ // console.log('有'); var defaultCode = _this.data.CityRecord if (defaultCode) { _this.setData({ currnetProvinceKey: defaultCode }) _this.getCity(defaultCode) } }else{ //如果没有选择过 , 传第一个城市 // console.log('无'); var defaultCode = provinceList[0]['area_id'] if (defaultCode) { _this.setData({ currnetProvinceKey: defaultCode }) _this.getCity(defaultCode) } } } }) }, getCity(codes) { // 多项选择 let _this = this; let d_url = 'public/citypid'; app.postRequest(d_url, { pid: codes }, function (res) { var cityList = res.data; var cityArr = []; if (res.code == '201') { cityArr = _this.mapArray(res.data); _this.setData({ multiArray: [_this.data.provinceArr, cityArr, []], cityArr, cityList }) // 方便取消事件调用 getProvince 判断 如果选择过城市 传选择过的城市 if (_this.data.areaRecord && _this.data.cancelID == false) { // console.log('有'); var defaultCode = _this.data.areaRecord // console.log(_this.data.areaRecord); if (defaultCode) { _this.setData({ currnetProvinceKey: defaultCode }) _this.getArea(defaultCode) } } else { //如果没有选择过 , 传第一个城市 // console.log('无'); var defaultCode = cityList[0]['area_id'] // console.log(defaultCode); if (defaultCode) { _this.setData({ currnetProvinceKey: defaultCode }) _this.getArea(defaultCode) } } } }) }, getArea(codes) { // 多项选择 let _this = this; let d_url = 'public/citypid'; app.postRequest(d_url, { pid: codes }, function (res) { var areaList = res.data; var areaArr = []; if (res.code == '201') { areaArr = _this.mapArray(res.data); } // console.log(areaList); // console.log(areaArr); _this.setData({ multiArray: [_this.data.provinceArr, _this.data.cityArr, areaArr], areaList, areaArr, }) _this.setData({ cancelID: true, }) }) }, mapArray: function (data) { let cityArray = [] if (data) { for (let i = 0; i < data.length; i++) { if (data[i].area_name) { cityArray[i] = data[i].area_name; } } } return cityArray; }, columnchange(e) { // 滚动选择器 触发的事件 var column = e.detail.column // 当前改变的列 // console.log(column); // console.log(this.data.multiIndex); // console.log(JSON.parse(JSON.stringify(this.data.multiIndex))); var data = { multiIndex: this.data.multiIndex, multiArray: this.data.multiArray } data.multiIndex[column] = e.detail.value; // 第几列改变了就是对应multiIndex的第几个,更新它 switch (column) { // 处理不同的逻辑 case 0: // 第一列更改 就是省级的更改 var currentProvinceKey = this.data.provinceList[e.detail.value].area_id if (currentProvinceKey != this.data.currnetProvinceKey) { // 判断当前的key是不是真正的更新了 this.getCity(currentProvinceKey) // 获取当前key下面的市级数据 } data.multiIndex[1] = 0 // 将市默认选择第一个 break; case 1: // 市发生变化 var currentCitykey = this.data.cityList[e.detail.value].area_id if (currentCitykey != this.data.currnetCityKey) { // 同样判断 this.getArea(currentCitykey) // 获取门店 } data.multiIndex[2] = 0 break; } this.setData(data) // 更新数据 // console.log(this.data.step) }, pickchange(e) { // console.log(this.data.multiIndex); // console.log(this.data.provinceList[e.detail.value[0]].area_id); // console.log(this.data.cityList[e.detail.value[1]].area_id); // console.log(this.data.areaList[e.detail.value[2]].area_id); this.setData({ step: 1, // 更新,用来选择用户选中的门店 multiIndex: e.detail.value, // 更新下标字段 province: this.data.provinceList[e.detail.value[0]].area_id, // 市 city: this.data.cityList[e.detail.value[1]].area_id, // 市 area: this.data.areaList[e.detail.value[2]].area_id, // 区 provincename: this.data.provinceList[e.detail.value[0]].area_name, // 市 cityname: this.data.cityList[e.detail.value[1]].area_name, // 市 areaname: this.data.areaList[e.detail.value[2]].area_name, // 区 CityRecord: this.data.provinceList[e.detail.value[0]].area_id, // 省 areaRecord: this.data.cityList[e.detail.value[1]].area_id, // 市 CityRecordid:this.data.multiIndex, UsedRecord:true, //已使用过 }) }, // 城市取消 cancel: function (e) { var _this = this; if (_this.data.UsedRecord == true){ _this.setData({ multiIndex: _this.data.CityRecordid, cancelID: false }) // console.log(_this.data.CityRecordid); _this.getProvince(); //地址 ajax } }, // 会员编码 getPhone: function (e) { var nickname = e.detail.value; // console.log(nickname); this.setData({ nickname: nickname }); }, //下一步事件 register: function (e) { // console.log(this.data.photo); // 头像 // console.log(this.data.sex); // 性别 // console.log(this.data.nickname); // 名字 // console.log(this.data.age); // 年龄 // console.log(this.data.height); // 身高 // console.log(this.data.province); // 区域 -市-县 // console.log(this.data.city); // 区域 -市-县 // console.log(this.data.area); // 区域 -市-县 // console.log(this.data.education); // 学历 // console.log(this.data.marry); // 婚史 // console.log(this.data.income); // 收入 // if (this.data.photo != ''){ // console.log(1); // } // var photo = this.data.photo //头像 // var sex = this.data.sex // 性别 var nickname = this.data.nickname //姓名 var age = this.data.age // 年龄 var height = this.data.height // 身高 var education = this.data.education // 学历 var marry = this.data.marry // 婚史 var income = this.data.income // 收入 var province = this.data.province // 市 var city = this.data.city // 市 var area = this.data.area // 区 var provincename = this.data.provincename // 市 var cityname = this.data.cityname // 市 var areaname = this.data.areaname // 区 // var occupation = this.data.occupation // 职业 //设置全局变量(app已经定义 var app=getApp()) 赋值要传的参数 app.globalData.age = age; // 年龄 app.globalData.height = height; // 身高 app.globalData.marry = marry // 婚史 app.globalData.education = education // 学历 app.globalData.income = income; // 收入 app.globalData.Selection = 1; // 是否选中 1 选中 0没选中 app.globalData.province = province; // 省 app.globalData.city = city; // 市 app.globalData.area = area; // 区 app.globalData.provincename = provincename; // 省 app.globalData.cityname = cityname; // 市 app.globalData.areaname = areaname; // 区 wx.switchTab({ url: '../index/index', }) // if (photo == '') { // var _photo = '请上传头像' // getApp().Tips(_photo) // } else if (nickname == '') { // var _nickname = '请填写姓名' // getApp().Tips(_nickname) // } else if (sex == '') { // var _sex = '请选择性别' // getApp().Tips(_sex) // } else if (age == '') { // var _age = '请选择年龄' // getApp().Tips(_age) // } else if (height == '') { // var _height = '请选择身高' // getApp().Tips(_height) // } else if (province == '' && city == '' && area == '') { // var _province = '请选择住址' // getApp().Tips(_province) // } else if (education == '') { // var _education = '请选择学历' // getApp().Tips(_education) // } else if (marry == '') { // var _marry = '请选择婚史' // getApp().Tips(_marry) // } else if (income == '') { // var _income = '请选择收入' // getApp().Tips(_income) // } else if (occupation == '') { // var _occupation = '请选择职业' // getApp().Tips(_occupation) // } else { // } }, // 重置 Reset: function (e) { var _this = this; _this.setData({ AgeIndex: ['', ''], // 年龄-下标 age: 0, // 年龄 Ageid: 0, heightindex: ['', ''], // 身高-下标 height: 0, //身高 heightid: 0, Marriageindex: '', // 婚史-下标 marry: 0, Educationindex: '', //学历 education: 0, //学历 incomeindex: ['', ''], //收入 income: 0, //收入 step: 0, // 地址 province: 0, // 市 city: 0, // 市 area: 0, // 区 provincename:'', // 省 cityname: '', // 市 areaname:'' , // 区 inputValue: '', //ID nickname: '',//ID }) // console.log(this.data.province); // 区域 -市-县 // console.log(this.data.city); // 区域 -市-县 // console.log(this.data.area); // 区域 -市-县 }, })