group.vue 13 KB

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