addRules.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. },
  231. data: {
  232. // 是否需要人脸识别
  233. faceRecognition: true,
  234. // 考勤组ID列表
  235. groupIds: this.groupIds,
  236. // 是否同步节假日
  237. holiday: this.holiday,
  238. // 是否可选择本地图片
  239. localPicture: false,
  240. // 规则名称
  241. name: this.ruleName,
  242. // 提前通知时间
  243. noticeTime: this.value,
  244. // 是否需要场景拍照
  245. takePicture: true,
  246. // 打卡地点列表
  247. locations: this.locations,
  248. // 打卡时间列表
  249. timeGroups: this.time
  250. },
  251. })
  252. // console.log(res)
  253. if (res.code == 200) {
  254. uni.showToast({
  255. title: "添加成功",
  256. icon: 'success'
  257. })
  258. setTimeout(() => {
  259. uni.navigateBack({
  260. delta: 1
  261. })
  262. }, 1500)
  263. }
  264. }
  265. }
  266. });
  267. },
  268. // 提前通知选择框点击回调
  269. changeSelect(e) {
  270. let index = e.detail.value
  271. this.value = this.array[index]
  272. let index2 = this.value.indexOf("分", 0)
  273. this.value = this.value.substring(0, index2);
  274. },
  275. // switch的值改变回调
  276. switchChange(e) {
  277. this.holiday = e.detail.value
  278. // console.log(this.holiday);
  279. },
  280. // 点击规则名称跳转回调
  281. goPageRuleName() {
  282. uni.navigateTo({
  283. url: `/pagesClockIn/ruleName/ruleName`
  284. })
  285. },
  286. // 点击考勤组跳转回调
  287. goPageGroup() {
  288. uni.navigateTo({
  289. url: `/pagesClockIn/group/group?flag=2`
  290. })
  291. },
  292. // 点击打卡时间跳转回调
  293. goPagePunchTime() {
  294. uni.navigateTo({
  295. url: "/pagesClockIn/punchTime/punchTime"
  296. })
  297. },
  298. // 点击打卡地点跳转回调
  299. goPagePunchLocation() {
  300. uni.navigateTo({
  301. url: "/pagesClockIn/punchLocation/punchLocation"
  302. })
  303. },
  304. // 格式化时间
  305. formatTime(val) {
  306. let tem = '2021-11-22 ' + val + ':00'
  307. // console.log(tem);
  308. let date = new Date(tem);
  309. let time = date.getTime();
  310. return time
  311. },
  312. // 格式化时间
  313. format_time(timestamp) {
  314. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  315. var date = new Date(timestamp);
  316. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  317. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  318. let strDate = h + m;
  319. return strDate;
  320. }
  321. }
  322. }
  323. </script>
  324. <style lang="scss" scoped>
  325. .container {
  326. height: 100vh;
  327. background-color: #fff;
  328. .box {
  329. display: flex;
  330. align-items: center;
  331. margin: 0 30rpx;
  332. width: 690rpx;
  333. height: 90rpx;
  334. font-size: 30rpx;
  335. border-bottom: 1rpx solid #CCCCCC;
  336. .name {
  337. flex: 1;
  338. }
  339. .val {
  340. flex: 3;
  341. display: flex;
  342. align-items: center;
  343. .ele {
  344. margin-right: 20rpx;
  345. display: inline-block;
  346. width: 460rpx;
  347. text-align: end;
  348. color: #A6A6A6;
  349. overflow: hidden;
  350. white-space: nowrap;
  351. text-overflow: ellipsis;
  352. span {
  353. margin-right: 10rpx;
  354. }
  355. }
  356. .black {
  357. color: #000;
  358. }
  359. .right {
  360. width: 40rpx;
  361. display: inline-flex;
  362. justify-content: center;
  363. align-items: center;
  364. img {
  365. width: 16rpx;
  366. height: 25rpx;
  367. }
  368. }
  369. }
  370. .val2 {
  371. flex: 1;
  372. margin-right: 20rpx;
  373. text-align: end;
  374. }
  375. }
  376. .button {
  377. margin: auto;
  378. margin-top: 52rpx;
  379. width: 690rpx;
  380. height: 80rpx;
  381. line-height: 80rpx;
  382. text-align: center;
  383. font-size: 32rpx;
  384. font-weight: 500;
  385. color: #fff;
  386. border-radius: 16rpx;
  387. background-color: #3396FB;
  388. }
  389. }
  390. </style>