addRules.vue 9.4 KB

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