123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- import { $wuxToast } from '../../dist/index'
- import { $wuxSelect } from '../../dist/index';
- const app = getApp()
- Page({
- data: {
- motto: 'Hello World',
- userInfo: {},
- hasUserInfo: false,
- canIUse: wx.canIUse('button.open-type.getUserInfo'),
- openid: '',
- message: '',
- tel: '',
- name: '',
- upwd: '',
- id:'',
- utype:'',
- title2: '',
- value2: '',
- dlist: [],
- cids:[]
- },
- //事件处理函数
- bindViewTap: function() {
- wx.navigateTo({
- url: '../logs/logs'
- })
- },
-
- onLoad: function () {
- var that = this
- console.log("孙");
- console.log("-"+app.globalData.quanju);
-
- if (app.globalData.userInfo) {
- this.setData({
- userInfo: app.globalData.userInfo,
- hasUserInfo: true
- })
- } else if (this.data.canIUse){
- // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
- // 所以此处加入 callback 以防止这种情况
- app.userInfoReadyCallback = res => {
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- }
- } else {
- // 在没有 open-type=getUserInfo 版本的兼容处理
- wx.getUserInfo({
- success: res => {
- app.globalData.userInfo = res.userInfo
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- }
- })
- }
- // 获取openid
- wx.login({
- success: function (res) {
- if (res.code) {
- wx.getUserInfo({
- success: function (res) {
- console.log("存在code")
- }
- });
- var appid = "wxc55158faad3e366a"
- var secret = "f38f654411e153673ff4a473f1ccefd0"
- var openid = ""
- var l = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
- wx.request({
- url: l,
- data: {},
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- // header: {}, // 设置请求的 header
- success: function (res) {
- var obj = {};
- obj.openid = res.data.openid;
- console.log("取得的openid==" + res.data.openid);
-
- that.setData({
- openid: obj.openid
- })
-
- obj.expires_in = Date.now() + res.data.expires_in;
- // console.log(obj);
- // wx.setStorageSync('user', obj);//存储openid
- }
- });
- } else {
- console.log('获取用户登录态失败!' + res.errMsg)
- }
- }
- });
-
-
- //获取登录用户的code
- // wx.login({
- // success(res){
- // if(res.code){
- // console.log("当前code存在")
- // //发送code
- // wx.request({
- // url: 'http://localhost:8080/sendOpenid',
- // data:{
- // code:res.code
- // }
- // })
- // }
- // else{
- // console.log('登录失败!' + res.errMsg)
- // }
- // }
- // })
-
-
- },
- getUserInfo: function(e) {
- console.log(e)
- console.log("---");
- app.globalData.userInfo = e.detail.userInfo
- this.setData({
- userInfo: e.detail.userInfo,
- hasUserInfo: true
- })
- },
- onChange(e) {
- let that = this;
- let id = e.currentTarget.id;
- let values = e.detail.value;
-
- if (id == 'tel') {
- that.setData({
- tel: values
- });
- }
- if (id == 'name') {
- that.setData({
- name: values
- });
- }
- if (id == 'upwd') {
- that.setData({
- upwd: values
- });
- }
-
- },
- saveUser: function () {
- let tel = this.data.tel;
- if (tel == null || tel == '') {
- this.showError('请输入电话');
- return;
- }
-
- let upwd = this.data.upwd;
- if (upwd == null || upwd == '') {
- this.showError('请输入密码');
- return;
- }
- let name = this.data.name;
- if (name == null || name == '') {
- this.showError('请输入姓名');
- return;
- }
- let value2 = this.data.value2;
- if (value2 == null || value2 == '') {
- wx.showModal({
- title: '提示',
- content: '请选择个人喜好',
- showCancel: false
- })
- return
- }
- let utype = this.data.utype;
- let id = app.globalData.openid;
- wx.request({
- url: app.data.resturl + '/updateuser.action',
- method: 'post',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data: {
- name: name,
- tel: tel,
- upwd: upwd,
- utype: value2,
- id: id
- },
- success: function (res) {
- let code = res.data.code;
- if (code == 200) {
- wx.navigateBack({
-
- })
- }
- }
- })
- },
- onClick2() {
- console.log(this.data.value2);
- $wuxSelect('#wux-select2').open({
- multiple: true,
- value: this.data.cids,
- options: this.data.dlist,
- onChange: (value, index, options) => {
- console.log('onChange', value, index, options)
- this.setData({
- value2: value,
- title2: index.map((n) => options[n].title),
- })
- },
- onConfirm: (value, index, options) => {
- console.log('onConfirm', value, index, options)
- this.setData({
- value2: value,
- title2: index.map((n) => options[n].title),
- })
- },
- })
- },
- showError: function (info) {
- $wuxToast().show({
- type: 'text',
- duration: 1500,
- color: '#fff',
- text: info
- })
- },
- onShow: function () {
- var that = this;
- this.getUserinfo();
- this.clist();
- },
-
- getUserinfo() {
- var that = this;
- let openid = app.globalData.openid;
- console.log("openid=" + openid);
- if (openid == '') {
- wx.redirectTo({
- url: '../../pages/login/login',
- })
- }
- wx.request({
- url: app.data.resturl + '/uinfo.action',
- method: 'post',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data: {
- uid: openid
- },
- success: function (res) {
- let uinfo = res.data.uinfo;
- that.setData({
- upwd: uinfo.upwd,
- name:uinfo.name,
- tel:uinfo.tel,
- utype: uinfo.utype,
- title2: uinfo.cname,
- value2: uinfo.utype,
- cids:uinfo.cids
- });
- }
- })
- },
- clist: function () {
- let that = this;
- wx.request({
- url: app.data.resturl + '/cateloglist.action',
- data: {
- },
- success: function (res) {
- console.log(res.data.dlist);
- that.setData({
- dlist: res.data.dlist
- })
- }
- })
- }
- })
|