123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872 |
- const app = getApp();
- Page({
- data: {
- // viewhiddenName:true,
- // selectArray: [], // 性别-数据
- // index: '', // 性别-下标、
- heightid:0,
- heightArray: [], // 身高-数据
- heightindex: [0, 0], // 身高-下标
- EducationArray: [], // 学历-数据
- Educationindex: '', // 学历-下标
- // MarriageArray: [], // 婚史-数据
- // Marriageindex: '', // 婚史-下标
- incomeid:0,
- incomeArray: [], // 收入-数据
- incomeindex: [0, 0], // 收入-下标
- OccupationArray: [], // 职业-数据
- Occupationindex: '', // 职业-下标
- // contactArray: [], // 允许有意者联系我-数据
- // contactindex: '', // 允许有意者联系我-下标
- multiArray: [], // 地址-数据
- step: 0, // 地址
- multiIndex: [0, 0, 0], // 地址-下标
- // sex: '', // 性别
- age: '', // 年龄
- height: '', // 身高
- province: '', // 省
- city: '', // 市
- area: '', // 区
- education: '', // 学历
- // marry: '', // 婚史
- income: '', // 收入
- occupation: '', // 职业
- Ageid:0,
- AgeArray: [], // 年龄-数据
- AgeIndex: [0, 0], // 年龄-下标
- },
- onLoad: function () {
- var that = this
-
- // 获取择偶信息
- // let personal_url = 'my/personaloption/optioninfo';
- // let personal_data = {
- // };
- // app.postRequest(personal_url, personal_data, function (res) {
- // if (res.code == 201) {
-
-
- // }
- // })
- // 默认择偶信息
- let editinfo_url = 'my/personaloption/editoption';
- let editinfo_data = {
- };
- app.postRequest(editinfo_url, editinfo_data, function (res) {
- that.setData({
- personal: res.data, //获取全部数据
- })
- // console.log(res.data)
- // 年龄 ajax
- let Age_url = 'public/paramsgather?type=age';
- let Age_data = {
- // pid: '0'
- };
- let _age_min = res.data.age_min == 0 ? '不限' : res.data.age_min;
- let _age_max = res.data.age_max == 0 ? '以上' : res.data.age_max;
- // console.log(_age_min);
- // console.log(_age_max);
- app.postRequest(Age_url, Age_data, function (res) { // 年龄 ajax
- if (res.code == 201) {
- let newarray = ['不限'];
- var res_data = newarray.concat(res.data); //在原有的数据上 凭借上 不限
- let newarray1 = ['以上'];
- var res_data1 = newarray1.concat(res.data); //在原有的数据上 凭借上 以上
- let min = data_processing(res_data, _age_min); //已选中的数据处理 min
- let max = data_processing(res_data1, _age_max); //已选中的数据处理 max
-
- that.setData({
- AgeIndex: [min, max]
- })
- let dictObject = res.data; //对象不能直接使用 以下转成数组
- // 对象转成数组
- var createArr = []
- for (let i in dictObject) {
- createArr.push(dictObject[i] + "岁"); //在数据后面凭借 岁
- }
- let bx = ['不限'];
- var Unlimited = bx.concat(createArr); //在原有的数据上 凭借上 不限
- let ys = ['以上'];
- var Above = ys.concat(createArr); //在原有的数据上 凭借上 以上
- that.setData({
- AgeArray: [Unlimited, Above],
- })
- // console.log(createArr);
- }
- })
- // 身高 ajax
- let height_url = 'public/paramsgather?type=height';
- let height_data = {
- pid: '0'
- };
- let _height_min = res.data.height_min == 0 ? '不限' : res.data.height_min;
- let _height_max = res.data.height_max == 0 ? '以上' : res.data.height_max;
- // console.log(_height_min)
- // console.log(_height_max)
- app.postRequest(height_url, height_data, function (res) { // 身高 ajax
- if (res.code == 201) {
-
- let newarray = ['不限'];
- var res_data = newarray.concat(res.data); //在原有的数据上 凭借上 不限
- let newarray1 = ['以上'];
- var res_data1 = newarray1.concat(res.data); //在原有的数据上 凭借上 以上
- let min = data_processing(res_data, _height_min); //已选中的数据处理 min
- let max = data_processing(res_data1, _height_max); //已选中的数据处理 max
-
- that.setData({
- heightindex: [min, max]
- })
-
- let dictObject = res.data; //对象不能直接使用 以下转成数组
- // 对象转成数组
- var createArr = []
- for (let i in dictObject) {
- createArr.push(dictObject[i] + "cm");
- }
- let bx = ['不限'];
- var Unlimited = bx.concat(createArr);
- let ys = ['以上'];
- var Above = ys.concat(createArr);
- // console.log(createArr);
- that.setData({
- heightArray: [Unlimited, Above],
- })
- }
- })
- // 学历 ajax
- let Education_url = 'public/paramsgather?type=xueli';
- let Education_data = {
- // pid: '0'
- };
- let _education = res.data.education;
- console.log(_education)
- app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax
- if (res.code == 201) {
-
- var obj = { id: 0, name: '不限' };
- var datares = res.data;
- datares.unshift(obj)
- for (let i = 0; i < datares.length; i++) { //已选中的数据处理
- if (datares[i].id == _education) {
- that.setData({
- Educationindex: i,
- })
- }
- }
- that.setData({
- EducationArray: datares,
-
- })
- // for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
- // if (res.data[i].id == _education) {
- // // console.log(res.data[i].id)
- // that.setData({
- // Educationindex: i
- // })
- // }
- // }
- // that.setData({
- // EducationArray: res.data
- // })
- }
- })
- // 婚史 ajax
- // let Marriage_url = 'public/paramsgather?type=marriage';
- // let Marriage_data = {
- // pid: '0'
- // };
-
- // app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax
- // if (res.code == 201) {
- // that.setData({
- // MarriageArray: res.data
- // })
- // }
- // })
- // 收入 ajax
- let income_url = 'public/paramsgather?type=shouru1';
- let income_data = {
- // pid: '0'
- };
- let _income_min = res.data.income_min == 0 ? '不限' : res.data.income_min;
- let _income_max = res.data.income_max == 0 ? '以上' : res.data.income_max;
- // console.log(_income_min);
- // console.log(_income_max);
- app.postRequest(income_url, income_data, function (res) { // 收入 ajax
- if (res.code == 201) {
-
- let newarray = ['不限'];
- var res_data = newarray.concat(res.data); //在原有的数据上 凭借上 不限
- let newarray1 = ['以上'];
- var res_data1 = newarray1.concat(res.data); //在原有的数据上 凭借上 以上
- var min = data_processing(res_data, _income_min); //已选中的数据处理 min
- var max = data_processing(res_data1, _income_max); //已选中的数据处理 max
- // console.log(min);
- // console.log(max);
- that.setData({
- incomeindex: [min, max]
- })
-
- that.setData({
- incomeArray: [res_data, res_data1],
- })
- }
- })
- // 职业 ajax
- let Occupation_url = 'public/paramsgather?type=zhiye';
- let Occupation_data = {
- // pid: '0'
- };
- let _occupation = res.data.occupation;
-
- app.postRequest(Occupation_url, Occupation_data, function (res) { // 职业 ajax
- if (res.code == 201) {
- // console.log(res);
- var obj = { id: 0, name: '不限' };
- var datares = res.data;
- datares.unshift(obj)
- for (let i = 0; i < datares.length; i++) { //已选中的数据处理
- if (datares[i].id == _occupation) {
- that.setData({
- Occupationindex: i,
- })
- }
- }
- that.setData({
- OccupationArray: datares,
- })
- }
- })
-
- if (res.code == 201) {
- var _age , _height , _income ;
- if (res.data.age_min == 0 && res.data.age_max == 0){
- _age = '';
- }else{
- _age = res.data.age_min + '-' + res.data.age_max
- }
- if (res.data.height_min == 0 && res.data.height_max == 0) {
- _height = '';
- }else{
- _height = res.data.height_min + '-' + res.data.height_max
- }
- if (res.data.income_min == 0 && res.data.income_max == 0) {
- _income = '';
- }else {
- _income = res.data.income_min + '-' + res.data.income_max
- }
- that.setData({
-
- // sex: res.data.sex, // 性别
- age: _age, // 年龄
- height: _height, // 身高
- province: res.data.province, // 市
- city: res.data.city, // 市
- area: res.data.area, // 区
- education: res.data.education, // 学历
- // marry: res.data.marry, // 婚史
- income: _income, // 收入
- occupation: res.data.occupation, // 职业
-
- // Marriageindex: res.data.marry, // 婚史
-
- personacodel: res, //获取全部数据
- })
- }
- that.getProvince(); //地址 ajax
- })
- // 性别 ajax
- // let p_url = 'public/paramsgather?type=sex';
- // let p_data = {
- // // pid: '0'
- // };
- // app.postRequest(p_url, p_data, function (res) { // 性别 ajax
- // if (res.code == 201) {
- // // console.log(res.data);
- // that.setData({
- // selectArray: res.data
- // })
- // }
- // })
- // 允许有意者联系我 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
- // })
- // })
- },
- // GenderEvent: function (e) { // 性别 单项选择器
- // // console.log(this);
- // // console.log(e);
- // // console.log(this.data.selectArray[e.detail.value]);
- // // console.log('picker发送选择改变,携带值为', e.detail.value)
- // this.setData({
- // index: e.detail.value,
- // sex: e.detail.value
- // })
- // },
- // 年龄双选
- AgeEvent: function (e) {
- var that =this;
- console.log('picker发送选择改变,携带值为', e.detail.value)
- var _value = 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);
- if (Small > large && Small != '不限' && large != '以上') { //判断 最小值 大于 最大值 数据互换
- // console.log('调换')
- var Agedata = large + '-' + Small;
- that.Exchange(_value); // 调用数组调换
- } else {
- var Agedata = Small + '-' + large; //否则正常选中
- }
- console.log(Agedata);
- this.setData({
- AgeIndex: _value,
- age: Agedata,
- Ageid: 1,
- })
- },
- heightEvent: function (e) { // 身高 单项选择器
- var that = this;
- // console.log(this);
- // console.log(e);
- // console.log(this.data.heightArray[e.detail.value]);
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- var _value = 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);
-
- // console.log(heightdata)
- if (heightSmall > heightlarge && heightSmall != '不限' && heightlarge != '以上') { //判断 最小值 大于 最大值 数据互换
- // console.log('调换')
- var heightdata = heightlarge + '-' + heightSmall;
- that.Exchange(_value); // 调用数组调换
- } else {
- var heightdata = heightSmall + '-' + heightlarge;
- }
- this.setData({
- heightindex: _value,
- height: heightdata,
- heightid: 1,
- })
- },
- 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
- })
- },
- // 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
- // })
- // },
- incomeEvent: function (e) { // 收入 单项选择器
- var that = this;
- // console.log(this);
- // console.log(e);
- // console.log(this.data.incomeArray[e.detail.value].id);
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- var _value = e.detail.value; //发送选择改变,携带值为
- var srSmall = this.data.incomeArray[0][e.detail.value[0]];
- var srlarge = this.data.incomeArray[1][e.detail.value[1]];
- if (srSmall > srlarge && srSmall != '不限' && srlarge != '以上') { //判断 最小值 大于 最大值 数据互换
- // console.log('调换')
- var srdata = srlarge + '-' + srSmall;
- that.Exchange(_value); // 调用数组调换
- } else {
- var srdata = srSmall + '-' + srlarge; //否则正常选中
- }
- // console.log(srdata);
- this.setData({
- incomeindex: _value,
- income: srdata,
- incomeid:1,
- })
- },
- OccupationEvent: function (e) { // 职业 单项选择器
- // console.log(this);
- // console.log(e);
- // console.log(this.data.OccupationArray[e.detail.value].id);
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- Occupationindex: e.detail.value,
- occupation: this.data.OccupationArray[e.detail.value].id
- })
- },
- // 数组数据调换
- Exchange: function (data) {
- for (var i = 0; i < data.length / 2; i++) {
- var data_i = data[i];
- data[i] = data[data.length - 1 - i];
- data[data.length - 1 - i] = data_i;
- }
- return;
- },
- // 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) {
- // console.log(res.data);
- 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);
- var defaultCode = provinceList[0]['area_id']
- // console.log(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
- })
- var defaultCode = cityList[0]['area_id']
- 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
- })
-
- })
- },
- 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) // 更新数据
- },
- pickchange(e) {
- // 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 // 区
- })
- },
- //下一步事件
- register: function (e) {
- var that =this ;
- var _age = transformation(that.data.age) //不限以上 转换成0
- var _height = transformation(that.data.height) //不限以上 转换成0
- var _income = transformation(that.data.income) //不限以上 转换成0
- console.log(_age);
- // console.log(this.data.age); // 年龄
- console.log(this.data.height); // 身高
- console.log(this.data.education); // 学历
- // console.log(this.data.marry); // 婚史
- console.log(this.data.income); // 收入
- console.log(this.data.province); // 省
- console.log(this.data.city); // 市
- console.log(this.data.area); // 区
- console.log(this.data.occupation); // 职业
- // let _Receive_img = that.data.Receive_news;
- // _Receive_img.push(obj); //合并历史消息对象
- var age = this.data.age // 年龄
- var height = this.data.height // 身高
- var province = this.data.province // 省
- var city = this.data.city // 市
- var area = this.data.area // 区
- var education = this.data.education // 学历
- // var marry = this.data.marry // 婚史
- var income = this.data.income // 收入
- var occupation = this.data.occupation // 职业
- // 修改择偶信息
- let editinfoform_url = 'my/personaloption/editoptionform';
- let editinfoform_data = {
- age: _age, // 年龄
- height: _height, // 身高
- province: this.data.province, // 市
- city: this.data.city, // 市
- area: this.data.area, // 区
- education: this.data.education, // 学历
- // marry: this.data.marry, // 婚史
- income: _income, // 收入
- occupation: this.data.occupation, // 职业
- };
-
- app.postRequest(editinfoform_url, editinfoform_data, function (res) {
- if (res.code == 201) {
- wx.showToast({
- title: '修改成功',
- icon: 'success',
- duration: 2000
- })
- return;
- }
- var fail = '修改失败' //调用提示框
- getApp().Tips(fail)
- })
- },
- // onReady: function () {
- // this.setData({
- // viewhiddenName:false
- // })
- // },
- })
- var data_processing = function (data, min_max, ) {
- for (let i = 0; i < data.length; i++) { //已选中的数据处理
- if (data[i] == min_max) {
- return i;
- }
- }
- }
- var transformation = function (resdata) {
- if (resdata) {
- let newArry = resdata.split("-"); //转成数组
- if (newArry[0] == '不限' || newArry[0] == undefined) {
- var _min = 0
- } else {
- var _min = newArry[0];
- }
- if (newArry[1] == '以上' || newArry[1] == undefined) {
- var _max = 0
- } else {
- var _max = newArry[1];
- }
- resdata = _min + '-' + _max
- }
- return resdata;
- }
|