editRules.vue 12 KB

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