Files
bsmall/pages/shop_user/shop_user.js
2020-09-24 11:08:03 +08:00

112 lines
2.3 KiB
JavaScript
Executable File

const api = require("../../api/api")
const app = getApp()
Page({
data: {
page : 1,
userList: [],
count : 0,
meta : {},
isLogin : false
},
onLoad() {
my.showLoading();
},
// 页面显示
onShow() {
my.showNavigationBarLoading();
this.setData({
userList: []
})
this.getShopuser()
},
// 店员列表
getShopuser(){
api.request({
url : "users/userList",
header: {
"Authorization": app.globalData.token
},
data : {
page: this.data.page
}
}).then(res=>{
let atArr = this.data.userList,
newArr = []
newArr = atArr.concat(res.data)
this.setData({
userList: newArr,
meta : res.meta,
count : res.count,
isLogin : false
})
my.hideLoading();
my.hideNavigationBarLoading();
})
},
// 删除店员
removeUser(e){
let userList = this.data.userList,
userId = e.target.dataset.id,
userNmae = e.target.dataset.name
my.confirm({
title : '删除提示',
content : '确定删除员工"' + userNmae + '"吗?',
confirmButtonText: '删除',
cancelButtonText : '取消',
success : (result) => {
if(result.confirm){
my.showLoading()
this.setData({
userList: []
})
api.request({
url : "users/userDel",
header: {
"Authorization": app.globalData.token
},
method: "POST",
data : {
user_id: userId
}
}).then(res=>{
my.showToast({
content: res.data,
type : "success"
});
this.getShopuser()
}).catch(err=>{
my.showToast({
content: "删除失败,请稍后重试",
type : "none"
});
my.hideLoading()
})
}
},
})
},
// 分页
onReachBottom(){
let meta = this.data.meta,
atPage = this.data.page
this.setData({
isLogin: true
})
if(meta.current_page < meta.last_page){
this.setData({
page: atPage + 1
})
this.getShopuser()
}
}
});