editRules.vue 11 KB

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