group.vue 13 KB

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