editRules.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <template>
  2. <view class="container">
  3. <!-- 每一个选项区域 -->
  4. <view class="box">
  5. <view class="name">
  6. 规则名称:
  7. </view>
  8. <view class="val" @click="goPageRuleName">
  9. <view class="ele" v-if="ruleName=='未设置'">
  10. {{ruleName}}
  11. </view>
  12. <view class="ele black" v-else>
  13. {{ruleName}}
  14. </view>
  15. <view class="right">
  16. <img src="../../static/right.png">
  17. </view>
  18. </view>
  19. </view>
  20. <view class="box">
  21. <view class="name">
  22. 考 勤 组:
  23. </view>
  24. <view class="val" @click="goPageGroup">
  25. <view class="ele" v-if="group=='未设置'">
  26. {{group}}
  27. </view>
  28. <view class="ele black" v-else>
  29. {{group}}
  30. </view>
  31. <view class="right">
  32. <img src="../../static/right.png">
  33. </view>
  34. </view>
  35. </view>
  36. <view class="box">
  37. <view class="name">
  38. 打卡时间:
  39. </view>
  40. <view class="val" @click="goPagePunchTime">
  41. <view class="ele" v-if="time=='未设置'">
  42. {{time}}
  43. </view>
  44. <view class="ele black" v-else>
  45. <span>{{time.join(",")}}</span>
  46. <span v-for="(item,index) in periods" :key="index">
  47. {{item.beginTime}}-{{item.endTime}}
  48. </span>
  49. </view>
  50. <view class="right">
  51. <img src="../../static/right.png">
  52. </view>
  53. </view>
  54. </view>
  55. <view class="box">
  56. <view class="name">
  57. 打卡地点:
  58. </view>
  59. <view class="val" @click="goPagePunchLocation">
  60. <view class="ele" v-if="place=='未设置'">
  61. {{place}}
  62. </view>
  63. <view class="ele black" v-else>
  64. {{place}}
  65. </view>
  66. <view class="right">
  67. <img src="../../static/right.png">
  68. </view>
  69. </view>
  70. </view>
  71. <view class="box">
  72. <view class="name">
  73. 提前通知:
  74. </view>
  75. <picker :value="index" :range="array" @change="changeSelect">
  76. <view class="val">
  77. <view class="ele" v-if="value=='未设置'">
  78. {{value}}
  79. </view>
  80. <view class="ele black" v-else>
  81. {{value}}分钟
  82. </view>
  83. <view class="right">
  84. <img src="../../static/right.png">
  85. </view>
  86. </view>
  87. </picker>
  88. </view>
  89. <!-- 确认按钮区域 -->
  90. <view class="button" @click="handleConfirm">
  91. 确认
  92. </view>
  93. <!-- 删除按钮区域 -->
  94. <view class="button2" @click="handleDelete">
  95. 删除
  96. </view>
  97. </view>
  98. </template>
  99. <script>
  100. export default {
  101. data() {
  102. return {
  103. info: {},
  104. // 规则名称
  105. ruleName: "未设置",
  106. // 考勤组
  107. group: "未设置",
  108. // 打卡时间
  109. time: "未设置",
  110. // 打卡地点
  111. place: "未设置",
  112. // 提前通知
  113. value: "未设置",
  114. // 提前通知选项
  115. array: ['5分钟', '10分钟', '15分钟', '20分钟'],
  116. periods: [],
  117. index: 0,
  118. id: "",
  119. groupIds: [],
  120. timeGroups: [],
  121. locations: []
  122. };
  123. },
  124. onLoad(option) {
  125. uni.removeStorageSync("chooseList_edit")
  126. uni.removeStorageSync("ruleTime_edit")
  127. uni.removeStorageSync("flag")
  128. uni.$on('updateRuleName', (data) => {
  129. this.ruleName = data
  130. })
  131. uni.$on('updateRuleGroup', (data) => {
  132. let temList = []
  133. this.groupIds = []
  134. data.forEach((ele) => {
  135. temList.push(ele.name)
  136. this.groupIds.push(ele.id)
  137. })
  138. this.group = temList.join(",")
  139. })
  140. this.info = JSON.parse(option.info)
  141. console.log(this.info);
  142. if (this.info) {
  143. this.ruleName = this.info.name
  144. this.group = this.info.groups
  145. this.place = this.info.locations
  146. this.value = this.info.noticeTime
  147. this.id = this.info.id
  148. this.time = this.info.temList
  149. this.periods = []
  150. this.info.periods.forEach((ele) => {
  151. this.periods.push({
  152. beginTime: this.format_time(ele.beginTime),
  153. endTime: this.format_time(ele.endTime)
  154. })
  155. })
  156. }
  157. },
  158. onShow() {
  159. let rulePlace = uni.getStorageSync("chooseList") || uni.getStorageSync("chooseList_edit")
  160. if (rulePlace) {
  161. this.locations = rulePlace
  162. let temList = []
  163. rulePlace.forEach((ele) => {
  164. temList.push(ele.name)
  165. })
  166. this.place = temList.join(",")
  167. }
  168. let ruleTime = uni.getStorageSync("ruleTime") || uni.getStorageSync("ruleTime_edit")
  169. let flag = uni.getStorageSync("flag")
  170. if (ruleTime.length == 0 && flag) {
  171. this.time = "未设置"
  172. }
  173. if (ruleTime.length > 0) {
  174. let temList = []
  175. ruleTime.forEach((ele) => {
  176. temList.push({
  177. dayOfWeeks: ele.selectedWeeks,
  178. periods: ele.list
  179. })
  180. })
  181. this.periods = []
  182. this.time = []
  183. temList.forEach((element) => {
  184. this.time.push(element.dayOfWeeks.join(","))
  185. this.periods.push(element.periods[0])
  186. })
  187. temList.forEach((item) => {
  188. item.dayOfWeeks = item.dayOfWeeks.map((element) => {
  189. if (element == '星期一') {
  190. return element = 1
  191. }
  192. if (element == '星期二') {
  193. return element = 2
  194. }
  195. if (element == '星期三') {
  196. return element = 3
  197. }
  198. if (element == '星期四') {
  199. return element = 4
  200. }
  201. if (element == '星期五') {
  202. return element = 5
  203. }
  204. if (element == '星期六') {
  205. return element = 6
  206. }
  207. if (element == '星期天') {
  208. return element = 7
  209. }
  210. })
  211. })
  212. this.timeGroups = temList
  213. }
  214. // let ruleTime = uni.getStorageSync("ruleTime_edit")
  215. // console.log(ruleTime);
  216. // if (ruleTime) {
  217. // this.time = ruleTime
  218. // let temList = []
  219. // ruleTime.forEach((ele) => {
  220. // temList.push({
  221. // dayOfWeeks: ele.selectedWeeks,
  222. // periods: ele.list
  223. // })
  224. // })
  225. // temList.forEach((item) => {
  226. // item.dayOfWeeks = item.dayOfWeeks.map((element) => {
  227. // if (element == '星期一') {
  228. // return element = 1
  229. // }
  230. // if (element == '星期二') {
  231. // return element = 2
  232. // }
  233. // if (element == '星期三') {
  234. // return element = 3
  235. // }
  236. // if (element == '星期四') {
  237. // return element = 4
  238. // }
  239. // if (element == '星期五') {
  240. // return element = 5
  241. // }
  242. // if (element == '星期六') {
  243. // return element = 6
  244. // }
  245. // if (element == '星期天') {
  246. // return element = 7
  247. // }
  248. // })
  249. // })
  250. // this.timeGroups = temList
  251. // }
  252. // let ruleName = uni.getStorageSync("ruleName")
  253. // if (ruleName) {
  254. // this.ruleName = ruleName
  255. // }
  256. // let ruleGroup = uni.getStorageSync("ruleGroup")
  257. // if (ruleGroup) {
  258. // let temList = []
  259. // this.groupIds = []
  260. // ruleGroup.forEach((ele) => {
  261. // temList.push(ele.name)
  262. // this.groupIds.push(ele.id)
  263. // })
  264. // this.group = temList.join(",")
  265. // }
  266. },
  267. methods: {
  268. // 点击确认按钮回调
  269. handleConfirm() {
  270. if (this.ruleName == '未设置') {
  271. uni.showToast({
  272. title: "请设置规则名称",
  273. icon: 'none'
  274. })
  275. return
  276. }
  277. if (this.group == '未设置') {
  278. uni.showToast({
  279. title: "请设置考勤组",
  280. icon: 'none'
  281. })
  282. return
  283. }
  284. if (this.time == '未设置') {
  285. uni.showToast({
  286. title: "请设置打卡时间",
  287. icon: 'none'
  288. })
  289. return
  290. }
  291. if (this.place == '未设置' || this.place == "") {
  292. uni.showToast({
  293. title: "请设置打卡地点",
  294. icon: 'none'
  295. })
  296. return
  297. }
  298. if (this.value == '未设置') {
  299. uni.showToast({
  300. title: "请设置提前通知时间",
  301. icon: 'none'
  302. })
  303. return
  304. }
  305. uni.showModal({
  306. title: '提示',
  307. content: '确定修改吗?',
  308. success: async (res) => {
  309. if (res.confirm) {
  310. let temList = []
  311. this.timeGroups.forEach((ele) => {
  312. ele.periods.forEach((item) => {
  313. temList.push({
  314. beginTime: this.formatTime(item.beginTime),
  315. endTime: this.formatTime(item.endTime)
  316. })
  317. })
  318. ele.periods = temList
  319. })
  320. let res = await this.$myRequest({
  321. url: "/attendance/api/settings/rule/update",
  322. method: "put",
  323. header: {
  324. 'Authorization': uni.getStorageSync("token") ||
  325. 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1MDQ2LCJ1c2VyX3V1aWQiOjEzNDc3NzE0NzM1NTY5NzE1MiwibmJmIjoxNjcxMTU1ODQzfQ.u4-N762Ijfb9RkuuFOFkeMiJQI9uCi0IaheJlGwi5Ms'
  326. },
  327. data: {
  328. // 编辑的规则id
  329. id: this.id,
  330. // 是否需要人脸识别
  331. faceRecognition: true,
  332. // 考勤组ID列表
  333. groupIds: this.groupIds,
  334. // 是否同步节假日
  335. holiday: true,
  336. // 是否可选择本地图片
  337. localPicture: false,
  338. // 规则名称
  339. name: this.ruleName,
  340. // 提前通知时间
  341. noticeTime: this.value,
  342. // 是否需要场景拍照
  343. takePicture: true,
  344. // 打卡地点列表
  345. locations: this.locations,
  346. // 打卡时间列表
  347. timeGroups: this.timeGroups
  348. }
  349. })
  350. console.log(res);
  351. } else if (res.cancel) {}
  352. }
  353. });
  354. },
  355. // 点击删除按钮回调
  356. handleDelete() {
  357. uni.showModal({
  358. title: '提示',
  359. content: '确定删除吗?',
  360. success: async (res) => {
  361. if (res.confirm) {
  362. let res = await this.$myRequest({
  363. url: "/attendance/api/settings/rule/delete",
  364. method: "delete",
  365. data: {
  366. ids: [this.id]
  367. }
  368. })
  369. // console.log(res);
  370. if (res.code == 200) {
  371. uni.showToast({
  372. title: "删除成功"
  373. })
  374. setTimeout(() => {
  375. uni.navigateBack({
  376. delta: 1
  377. })
  378. }, 1500)
  379. }
  380. } else if (res.cancel) {}
  381. }
  382. });
  383. },
  384. // 提前通知选择框点击回调
  385. changeSelect(e) {
  386. let index = e.detail.value
  387. this.value = this.array[index]
  388. let index2 = this.value.indexOf("分", 0)
  389. this.value = this.value.substring(0, index2);
  390. },
  391. // 点击规则名称跳转回调
  392. goPageRuleName() {
  393. uni.navigateTo({
  394. url: `/pages/ruleName/ruleName?type=1`
  395. })
  396. },
  397. // 点击考勤组跳转回调
  398. goPageGroup() {
  399. uni.navigateTo({
  400. url: `/pages/group/group?flag=2&type=1`
  401. })
  402. },
  403. // 点击打卡时间跳转回调
  404. goPagePunchTime() {
  405. if (this.time == "未设置") {
  406. let periods = []
  407. let time = []
  408. uni.navigateTo({
  409. url: `/pages/punchTime/punchTime?time=${time}&periods=${periods}&type=1`
  410. })
  411. } else {
  412. let periods = JSON.stringify(this.periods)
  413. let time = JSON.stringify(this.time)
  414. uni.navigateTo({
  415. url: `/pages/punchTime/punchTime?time=${time}&periods=${periods}&type=1`
  416. })
  417. }
  418. },
  419. // 点击打卡地点跳转回调
  420. goPagePunchLocation() {
  421. uni.navigateTo({
  422. url: `/pages/punchLocation/punchLocation?id=${this.id}&type=1`
  423. })
  424. },
  425. // 格式化时间
  426. format_time(timestamp) {
  427. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  428. var date = new Date(timestamp);
  429. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  430. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  431. let strDate = h + m;
  432. return strDate;
  433. },
  434. // 格式化时间
  435. formatTime(val) {
  436. let tem = '2021-11-22 ' + val + ':00'
  437. // console.log(tem);
  438. let date = new Date(tem);
  439. let time = date.getTime();
  440. return time
  441. }
  442. }
  443. }
  444. </script>
  445. <style lang="scss" scoped>
  446. .container {
  447. height: 100vh;
  448. background-color: #fff;
  449. .box {
  450. display: flex;
  451. align-items: center;
  452. margin: 0 30rpx;
  453. width: 690rpx;
  454. height: 90rpx;
  455. font-size: 30rpx;
  456. border-bottom: 1rpx solid #CCCCCC;
  457. background-color: #fff;
  458. .name {
  459. flex: 1;
  460. }
  461. .val {
  462. flex: 3;
  463. display: flex;
  464. align-items: center;
  465. .ele {
  466. display: inline-block;
  467. width: 460rpx;
  468. text-align: end;
  469. color: #A6A6A6;
  470. overflow: hidden;
  471. white-space: nowrap;
  472. text-overflow: ellipsis;
  473. span {
  474. margin-right: 10rpx;
  475. }
  476. }
  477. .black {
  478. color: #000;
  479. }
  480. .right {
  481. margin-left: 20rpx;
  482. width: 40rpx;
  483. display: inline-flex;
  484. justify-content: center;
  485. align-items: center;
  486. img {
  487. width: 16rpx;
  488. height: 25rpx;
  489. }
  490. }
  491. }
  492. }
  493. .button {
  494. margin: auto;
  495. margin-top: 52rpx;
  496. width: 690rpx;
  497. height: 80rpx;
  498. line-height: 80rpx;
  499. text-align: center;
  500. font-size: 32rpx;
  501. font-weight: 500;
  502. color: #fff;
  503. border-radius: 16rpx;
  504. background-color: #3396FB;
  505. }
  506. .button2 {
  507. margin: auto;
  508. margin-top: 30rpx;
  509. width: 690rpx;
  510. height: 80rpx;
  511. line-height: 80rpx;
  512. text-align: center;
  513. font-size: 32rpx;
  514. font-weight: 500;
  515. color: #FF5733;
  516. border-radius: 16rpx;
  517. background-color: #fff;
  518. }
  519. }
  520. </style>