organization.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. var app = getApp();
  2. var that;
  3. Page({
  4. data: {
  5. userList: [],
  6. all_rule_list: [],
  7. rule_tree: [],
  8. terr: [{
  9. name: '全公司',
  10. id: 0
  11. }],
  12. searchUser: [], //搜索
  13. searchName: '',
  14. isItem: true, //是否为搜索的值
  15. isAllChecked: false,
  16. isAllChecked2: false,
  17. dept_id: 0,
  18. minuteIndex: 0, //条件选择
  19. minuteArray: [{
  20. id: 0,
  21. name: '全部人员'
  22. },
  23. {
  24. id: 1,
  25. name: '已开启'
  26. },
  27. {
  28. id: 2,
  29. name: '已禁用'
  30. }
  31. ],
  32. isSuperAdministrator:false,
  33. },
  34. onLoad() {
  35. that = this;
  36. dd.setNavigationBar({
  37. title: "组织架构"
  38. });
  39. this.setData({
  40. isSuperAdministrator:app.globalData.isSuperAdministrator,
  41. terr: [{
  42. name: '全公司',
  43. id: 0
  44. }],
  45. })
  46. this.getMessage();
  47. this.getBmData();
  48. this.getUserData(0);
  49. },
  50. //选择积分分类
  51. bingIntegralType(e) {
  52. var list = this.data.isItem ? this.data.userList : this.data.searchUser;
  53. list.map(item => {
  54. item.isChecked = false;
  55. })
  56. if (this.data.isItem) {
  57. this.setData({
  58. userList: list,
  59. })
  60. } else {
  61. this.setData({
  62. searchUser: list,
  63. })
  64. }
  65. this.setData({
  66. minuteIndex: e.detail.value,
  67. isAllChecked:false
  68. });
  69. },
  70. radioChange(e) {
  71. var list = this.data.isItem ? this.data.userList : this.data.searchUser;
  72. let id = e.target.dataset.id;
  73. list.map(item => {
  74. if (item.id == id) {
  75. item.isChecked = e.detail.value;
  76. }
  77. })
  78. },
  79. //全选择
  80. ruleActiveAll(e) {
  81. var list = this.data.isItem ? this.data.userList : this.data.searchUser;
  82. if (e.detail.value) {
  83. list.map(item => {
  84. if (item.is_creator != 1) {
  85. if (this.data.minuteIndex == 1) {
  86. if (item.is_official == 1) {
  87. item.isChecked = true;
  88. }
  89. }else if(this.data.minuteIndex == 2) {
  90. if (item.is_official == 0) {
  91. item.isChecked = true;
  92. }
  93. }else{
  94. item.isChecked = true;
  95. }
  96. }
  97. })
  98. } else {
  99. list.map(item => {
  100. if (item.is_creator != 1) {
  101. if (this.data.minuteIndex == 1) {
  102. if (item.is_official == 1) {
  103. item.isChecked = false;
  104. }
  105. } else if(this.data.minuteIndex == 2) {
  106. if (item.is_official == 0) {
  107. item.isChecked = false;
  108. }
  109. }else{
  110. item.isChecked = false;
  111. }
  112. }
  113. })
  114. }
  115. if (this.data.isItem) {
  116. this.setData({
  117. userList: list,
  118. isAllChecked: e.detail.value
  119. })
  120. } else {
  121. this.setData({
  122. searchUser: list,
  123. isAllChecked2: e.detail.value
  124. })
  125. }
  126. },
  127. // 开启||禁用
  128. onOpen(e) {
  129. var index = e.target.dataset.index;
  130. let employeeId = [];
  131. var list = this.data.isItem ? this.data.userList : this.data.searchUser;
  132. list.map(item => {
  133. if (item.isChecked) {
  134. if (this.data.minuteIndex == 1) {
  135. if (item.is_official == 1) {
  136. employeeId.push(item.id)
  137. }
  138. } else {
  139. employeeId.push(item.id)
  140. }
  141. }
  142. })
  143. if (employeeId.length == 0) {
  144. app.globalData.showToast("请选择一名员工")
  145. return;
  146. }
  147. let url = index == 1 ? 'api/employee/disable' : 'api/employee/enable'
  148. app.$post(url, {
  149. employee_id: JSON.stringify(employeeId)
  150. }).then((res) => {
  151. app.globalData.showToast("设置成功")
  152. if (this.data.isItem) {
  153. this.getUserData(this.data.dept_id);
  154. } else {
  155. let data = {
  156. detail: {
  157. value: this.data.searchName
  158. }
  159. }
  160. this.bindKeyInput(data);
  161. }
  162. })
  163. },
  164. tbDd() {
  165. dd.navigateTo({
  166. url: '../tb/tb'
  167. })
  168. return false;
  169. dd.confirm({
  170. title: '温馨提示',
  171. content: '即将同步钉钉通讯录的人员名单,确定同步吗',
  172. confirmButtonText: '确定',
  173. cancelButtonText: '取消',
  174. success: (result) => {
  175. if (result.confirm) {
  176. var http1 = app.$post("api/ding/employee_sync", {});
  177. Promise.all([http1]).then((item) => {
  178. app.globalData.showToast(item[0].data.msg);
  179. })
  180. }
  181. },
  182. });
  183. },
  184. onReset() {
  185. this.setData({
  186. searchUser: [],
  187. isItem: true,
  188. isVal: false
  189. })
  190. },
  191. bindKeyInput(e) {
  192. app.$get("api/employee/index", {
  193. dept_id: 0
  194. }).then((res) => {
  195. var list = res.data.data.list;
  196. list.forEach(item => {
  197. item.isChecked = false
  198. if (item.id == app.globalData.userData.id) {
  199. item.is_creator = 1
  200. }
  201. })
  202. var items = list.filter((item) => {
  203. return item.name.indexOf(e.detail.value) >= 0
  204. });
  205. this.setData({
  206. searchUser: items,
  207. isItem: e.detail.value ? false : true,
  208. isVal: e.detail.value ? true : false,
  209. searchName: e.detail.value ? e.detail.value : '',
  210. isAllChecked2: false,
  211. })
  212. })
  213. },
  214. //点击导航栏
  215. activeItem(e) {
  216. var item = e.target.dataset.item;
  217. var index = e.target.dataset.index;
  218. var terr = this.data.terr;
  219. if ((index + 1) == terr.length) {
  220. return false
  221. };
  222. this.setData({
  223. rule_tree: []
  224. });
  225. if (index == 0) {
  226. this.setData({
  227. terr: [{
  228. name: '全公司',
  229. id: 0
  230. }],
  231. rule_tree: this.data.all_rule_list,
  232. dept_id: 0
  233. })
  234. } else {
  235. var arr = terr.slice(0, index + 1);
  236. this.setData({
  237. rule_tree: item._child,
  238. terr: arr,
  239. dept_id: item.id
  240. })
  241. }
  242. this.getUserData(item.id);
  243. },
  244. //点击一级
  245. activeTree(e) {
  246. var item = e.target.dataset.item
  247. var terr = this.data.terr;
  248. terr.push(item)
  249. this.setData({
  250. rule_tree: item._child,
  251. terr: terr,
  252. dept_id: item.id
  253. });
  254. this.getUserData(item.id);
  255. },
  256. //获取部门列表
  257. getBmData() {
  258. app.$get("api/department/tree", {}).then((res) => {
  259. var list = res.data.data.list;
  260. this.setData({
  261. rule_tree: list,
  262. all_rule_list: list
  263. })
  264. })
  265. },
  266. //获取员工信息
  267. getUserData(dept_id) {
  268. this.setData({
  269. userList: []
  270. })
  271. app.$get("api/employee/index", {
  272. dept_id: dept_id
  273. }).then((res) => {
  274. var list = res.data.data.list;
  275. list.forEach(item => {
  276. item.isChecked = false
  277. if (item.id == app.globalData.userData.id) {
  278. item.is_creator = 1
  279. }
  280. })
  281. this.setData({
  282. isAllChecked: false,
  283. userList: list
  284. })
  285. })
  286. },
  287. getMessage() {
  288. app.$get("api/site/info").then((res) => {
  289. this.setData({
  290. gsData: res.data.data
  291. })
  292. })
  293. }
  294. });