123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- var app = getApp();
- var that;
- Page({
- data: {
- userList: [],
- all_rule_list: [],
- rule_tree: [],
- terr: [{
- name: '全公司',
- id: 0
- }],
- searchUser: [], //搜索
- searchName: '',
- isItem: true, //是否为搜索的值
- isAllChecked: false,
- isAllChecked2: false,
- dept_id: 0,
- minuteIndex: 0, //条件选择
- minuteArray: [{
- id: 0,
- name: '全部人员'
- },
- {
- id: 1,
- name: '已开启'
- },
- {
- id: 2,
- name: '已禁用'
- }
- ],
- },
- onLoad() {
- that = this;
- dd.setNavigationBar({
- title: "组织架构"
- });
- this.setData({
- terr: [{
- name: '全公司',
- id: 0
- }],
- })
- this.getMessage();
- this.getBmData();
- this.getUserData(0);
- },
- //选择积分分类
- bingIntegralType(e) {
- this.setData({
- minuteIndex: e.detail.value,
- });
- },
- radioChange(e) {
- var list = this.data.isItem ? this.data.userList : this.data.searchUser;
- let id = e.target.dataset.id;
- list.map(item => {
- if (item.id == id) {
- item.isChecked = e.detail.value;
- }
- })
- },
- //全选择
- ruleActiveAll(e) {
- var list = this.data.isItem ? this.data.userList : this.data.searchUser;
- if (e.detail.value) {
- list.map(item => {
- if (item.is_creator != 1) {
- if (this.data.minuteIndex == 1) {
- if (item.is_official == 1) {
- item.isChecked = true;
- }
- } else {
- item.isChecked = true;
- }
- }
- })
- } else {
- list.map(item => {
- if (item.is_creator != 1) {
- if (this.data.minuteIndex == 1) {
- if (item.is_official == 1) {
- item.isChecked = false;
- }
- } else {
- item.isChecked = false;
- }
- }
- })
- }
- if (this.data.isItem) {
- this.setData({
- userList: list,
- isAllChecked: e.detail.value
- })
- } else {
- this.setData({
- searchUser: list,
- isAllChecked2: e.detail.value
- })
- }
- },
- // 开启||禁用
- onOpen(e) {
- var index = e.target.dataset.index;
- let employeeId = [];
- var list = this.data.isItem ? this.data.userList : this.data.searchUser;
- list.map(item => {
- if (item.isChecked) {
- if (this.data.minuteIndex == 1) {
- if (item.is_official == 1) {
- employeeId.push(item.id)
- }
- } else {
- employeeId.push(item.id)
- }
- }
- })
- if (employeeId.length == 0) {
- app.globalData.showToast("请选择一名员工")
- return;
- }
- let url = index == 1 ? 'api/employee/disable' : 'api/employee/enable'
- app.$post(url, {
- employee_id: JSON.stringify(employeeId)
- }).then((res) => {
- app.globalData.showToast("设置成功")
- if (this.data.isItem) {
- this.getUserData(this.data.dept_id);
- } else {
- let data = {
- detail: {
- value: this.data.searchName
- }
- }
- this.bindKeyInput(data);
- }
- })
- },
- tbDd() {
- // dd.navigateTo({
- // url: '../tb/tb'
- // })
- // return false;
- dd.confirm({
- title: '温馨提示',
- content: '即将同步钉钉通讯录的人员名单,确定同步吗',
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- success: (result) => {
- if (result.confirm) {
- var http1 = app.$post("api/ding/employee_sync", {});
- Promise.all([http1]).then((item) => {
- app.globalData.showToast(item[0].data.msg);
- })
- }
- },
- });
- },
- onReset() {
- this.setData({
- searchUser: [],
- isItem: true,
- isVal: false
- })
- },
- bindKeyInput(e) {
- app.$get("api/employee/index", {
- dept_id: 0
- }).then((res) => {
- var list = res.data.data.list;
- list.forEach(item => {
- item.isChecked = false
- if (item.id == app.globalData.userData.id) {
- item.is_creator = 1
- }
- })
- var items = list.filter((item) => {
- return item.name.indexOf(e.detail.value) >= 0
- });
- this.setData({
- searchUser: items,
- isItem: e.detail.value ? false : true,
- isVal: e.detail.value ? true : false,
- searchName: e.detail.value ? e.detail.value : '',
- isAllChecked2: false,
- })
- })
- },
- //点击导航栏
- 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,
- dept_id: 0
- })
- } else {
- var arr = terr.slice(0, index + 1);
- this.setData({
- rule_tree: item._child,
- terr: arr,
- dept_id: item.id
- })
- }
- this.getUserData(item.id);
- },
- //点击一级
- activeTree(e) {
- var item = e.target.dataset.item
- var terr = this.data.terr;
- terr.push(item)
- this.setData({
- rule_tree: item._child,
- terr: terr,
- dept_id: item.id
- });
- this.getUserData(item.id);
- },
- //获取部门列表
- getBmData() {
- app.$get("api/department/tree", {}).then((res) => {
- var list = res.data.data.list;
- this.setData({
- rule_tree: list,
- all_rule_list: list
- })
- })
- },
- //获取员工信息
- getUserData(dept_id) {
- this.setData({
- userList: []
- })
- app.$get("api/employee/index", {
- dept_id: dept_id
- }).then((res) => {
- var list = res.data.data.list;
- list.forEach(item => {
- item.isChecked = false
- if (item.id == app.globalData.userData.id) {
- item.is_creator = 1
- }
- })
- this.setData({
- isAllChecked: false,
- userList: list
- })
- })
- },
- getMessage() {
- app.$get("api/site/info").then((res) => {
- this.setData({
- gsData: res.data.data
- })
- })
- }
- });
|