123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- var app = getApp()
- var that;
- Component({
- mixins: [],
- data: {
- userList: [],//人员集合
- all_user_list: [],//人员集合
- isShow: false,
- showId: 0,//显示的部门ID下员工
- terr: [
- { name: '全部', id: 0 }
- ],
- all_rule_list: [],
- rule_tree: [],
- selectUserId: [],
- isAllChecked: false,
- isAll: true,
- userData: [],
- isCreator: false,
- creatorName: '',
- keyVal:'',
- },
- props: {
- onClose: (data) => console.log(data),
- onConfirm: (data) => console.log(data),
- selectUser: [],
- isAllSelect: true,//是否多选
- isLeadership: false,//数据源是否是自己的管理范围
- isBoss: false,//是否去除创始人
- isUser: false,//是否去除自己
- },
- didMount() {
- that = this;
- this.setData({ isCreator: app.globalData.isCreator, creatorName: app.globalData.corpMessage.creators })
- // app.login(app.globalData.corpId, function (is) {
- // if (is) {
- that.setData({
- selectUserId: that.props.selectUser[0] ? that.props.selectUser : [],
- isAll: that.props.isAllSelect,
- userData:app.globalData.userData.employee_detail.manage_scope,
- terr: [{ name: '全部', id: 0 }]
- })
- // }
- that.getData(0);
- that.getBmData();
- // })
- },
- didUpdate() { },
- didUnmount() {
- },
- methods: {
- onReset() {
- this.setData({
- isVal: false,
- keyVal:''
- })
- },
- onConfirm() {
- if (this.data.selectUserId.length == 0) {
- app.globalData.showToast("请选择一名员工")
- return
- }
- this.props.onConfirm(this.data.selectUserId);
- this.onClose();
- },
- //搜索
- bindKeyInput(e) {
- this.setData({
- keyVal:e.detail.value,
- isVal: e.detail.value ? true : false
- })
- },
- changeSection(e) {
- var item = e.target.dataset.item;
- var terr = this.data.terr;
- terr.push(item);
- if (item._child.length > 0) {
- that.setData({
- rule_tree: item._child,
- terr: terr,
- isAllChecked: false
- })
- } else {
- that.setData({
- rule_tree: [],
- terr: terr,
- isAllChecked: false
- })
- }
- this.getData(item.id);
- },
- //点击导航栏
- activeItem(e) {
- var item = e.target.dataset.item;
- var index = e.target.dataset.index;
- var terr = this.data.terr;
- if ((index + 1) == terr.length) { return false };
- this.setData({ rule_tree: [] });
- if (index == 0) {
- this.setData({
- terr: [{ name: '全部', id: 0 }],
- rule_tree: this.data.all_rule_list,
- isAllChecked: false
- })
- } else {
- var arr = terr.slice(0, index + 1);
- this.setData({
- rule_tree: item._child,
- terr: arr,
- isAllChecked: false
- })
- }
- this.getData(item.id);
- },
- // 点击下一级
- openDown(e) {
- this.setData({ rule_tree: [] });
- var item = e.target.dataset.item;
- var terr = this.data.terr;
- terr.push(item);
- if (item._child.length > 0) {
- that.setData({
- rule_tree: item._child,
- terr: terr,
- isAllChecked: false
- })
- }
- this.getData(item.id);
- },
- getArrDifference(arr1, arr2) {
- var obj = {};
- arr1.concat(arr2).forEach(function (v, i, arr) {
- obj[v.id] = v;
- });
- return obj;
- },
- //全选择
- ruleActiveAll(e) {
- var userList = this.data.userList;
- var selectUserId = this.data.selectUserId;
- if (e.detail.value) {
- userList.map(item => {
- item.checked = true;
- })
- if (selectUserId.length > 0) {
- var obj = this.getArrDifference(selectUserId, userList);
- this.setData({
- selectUserId: Object.values(obj),
- userList: userList,
- isAllChecked: true
- })
- } else {
- this.setData({
- selectUserId: userList,
- userList: userList,
- isAllChecked: true
- })
- }
- } else {
- userList.map(item => {
- item.checked = false;
- })
- this.setData({
- userList: userList,
- selectUserId: [],
- isAllChecked: false
- })
- }
- },
- //选择
- radioChange: function (e) {
- var selectUserId = this.data.selectUserId;
- var isExist = false;
- var userList = this.data.userList;
- if (!this.data.isAll) {//单选择
- let item = e.target.dataset.item;
- let index = e.target.dataset.index;
- let checked = `userList[${index}].checked`;//获取当前控制选中的字段
- let elm = this.data.userList[index].checked;//当前的状态
- //将所有的选中状态改成未中
- var userList = this.data.userList;
- userList.map((item, item_index) => {
- if (item.checked) {
- var item_checked = `userList[${item_index}].checked`;
- this.setData({
- [item_checked]: false
- })
- }
- })
- if(!elm){
- selectUserId.forEach((element, _this) => {
- if (element.id == item.id) {
- isExist = true;
- }
- });
- if (!isExist) {
- selectUserId=[];
- selectUserId.push(item);
- }
- }else{//取消选中
- selectUserId=[];
- }
- this.setData({
- [checked]: !elm,
- })
- } else {//多选择
- let item = e.target.dataset.item;
- let index = e.target.dataset.index;
- let checked = `userList[${index}].checked`;//获取当前控制选中的字段
- let elm = this.data.userList[index].checked;//当前的状态
- this.setData({
- [checked]: !elm,
- })
- if (e.detail.value) {//当有值时选中
- selectUserId.forEach((element, _this) => {
- if (element.id == item.id) {
- isExist = true;
- }
- });
- if (!isExist) {
- selectUserId.push(item);
- }
- } else {//取消选中
- selectUserId.forEach((element, index, _this) => {
- if (element.id == item.id) {
- _this.splice(index, 1);
- }
- });
- }
- }
- this.setData({
- selectUserId: selectUserId
- })
- },
- //关闭
- onClose(e) {
- this.props.onClose();
- },
- //获取人员列表
- getData(dept_id) {
- this.setData({
- userList: [],
- all_user_list: []
- })
- app.$get("api/employee/list", { dept_id: dept_id }).then((res) => {
- var list = res.data.data.list || [];
- var selectUserId = this.data.selectUserId;
- var arr = [];
- var userList = [];
- list.forEach(item => {
- if(this.props.isBoss&&item.is_creator == 1){
- return null
- }else if(this.props.isUser&&item.id == app.globalData.userData.id){
- return null
- }else{
- userList.push(item)
- }
- });
- userList.map((item) => { //设置列表的选中状态
- item.checked = false;
- if (selectUserId.length > 0) {
- selectUserId.forEach(item2 => {
- if (item.id == item2.id) {
- item.checked = true;
- }
- })
- }
- })
- that.data.userData.map((item) => {//列表数据是否是自己的管理范围
- userList.map((item2) => {
- if (item.id == item2.id) {
- arr.push(item2);
- }
- })
- })
- this.setData({
- userList: that.props.isLeadership ? arr : userList,
- all_user_list: that.props.isLeadership ? arr : userList,
- })
- })
- },
- //获取部门列表
- getBmData() {
- app.$get("api/department/tree", {}).then((res) => {
- var list = res.data.data.list;
- this.setData({
- rule_tree: list,
- all_rule_list: list
- })
- })
- },
- },
- });
|