addRules.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. </view>
  133. </template>
  134. <script>
  135. export default {
  136. data() {
  137. return {
  138. // 规则名称
  139. ruleName: "未设置",
  140. // 考勤组
  141. group: "未设置",
  142. // 打卡时间
  143. time: "未设置",
  144. // 打卡地点
  145. place: "未设置",
  146. // 提前通知时间
  147. value: "未设置",
  148. // 提前通知时间选择数组
  149. array: ['5分钟', '10分钟', '15分钟', '20分钟'],
  150. // 提前通知时间选择数组默认选择的索引
  151. index: 0,
  152. // 考勤组id数组
  153. groupIds: [],
  154. // 打卡地点数组
  155. locations: [],
  156. // 是否同步节假日
  157. holiday: false,
  158. // 是否需要拍摄场景照片
  159. takePicture: false,
  160. // 是否需要人脸识别
  161. faceRecognition: false,
  162. // 是否提前通知全部人员
  163. notifyAll: false,
  164. // 星期映射数组
  165. arr: ["", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
  166. };
  167. },
  168. onLoad() {
  169. // 监听updateRuleName事件修改规则名称
  170. uni.$on('updateRuleName', (data) => {
  171. this.ruleName = data
  172. })
  173. // 监听updateRuleGroup事件修改考勤组
  174. uni.$on('updateRuleGroup', (data) => {
  175. let temList = []
  176. this.groupIds = []
  177. data.forEach((ele) => {
  178. temList.push(ele.name)
  179. this.groupIds.push(ele.id)
  180. })
  181. this.group = temList.join(",")
  182. })
  183. },
  184. onShow() {
  185. // 从缓存获取打卡时间数据
  186. let ruleTime = uni.getStorageSync("ruleTime")
  187. // 从缓存获取打卡时间数据是否为空的标识 true为空数组 false不为空
  188. let flag = uni.getStorageSync("flag")
  189. // 如果打卡时间数组不为空,将数组赋值给time
  190. if (ruleTime) {
  191. this.time = ruleTime
  192. }
  193. // 如果打卡时间数组为空,修改time的值
  194. if (ruleTime.length == 0 && flag) {
  195. this.time = "未设置"
  196. }
  197. // 从缓存获取打卡地点数据
  198. let temPlace = uni.getStorageSync("chooseList")
  199. // 从缓存获取打卡地点数据是否为空的标识 true为空数组 false不为空
  200. let flag_place = uni.getStorageSync("flag_place")
  201. // 如果打卡地点数组不为空,将数组赋值给locations
  202. if (temPlace) {
  203. this.locations = temPlace
  204. let temList = []
  205. temPlace.forEach((ele) => {
  206. temList.push(ele.name)
  207. })
  208. this.place = temList.join(",")
  209. }
  210. // 如果打卡地点数组为空,修改place的值
  211. if (temPlace.length == 0 && flag_place) {
  212. this.place = "未设置"
  213. }
  214. },
  215. methods: {
  216. // 点击确认按钮回调
  217. handleConfirm() {
  218. if (this.ruleName == '未设置') {
  219. uni.showToast({
  220. title: "请设置规则名称",
  221. icon: 'none'
  222. })
  223. return
  224. }
  225. if (this.group == '未设置') {
  226. uni.showToast({
  227. title: "请设置考勤组",
  228. icon: 'none'
  229. })
  230. return
  231. }
  232. if (this.time == '未设置') {
  233. uni.showToast({
  234. title: "请设置打卡时间",
  235. icon: 'none'
  236. })
  237. return
  238. }
  239. if (this.place == '未设置') {
  240. uni.showToast({
  241. title: "请设置打卡地点",
  242. icon: 'none'
  243. })
  244. return
  245. }
  246. if (this.value == '未设置') {
  247. uni.showToast({
  248. title: "请设置提前通知时间",
  249. icon: 'none'
  250. })
  251. return
  252. }
  253. uni.showModal({
  254. title: '提示',
  255. content: '确定新增吗?',
  256. success: async (res) => {
  257. if (res.confirm) {
  258. let res = await this.$myRequest_clockIn({
  259. url: "/attendance/api/settings/rule/add",
  260. method: "post",
  261. header: {
  262. 'Authorization': uni.getStorageSync("token"),
  263. 'platform': 2,
  264. 'Accept-Language': 'zh-CN,zh;q=0.9'
  265. },
  266. data: {
  267. // 是否需要人脸识别
  268. faceRecognition: this.faceRecognition,
  269. // 考勤组ID列表
  270. groupIds: this.groupIds,
  271. // 是否同步节假日
  272. holiday: this.holiday,
  273. // 是否可选择本地图片
  274. localPicture: false,
  275. // 规则名称
  276. name: this.ruleName,
  277. // 提前通知时间
  278. noticeTime: this.value,
  279. // 是否需要场景拍照
  280. takePicture: this.takePicture,
  281. // 打卡地点列表
  282. locations: this.locations,
  283. // 打卡时间列表
  284. timeGroups: this.time,
  285. // 是否提前通知全部人员
  286. notifyAll: this.notifyAll
  287. },
  288. })
  289. // console.log(res)
  290. if (res.code == 200) {
  291. uni.showToast({
  292. title: "添加成功",
  293. icon: 'success'
  294. })
  295. setTimeout(() => {
  296. uni.navigateBack({
  297. delta: 1
  298. })
  299. }, 1500)
  300. }
  301. }
  302. }
  303. });
  304. },
  305. // 提前通知选择框点击回调
  306. changeSelect(e) {
  307. let index = e.detail.value
  308. this.value = this.array[index]
  309. let index2 = this.value.indexOf("分", 0)
  310. this.value = this.value.substring(0, index2);
  311. },
  312. // switch的值改变回调
  313. switchChange(e) {
  314. this.holiday = e.detail.value
  315. // console.log(this.holiday);
  316. },
  317. switchChange_takePicture(e) {
  318. this.takePicture = e.detail.value
  319. },
  320. switchChange_faceRecognition(e) {
  321. this.faceRecognition = e.detail.value
  322. },
  323. switchChange_notifyAll(e) {
  324. this.notifyAll = e.detail.value
  325. },
  326. // 点击规则名称跳转回调
  327. goPageRuleName() {
  328. uni.navigateTo({
  329. url: `/pagesClockIn/ruleName/ruleName`
  330. })
  331. },
  332. // 点击考勤组跳转回调
  333. goPageGroup() {
  334. uni.navigateTo({
  335. url: `/pagesClockIn/group/group?flag=2`
  336. })
  337. },
  338. // 点击打卡时间跳转回调
  339. goPagePunchTime() {
  340. uni.navigateTo({
  341. url: "/pagesClockIn/punchTime/punchTime"
  342. })
  343. },
  344. // 点击打卡地点跳转回调
  345. goPagePunchLocation() {
  346. uni.navigateTo({
  347. url: "/pagesClockIn/punchLocation/punchLocation"
  348. })
  349. },
  350. // 格式化时间
  351. formatTime(val) {
  352. let tem = '2021-11-22 ' + val + ':00'
  353. // console.log(tem);
  354. let date = new Date(tem);
  355. let time = date.getTime();
  356. return time
  357. },
  358. // 格式化时间
  359. format_time(timestamp) {
  360. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  361. var date = new Date(timestamp);
  362. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  363. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  364. let strDate = h + m;
  365. return strDate;
  366. }
  367. }
  368. }
  369. </script>
  370. <style lang="scss" scoped>
  371. .container {
  372. height: 100vh;
  373. background-color: #fff;
  374. .box {
  375. display: flex;
  376. align-items: center;
  377. margin: 0 30rpx;
  378. width: 690rpx;
  379. height: 90rpx;
  380. font-size: 30rpx;
  381. border-bottom: 1rpx solid #CCCCCC;
  382. .name {
  383. flex: 1;
  384. }
  385. .val {
  386. flex: 3;
  387. display: flex;
  388. align-items: center;
  389. .ele {
  390. margin-right: 20rpx;
  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. width: 40rpx;
  407. display: inline-flex;
  408. justify-content: center;
  409. align-items: center;
  410. img {
  411. width: 16rpx;
  412. height: 25rpx;
  413. }
  414. }
  415. }
  416. .val2 {
  417. flex: 1;
  418. margin-right: 20rpx;
  419. text-align: end;
  420. }
  421. }
  422. .button {
  423. margin: auto;
  424. margin-top: 52rpx;
  425. width: 690rpx;
  426. height: 80rpx;
  427. line-height: 80rpx;
  428. text-align: center;
  429. font-size: 32rpx;
  430. font-weight: 500;
  431. color: #fff;
  432. border-radius: 16rpx;
  433. background-color: #3396FB;
  434. }
  435. }
  436. </style>