let app = getApp() import { userProfile } from "../../../api/user/user.js" Page({ data: { sex: ['男', '女'], sexindex: 0, showDialog: false, ifName: true, DOMAIN_NAME: app.IMG_NAME, park: [], parkindex: 0 }, /** * 生命周期函数--监听页面加载 */ onShow(e) { var that = this that.setData({ DOMAIN_NAME: app.img_Name }) app.AjaxRequest('get', { 'content-type': 'application/json' }, '/park/list', {}, function (res) { if (res.code == 0) { res.data.forEach(item => { let park = that.data.park park.push(item.parkName) that.setData({ park }) }) that.setData({ parkList: res.data }) that.parkIdtype(res.data, wx.getStorageSync('parkId')) } }) that.getList() }, parkIdtype(list, id) { list.forEach((item, index) => { if (item.id == id) { this.setData({ parkindex: index }) } }) }, parkChange(e) { let that = this that.data.parkList.forEach(item => { if (that.data.park[e.detail.value] == item.parkName) { that.setData({ parkindex: e.detail.value }) wx.setStorageSync('parkId', item.id) wx.setStorageSync('parkName', item.parkName) } }) }, cancel() { this.setData({ ifName: true }) }, change(e) { this.setData({ name: e.currentTarget.dataset.name, ifName: false }) }, setValue(e) { if (this.data.name == '姓名') { this.setData({ nickname: e.detail.value }) } else { this.setData({ post: e.detail.value }) } }, confirm() { let that = this if (this.data.name == '姓名') { app.AjaxRequest('POST', { 'content-type': 'application/json', 'Authorization': 'Bearer ' + app.Getopenid() }, '/user/profile/update', { username: that.data.nickname }, function (ret) { that.setData({ ifName: true }) that.getList() }) } else { app.AjaxRequest('POST', { 'content-type': 'application/json', 'Authorization': 'Bearer ' + app.Getopenid() }, '/user/profile/update', { post: that.data.post }, function (ret) { that.setData({ ifName: true }) that.getList() }) } }, // 性别选择 sexChange: function (e) { let that = this that.setData({ sexindex: e.detail.value }) app.AjaxRequest('POST', { 'content-type': 'application/json', 'Authorization': 'Bearer ' + app.Getopenid() }, '/user/profile/update', { gender: JSON.parse(e.detail.value) }, function (ret) { that.getList() }) }, getList() { let that = this userProfile(wx.getStorageSync('userId')).then(res => { that.setData({ memberInfo: res.data, sexindex: res.data.gender }) }) }, chooseimage: function () { var that = this let imgUrl = that.data.imgUrl wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { console.log(res.tempFilePaths[0]) wx.navigateTo({ url: '../cropper/cropper?img=' + res.tempFilePaths[0], }) } }) }, navCropper() { this.chooseimage() }, exitaccount() { wx.showModal({ title: '提示', content: '确定退出账号吗', success(res) { if (res.confirm) { wx.clearStorageSync() wx.reLaunch({ url: '/pages/login/login', }) } else if (res.cancel) { console.log('用户点击取消') } } }) } })