addRules.vue 10 KB

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