You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
4.5 KiB
JavaScript

// pages/group/group.js
import {
getTeamList,
saveTeam
} from '../../api/api'
import Dialog from 'tdesign-miniprogram/dialog/index';
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
groups: [],
groupName: '',
dialogKey: '',
showConfirm: false,
showWithInput: false,
select: {
page: 1,
size: 10,
isEnd: false
},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getData()
},
handleDelete(e) {
console.log(e.target.dataset.id)
console.log(e.target.dataset.num)
if (!e.target.dataset.num) {
const dialogConfig = {
context: this,
title: '确认删除该班组吗?',
content: '',
confirmBtn: '确定',
cancelBtn: '取消',
};
const that = this
Dialog.confirm(dialogConfig)
.then(() => {
saveTeam({
id: e.target.dataset.id,
state: 0
}).then(res => {
that.data.select = {
page: 1,
size: 10,
isEnd: false
}
that.data.groups = []
that.getData()
})
})
.catch(() => console.log('点击了取消'))
.finally(() => Dialog.close());
} else {
const dialogConfig = {
context: this,
content: '该班组下有人员绑定,请将人员解绑后再删除',
confirmBtn: "确定",
cancelBtn: null,
};
Dialog.confirm(dialogConfig)
.then(() => {})
.catch(() => console.log('点击了取消'))
.finally(() => Dialog.close());
}
},
showDialog(e) {
const {
key
} = e.currentTarget.dataset;
this.setData({
[key]: true,
dialogKey: key
});
},
closeDialog() {
const {
dialogKey
} = this.data;
this.setData({
[dialogKey]: false
});
},
handleChange(e) {
console.log(e.detail.value)
this.setData({
groupName: e.detail.value
})
},
edit() {
console.log(this.data.groupName)
if (!this.data.groupName) {
wx.showToast({
icon: 'none',
title: '请输入班组名称',
})
return
}
saveTeam({
jtTeamsName: this.data.groupName
}).then(res => {
wx.showToast({
icon: 'none',
title: '添加成功',
})
this.closeDialog()
this.data.select = {
page: 1,
size: 10,
isEnd: false
}
this.setData({
groupName: ''
})
this.data.groups = []
this.getData()
})
},
getData() {
if (this.data.select.isEnd) {
return
}
const param = {
pageNo: this.data.select.page
}
getTeamList(param).then(res => {
const arr = [...this.data.groups]
if (res.data && res.data.list && res.data.list.length > 0) {
this.data.select.page++
} else {
this.data.select.isEnd = true
}
const datas = arr.concat(res.data.list || [])
this.setData({
groups: datas
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
console.log(111)
this.getData()
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})