organization.js 5.3 KB

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