group.vue 13 KB

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