editRules.vue 12 KB

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