city-casereport/pages/censusDetail/censusDetail.js
2023-12-06 15:50:43 +08:00

117 lines
2.2 KiB
JavaScript

// pages/censusDetail/censusDetail.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
token: '',
id: '',
bean: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var _self = this;
wx.getStorage({
key: 'token',
success: function (res) {
_self.setData({
token: res.data,
id: options.id
})
//获取详情
_self.getDetailData();
}
})
let screenHeight = wx.getSystemInfoSync().windowHeight;
this.setData({
scrollHeight: screenHeight
})
},
//获取详情
getDetailData() {
var _self = this;
wx.showLoading({
title: '加载中...',
})
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/populationinfo/get/' + _self.data.id, [app.personUrl]), null, {
headers: {
token: _self.data.token
}
}, function (code, data) {
wx.hideLoading();
_self.setData({
bean: data
});
}, (code, error) => {
console.log(error);
wx.hideLoading();
wx.showToast({
title: '加载失败',
icon: 'error'
});
});
},
//编辑
doEdit() {
var _self = this;
wx.navigateTo({
url: '/pages/censusEdit/censusEdit?id=' + _self.data.id,
events: {
doNeedRefresh: (data) => {
_self.getDetailData();
}
}
})
},
//删除
doDel() {
var _self = this;
wx.showModal({
title: '提示',
content: '确定要删除该人员信息吗?',
complete: (res) => {
if (res.cancel) {
}
if (res.confirm) {
_self.doDelPerson();
}
}
})
},
//删除人员
doDelPerson() {
var _self = this;
wx.showLoading({
title: '删除中...',
})
app.restAjax.delete(app.restAjax.path('{url}app/populationinfo/remove/' + _self.data.id, [app.personUrl]), null, {
headers: {
token: _self.data.token
}
}, function (code, data) {
wx.hideLoading()
wx.showToast({
title: '删除成功',
icon: 'success',
success: () => {
const eventChannel = _self.getOpenerEventChannel()
eventChannel.emit('doNeedRefresh', { data: true });
wx.navigateBack()
}
})
}, function (code, data) {
wx.hideLoading()
wx.showToast({
title: '删除失败,请稍后重试',
icon: 'none'
})
});
}
})