editRules.vue 12 KB

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