editRules.vue 12 KB

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