123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- const app = getApp();
- Page({
- data: {
- // selectArray: [], // 性别-数据
- // index: '', // 性别-下标、
- AgeArray: [], // 年龄-数据
- Ageindex: '', // 年龄-下标
- heightArray: [], // 身高-数据
- heightindex: '', // 身高-下标
- EducationArray: [], // 学历-数据
- Educationindex: '', // 学历-下标
- MarriageArray: [], // 婚史-数据
- Marriageindex: '', // 婚史-下标
- incomeArray: [], // 收入-数据
- incomeindex: '', // 收入-下标
- OccupationArray: [], // 职业-数据
- Occupationindex: '', // 职业-下标
- // contactArray: [], // 允许有意者联系我-数据
- // contactindex: '', // 允许有意者联系我-下标
- multiArray: [], // 地址-数据
- step: 0, // 地址
- multiIndex: [0, 0, 0], // 地址-下标
- nickname: '', //姓名
- // sex: '', // 性别
- age: '', // 年龄
- height: '', // 身高
- province: '', // 市
- city: '', // 市
- area: '', // 区
- education: '', // 学历
- marry: '', // 婚史
- income: '', // 收入
- occupation: '', // 职业
- // openid:'', //授权
- personacodel:''
- },
- onLoad: function () {
- var that = this
- // 获取个人信息
- let personal_url = 'my/personaldata/personal';
- let personal_data = {
- };
- app.postRequest(personal_url, personal_data, function (res) {
- if (res.code == 201) {
-
- that.setData({
- personal: res.data, //获取全部数据
- })
- }
- })
- // 默认个人信息
- let editinfo_url = 'my/personaldata/editinfo';
- let editinfo_data = {
- };
- app.postRequest(editinfo_url, editinfo_data, function (res) {
- // 年龄 ajax
- let Age_url = 'public/paramsgather?type=age';
- let Age_data = {
- // pid: '0'
- };
- let _age = res.data.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) {
- that.setData({
- Ageindex: i,
- })
- }
- }
- let dictObject = res.data;
- // 对象转成数组
- var createArr = []
- for (let i in dictObject) {
- createArr.push(dictObject[i] + "岁");
- }
- // console.log(createArr);
- that.setData({
- AgeArray: createArr
- })
- }
- })
- // 身高 ajax
- let height_url = 'public/paramsgather?type=height';
- let height_data = {
- pid: '0'
- };
- let _height = res.data.height;
- app.postRequest(height_url, height_data, function (res) { // 身高 ajax
- if (res.code == 201) {
- for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
- if (res.data[i] == _height) {
- that.setData({
- heightindex: i,
- })
- }
- }
- let dictObject = res.data;
- // 对象转成数组
- var createArr = []
- for (let i in dictObject) {
- createArr.push(dictObject[i] + "cm");
- }
- // console.log(createArr);
- that.setData({
- heightArray: createArr
- })
- }
- })
- // 学历 ajax
- let Education_url = 'public/paramsgather?type=xueli';
- let Education_data = {
- // pid: '0'
- };
- let _education = res.data.education;
- app.postRequest(Education_url, Education_data, function (res) { // 学历 ajax
- if (res.code == 201) {
- 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 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) {
- for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
- if (res.data[i].id == _occupation) {
- that.setData({
- Occupationindex: i,
- })
- }
- }
-
- that.setData({
- OccupationArray: res.data
- })
- }
- })
- // 收入 ajax
- let income_url = 'public/paramsgather?type=shouru';
- let income_data = {
- // pid: '0'
- };
- let _income = res.data.income;
- app.postRequest(income_url, income_data, function (res) { // 收入 ajax
- if (res.code == 201) {
- for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
- if (res.data[i].id == _income) {
- that.setData({
- incomeindex: i,
- })
- }
- }
- that.setData({
- incomeArray: res.data
- })
- }
- })
- // 婚史 ajax
- let Marriage_url = 'public/paramsgather?type=marriage&marriage=1';
- let Marriage_data = {
- pid: '0'
- };
- let _marry = res.data.marry;
- app.postRequest(Marriage_url, Marriage_data, function (res) { // 婚史 ajax
- if (res.code == 201) {
- for (let i = 0; i < res.data.length; i++) { //已选中的数据处理
- if (res.data[i].id == _marry) {
- that.setData({
- Marriageindex: i,
- })
- }
- }
- // console.log(res.data);
- that.setData({
- MarriageArray: res.data
- })
- }
- })
- if (res.code == 201) {
- // console.log(res.data);
- that.setData({
- nickname: res.data.nickname, //姓名
- // sex: res.data.sex, // 性别
- age: res.data.age, // 年龄
- height: res.data.height, // 身高
- province: res.data.province, // 市
- city: res.data.city, // 市
- area: res.data.area, // 区
- education: res.data.education, // 学历
- marry: res.data.marry, // 婚史
- income: res.data.income, // 收入
- occupation: res.data.occupation, // 职业
- Marriageindex: res.data.marry, // 婚史
- personacodel: res, //获取code 前台判断
-
-
- })
- }
- that.getProvince(); //地址 ajax
- })
- },
- 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
- // })
- wx.showModal({
- title: '性别确定之后不可更改',
- content: '如需更改请联系管理员',
- showCancel: false,
- })
- },
- AgeEvent: function (e) { // 年龄 单项选择器
- // console.log(this);
- // console.log(e);
- // console.log(this.data.AgeArray[e.detail.value]);
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- Ageindex: e.detail.value,
- age: this.data.AgeArray[e.detail.value]
- })
- },
- heightEvent: function (e) { // 身高 单项选择器
- // console.log(this);
- // console.log(e);
- // console.log(this.data.heightArray[e.detail.value]);
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- heightindex: e.detail.value,
- height: this.data.heightArray[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
- })
- },
- MarriageEvent: function (e) { // 婚史 单项选择器
- // console.log(this);
- // console.log(e);
- console.log(this.data.MarriageArray[e.detail.value].id);
- // console.log(this.data.MarriageArray[e.detail.value]);
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- Marriageindex: e.detail.value,
- marry: this.data.MarriageArray[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)
- this.setData({
- incomeindex: e.detail.value,
- income: this.data.incomeArray[e.detail.value].id
- })
- },
- 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
- })
- },
- 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);
- 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 // 区
- })
- },
- // 名字
- getPhone: function (e) {
- var nickname = e.detail.value;
- // console.log(nickname);
- this.setData({
- nickname: nickname
- });
- },
- //下一步事件
- register: function (e) {
- // console.log(this.data.nickname); // 名字
- // console.log(this.data.sex); // 性别
- // 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); // 区
- // 修改个人信息
- let editinfoform_url = 'my/personaldata/editinfoform';
- let editinfoform_data = {
- nickname: this.data.nickname, //姓名
- age: this.data.age, // 年龄
- height: this.data.height, // 身高
- province: this.data.province, // 市
- city: this.data.city, // 市
- area: this.data.area, // 区
- education: this.data.education, // 学历
- marry: this.data.marry, // 婚史
- income: this.data.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 = res.data.nickname[0]; //调用提示框
- getApp().Tips(fail)
- })
- },
- })
|