Page({
data: {
array:[],
index: 0,
index1: 0,
//部門
dept:0,
//崗位
post:0,
//點擊修改的時候要傳進去的對象
uId:0
},
//點擊所屬部門的時候觸發的事件
bindPickerChange: function (e) {
console.log('picker發送選擇改變,攜帶值爲', e.detail.value)
// console.log(e.detail.value),
console.log(this.data.uId)
this.setData({
index: e.detail.value,
//同時設置更改後的部門的id
dept: e.detail.value
})
// console.log("收到部門信息")
},
//點擊所屬崗位的時候出發的事件
bindPickerChange1: function (e) {
console.log('picker發送選擇改變,攜帶值爲', e.detail.value)
this.setData({
index1: e.detail.value,
//同時設置更改後的崗位的id
post: e.detail.value
})
},
//點擊修改按鈕的時候出發的事件
modify: function (e) {
//將數據庫中user對應的字段的部門id和崗位id進行修改
console.log("返回數據庫"+this.data.uId+" ,"+this.data.dept+" ,"+this.data.post)
//將要修改的參數定義好
var that = this
var u_id = that.data.uId
var group_id = that.data.dept
var u_type = that.data.post
console.log("請求的參數"+u_id+","+group_id+","+u_type)
//發送ajax請求到服務器修改u_id所對應的部門id和崗位id
wx:wx.request({
url: 'http://localhost:8080/Weixinapp/user/updateByUid.do',
data: {
u_id:u_id,
group_id:group_id,
u_type:u_type
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默認值
},
method: 'POST',
dataType: 'json',
responseType: 'text',
success: function(res) {
console.log("成功")
wx:wx.redirectTo({
url: '../user',
})
},
fail: function(res) {
wx.showToast({
title: '服務器網絡錯誤,請稍後重試',
icon: 'loading',
duration: 1500
})
},
complete: function(res) {
},
})
},
//點擊取消的時候觸發的事件
cancel: function () {
// console.log("取消")
//點擊取消時返回上一級目錄
wx.navigateBack({
delta:1
})
},
//頁面也加載的時候就接收到上一級傳過來的參數併發送請求到數據庫中查詢對應的信息渲染到頁面上
onLoad: function (options) {
var that = this
//收到u_id
// console.log(options)
var u_id = options.u_id
this.uId = options.u_id
// console.log("收到了詳細信息"+u_id)
//發送ajax請求查詢u_id對應的用戶的信息
wx:wx.request({
url: 'http://localhost:8080/Weixinapp/user/findUserByUid.do',
data: {
u_id:u_id
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默認值
},
method: 'POST',
dataType: 'json',
responseType: 'text',
success: function(res) {
console.log(res.data)
console.log(res.data.users)
console.log(res.data.groups)
// console.log(res.data.users[8])
that.setData({
title: res.data.users,
array: res.data.groups,
array1: res.data.posts,
index: res.data.users.group_id,
index1: res.data.users.u_type,
// 設置修改的時候傳過去的uId
uId: res.data.users.u_id
})
},
fail: function(res) {
wx.showToast({
title: '服務器網絡錯誤,請稍後重試',
icon: 'loading',
duration: 1500
})
},
complete: function(res) {
},
})
},