group.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <template>
  2. <view class="container">
  3. <!-- 头部搜索栏区域 -->
  4. <view class="search">
  5. <uni-search-bar bgColor="#fff" placeholder="请输入搜索内容" cancelButton="none" v-model="searchValue"
  6. @clear="clear" @blur="getGroupData">
  7. </uni-search-bar>
  8. </view>
  9. <!-- 新增考勤组区域 -->
  10. <view class="add">
  11. <view v-if="flag==1" class="icon" @click="handleAdd">
  12. <img src="../../static/add.png">
  13. </view>
  14. <view v-if="flag==1" class="title" @click="handleAdd">
  15. 新增考勤组
  16. </view>
  17. <view v-if="flag==2" class="icon" @click="handleRelevancy">
  18. <img src="../../static/add.png">
  19. </view>
  20. <view v-if="flag==2" class="title" @click="handleRelevancy">
  21. 关联考勤组
  22. </view>
  23. </view>
  24. <!--考勤组列表区域 -->
  25. <view class="group">
  26. <uni-swipe-action>
  27. <!-- 每一个考勤组区域 -->
  28. <uni-swipe-action-item :auto-close="true" :right-options="options" @click="onClick(item.id)"
  29. v-for="item in list" :key="item.id">
  30. <view class="group_item">
  31. <uni-collapse :ref="item.id+'collapse'">
  32. <uni-collapse-item open>
  33. <!-- 自定义标题区域 -->
  34. <template v-slot:title>
  35. <view class="collapse_title">
  36. <checkbox class="collapse_check" :disabled="checkStatus" color="#0082FC"
  37. :checked="item.checked" @click.stop="handleChange(item)" />
  38. <view class="collapse_info">
  39. {{item.name}}
  40. </view>
  41. </view>
  42. </template>
  43. <!-- 折叠内容区域 -->
  44. <view class="content">
  45. <view class="num">
  46. 随机人数:{{item.peopleCount}}人
  47. </view>
  48. <!-- 树状结构区域 -->
  49. <view class="tree">
  50. <dropDown :node="item.textArr" @nodechange="nodechange(item.id+'collapse')">
  51. </dropDown>
  52. </view>
  53. </view>
  54. </uni-collapse-item>
  55. </uni-collapse>
  56. </view>
  57. </uni-swipe-action-item>
  58. </uni-swipe-action>
  59. </view>
  60. <!-- 新增考勤组弹窗区域 -->
  61. <uni-popup ref="popup" :is-mask-click="false">
  62. <view class="popup_box">
  63. <view class="header">
  64. 新增考勤组
  65. </view>
  66. <view class="body">
  67. <view class="name">
  68. <input type="text" placeholder="请输入考勤组名称" v-model="group_name">
  69. </view>
  70. <view class="scope" @click="handleChoose">
  71. <view class="notes" v-if="!group_scope">
  72. 请选择考勤组范围
  73. </view>
  74. <view class="notes2" v-else>
  75. {{group_scope}}
  76. </view>
  77. <view class="icon">
  78. <img src="./imgs/bottom.png">
  79. </view>
  80. </view>
  81. <view class="num">
  82. <view class="count">
  83. <view class="icon">
  84. <img src="./imgs/people.png">
  85. </view>
  86. <view class="info">
  87. {{group_total}}人
  88. </view>
  89. </view>
  90. <view class="input">
  91. <input type="number" placeholder="请输入打卡人数" v-model="group_num">
  92. </view>
  93. </view>
  94. </view>
  95. <view class="foot">
  96. <view class="left" @click="handleCancel">
  97. 取消
  98. </view>
  99. <view class="right" @click="handleSave">
  100. 保存
  101. </view>
  102. </view>
  103. </view>
  104. </uni-popup>
  105. <!-- 选择考勤组范围区域 -->
  106. <tki-tree ref="tkitree" multiple :range="range" rangeKey="name" confirmColor="#3396FB" @confirm="treeConfirm"
  107. @cancel="treeCancel" />
  108. </view>
  109. </template>
  110. <script>
  111. import tkiTree from "@/components/tki-tree/tki-tree.vue"
  112. export default {
  113. components: {
  114. tkiTree
  115. },
  116. data() {
  117. return {
  118. // 新增考勤组名称
  119. group_name: "",
  120. // 新增考勤组范围
  121. group_scope: "",
  122. // 新增考勤组需要打卡人数
  123. group_num: null,
  124. // 新增考勤组总人数
  125. group_total: 0,
  126. // 新增考勤组ID数组
  127. userOrgList: [],
  128. flag: null,
  129. // 考勤组勾选框禁用标识
  130. checkStatus: false,
  131. // 搜索框绑定的值
  132. searchValue: "",
  133. options: [{
  134. text: '删除',
  135. style: {
  136. backgroundColor: '#D43030'
  137. }
  138. }],
  139. // 考勤组列表数据
  140. list: [],
  141. range: []
  142. };
  143. },
  144. onLoad(options) {
  145. this.flag = options.flag
  146. if (this.flag == 1) {
  147. this.checkStatus = true
  148. }
  149. this.getGroupData()
  150. },
  151. methods: {
  152. // 获取考勤组列表数据
  153. async getGroupData() {
  154. let res = await this.$myRequest({
  155. url: "/attendance/api/settings/group/list",
  156. data: {
  157. name: this.searchValue,
  158. size: 999
  159. }
  160. })
  161. // console.log(res);
  162. if (res.code == 200) {
  163. res.data.list.forEach((ele) => {
  164. ele.checked = false
  165. ele.textArr = []
  166. ele.names.forEach((element) => {
  167. ele.textArr.push({
  168. name: element
  169. })
  170. })
  171. })
  172. this.list = res.data.list
  173. }
  174. },
  175. // 考勤组选择框确定回调事件
  176. treeConfirm(e) {
  177. // console.log(e)
  178. let count = 0
  179. let temList = []
  180. let userOrgList = []
  181. e.forEach((ele) => {
  182. temList.push(ele.name)
  183. userOrgList.push({
  184. orgId: ele.id,
  185. type: 2
  186. })
  187. count += ele.number
  188. })
  189. this.group_scope = temList.join(",")
  190. this.group_total = count
  191. this.userOrgList = userOrgList
  192. },
  193. // 考勤组选择框取消回调事件
  194. treeCancel(e) {
  195. // this.$refs.tkitree._hide()
  196. },
  197. // 点击选择考勤组选择框回调
  198. async handleChoose() {
  199. this.range = []
  200. let res = await this.$myRequest({
  201. url: "/attendance/api/settings/org/tree"
  202. })
  203. // console.log(res);
  204. if (res.code == 200) {
  205. this.range = res.data
  206. this.$refs.tkitree._show()
  207. }
  208. },
  209. handleChange(item) {
  210. // console.log(item);
  211. item.checked = !item.checked
  212. },
  213. // 点击弹窗保存按钮回调
  214. async handleSave() {
  215. if (!this.group_name) {
  216. uni.showToast({
  217. title: "请输入考勤组名称",
  218. icon: "none"
  219. })
  220. return
  221. }
  222. if (!this.group_scope) {
  223. uni.showToast({
  224. title: "请选择考勤组范围",
  225. icon: "none"
  226. })
  227. return
  228. }
  229. if (this.group_total == 0) {
  230. uni.showToast({
  231. title: "该考勤组范围中人数为0,请重新选择",
  232. icon: "none"
  233. })
  234. return
  235. }
  236. if (!this.group_num) {
  237. uni.showToast({
  238. title: "请输入打卡人数",
  239. icon: "none"
  240. })
  241. return
  242. }
  243. if (this.group_num - 0 > this.group_total - 0) {
  244. uni.showToast({
  245. title: "打卡人数不能超过总人数",
  246. icon: "none"
  247. })
  248. return
  249. }
  250. let res = await this.$myRequest({
  251. url: "/attendance/api/settings/group/add",
  252. method: "post",
  253. header: {
  254. 'content-type': 'application/json',
  255. 'Authorization': uni.getStorageSync("token") ||
  256. 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1MDQ2LCJ1c2VyX3V1aWQiOjEzNDc3NzE0NzM1NTY5NzE1MiwibmJmIjoxNjcxMTU1ODQzfQ.u4-N762Ijfb9RkuuFOFkeMiJQI9uCi0IaheJlGwi5Ms'
  257. },
  258. data: {
  259. name: this.group_name,
  260. peopleCount: this.group_num,
  261. peopleTotal: this.group_total,
  262. userOrgList: this.userOrgList
  263. }
  264. })
  265. // console.log(res);
  266. if (res.code == 200) {
  267. this.$refs.popup.close()
  268. uni.showToast({
  269. title: "添加成功",
  270. icon: "none"
  271. })
  272. setTimeout(() => {
  273. this.getGroupData()
  274. }, 1500)
  275. } else {
  276. uni.showToast({
  277. title: res.message,
  278. icon: "none"
  279. })
  280. }
  281. },
  282. // 点击弹窗取消按钮回调
  283. handleCancel() {
  284. this.$refs.popup.close()
  285. },
  286. // 点击新增考勤组按钮回调
  287. handleAdd() {
  288. this.group_name = ""
  289. this.group_num = null
  290. this.group_total = 0
  291. this.group_scope = ""
  292. this.userOrgList = []
  293. this.$nextTick(() => {
  294. this.$refs.popup.open()
  295. })
  296. },
  297. // 点击关联考勤组按钮回调
  298. handleRelevancy() {
  299. let temList = []
  300. this.list.forEach((ele) => {
  301. if (ele.checked == true) {
  302. temList.push(ele.name)
  303. }
  304. })
  305. if (temList.length == 0) {
  306. uni.showToast({
  307. title: "请先勾选考勤组",
  308. icon: "none"
  309. })
  310. } else {
  311. uni.setStorageSync("ruleGroup", temList)
  312. uni.navigateBack({
  313. delta: 1
  314. })
  315. }
  316. },
  317. // 点击树状节点回调
  318. nodechange(ref) {
  319. this.$nextTick(() => {
  320. setTimeout(() => {
  321. this.$refs[ref][0].resize()
  322. }, 200)
  323. })
  324. },
  325. // 点击右侧删除按钮回调
  326. onClick(id) {
  327. // console.log(id);
  328. uni.showModal({
  329. title: '提示',
  330. content: '确定删除该考勤组吗?',
  331. success: async (res) => {
  332. if (res.confirm) {
  333. let res = await this.$myRequest({
  334. url: "/attendance/api/settings/group/delete",
  335. method: "delete",
  336. data: {
  337. ids: [id]
  338. }
  339. })
  340. // console.log(res);
  341. if (res.code == 200) {
  342. uni.showToast({
  343. title: "删除成功",
  344. icon: 'success'
  345. })
  346. setTimeout(() => {
  347. this.getGroupData()
  348. }, 1500)
  349. } else {
  350. uni.showToast({
  351. title: res.message,
  352. icon: 'success'
  353. })
  354. }
  355. } else if (res.cancel) {}
  356. }
  357. });
  358. },
  359. // 清除搜索框内容时的回调
  360. clear() {
  361. this.searchValue = ""
  362. this.getGroupData()
  363. },
  364. }
  365. }
  366. </script>
  367. <style lang="scss" scoped>
  368. .container {
  369. padding-top: 20rpx;
  370. .search {
  371. box-sizing: border-box;
  372. padding: 0 30rpx;
  373. width: 750rpx;
  374. height: 90rpx;
  375. border-radius: 170rpx;
  376. background-color: #fff;
  377. }
  378. .add {
  379. margin-top: 20rpx;
  380. display: flex;
  381. align-items: center;
  382. width: 750rpx;
  383. height: 110rpx;
  384. background-color: #fff;
  385. .icon {
  386. margin: 0 20rpx 0 30rpx;
  387. width: 36rpx;
  388. height: 36rpx;
  389. img {
  390. width: 100%;
  391. height: 100%;
  392. }
  393. }
  394. .title {
  395. font-size: 30rpx;
  396. color: #0082FC;
  397. }
  398. }
  399. .group {
  400. margin-top: 20rpx;
  401. background-color: #F2F2F2;
  402. .group_item {
  403. margin-bottom: 20rpx;
  404. width: 750rpx;
  405. background-color: #fff;
  406. .collapse_title {
  407. display: flex;
  408. align-items: center;
  409. height: 79rpx;
  410. .collapse_check {
  411. margin-left: 30rpx;
  412. }
  413. .collapse_info {
  414. margin-left: 10rpx;
  415. font-size: 28rpx;
  416. font-weight: 600;
  417. }
  418. }
  419. .content {
  420. padding-bottom: 50rpx;
  421. .num {
  422. margin-left: 30rpx;
  423. height: 50rpx;
  424. font-size: 24rpx;
  425. color: #808080;
  426. }
  427. .tree {}
  428. }
  429. }
  430. }
  431. .popup_box {
  432. width: 630rpx;
  433. height: 610rpx;
  434. border-radius: 33rpx;
  435. background-color: #fff;
  436. .header {
  437. width: 630rpx;
  438. height: 97rpx;
  439. line-height: 97rpx;
  440. text-align: center;
  441. font-size: 32rpx;
  442. font-weight: 500;
  443. border-bottom: 1rpx solid #E6E6E6;
  444. }
  445. .body {
  446. display: flex;
  447. flex-direction: column;
  448. align-items: center;
  449. width: 630rpx;
  450. height: 414rpx;
  451. border-bottom: 1rpx solid #E6E6E6;
  452. .name {
  453. margin-top: 42rpx;
  454. width: 570rpx;
  455. height: 80rpx;
  456. border-radius: 10rpx;
  457. border: 1rpx solid #ccc;
  458. input {
  459. padding: 0 24rpx;
  460. width: 90%;
  461. height: 100%;
  462. font-size: 28rpx;
  463. }
  464. }
  465. .scope {
  466. display: flex;
  467. align-items: center;
  468. margin-top: 32rpx;
  469. width: 570rpx;
  470. height: 80rpx;
  471. border-radius: 10rpx;
  472. border: 1rpx solid #ccc;
  473. .notes {
  474. padding-left: 24rpx;
  475. flex: 5;
  476. font-size: 28rpx;
  477. color: #808080;
  478. }
  479. .notes2 {
  480. padding-left: 24rpx;
  481. flex: 5;
  482. font-size: 28rpx;
  483. overflow: hidden;
  484. white-space: nowrap;
  485. text-overflow: ellipsis;
  486. }
  487. .icon {
  488. flex: 1;
  489. display: flex;
  490. justify-content: center;
  491. align-items: center;
  492. img {
  493. width: 25rpx;
  494. height: 20rpx;
  495. }
  496. }
  497. }
  498. .num {
  499. display: flex;
  500. align-items: center;
  501. margin-top: 32rpx;
  502. width: 570rpx;
  503. height: 80rpx;
  504. border-radius: 10rpx;
  505. border: 1rpx solid #ccc;
  506. .count {
  507. flex: 2;
  508. display: flex;
  509. align-items: center;
  510. height: 50rpx;
  511. border-right: 1rpx solid #A6A6A6;
  512. .icon {
  513. flex: 1;
  514. display: flex;
  515. justify-content: center;
  516. align-items: center;
  517. img {
  518. width: 30rpx;
  519. height: 30rpx;
  520. }
  521. }
  522. .info {
  523. flex: 2;
  524. font-size: 28rpx;
  525. }
  526. }
  527. .input {
  528. flex: 4;
  529. input {
  530. padding: 0 45rpx;
  531. width: 80%;
  532. font-size: 28rpx;
  533. }
  534. }
  535. }
  536. }
  537. .foot {
  538. display: flex;
  539. justify-content: space-evenly;
  540. width: 630rpx;
  541. height: 99rpx;
  542. line-height: 99rpx;
  543. font-size: 28rpx;
  544. .left {
  545. flex: 1;
  546. text-align: center;
  547. border-right: 1rpx solid #CCC;
  548. }
  549. .right {
  550. flex: 1;
  551. text-align: center;
  552. color: #2A82E4;
  553. }
  554. }
  555. }
  556. }
  557. // 解决输入框不居中问题
  558. ::v-deep .uni-searchbar {
  559. padding: 10rpx;
  560. }
  561. // 解决左滑区域突出问题
  562. ::v-deep .uni-swipe_button-group {
  563. margin-bottom: 20rpx;
  564. }
  565. // 清除树状组件下边框
  566. ::v-deep .uni-collapse-item__wrap-content.uni-collapse-item--border {
  567. border-bottom: none;
  568. }
  569. </style>