addRules.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <view class="container">
  3. <!-- 每一个选项区域 -->
  4. <view class="box">
  5. <view class="name">规则名称:</view>
  6. <view class="val" @click="goPageRuleName">
  7. <view class="ele" v-if="ruleName == '未设置'">{{ ruleName }}</view>
  8. <view class="ele black" v-else>{{ ruleName }}</view>
  9. <view class="right"><img src="../../static/imgs/right.png" /></view>
  10. </view>
  11. </view>
  12. <view class="box">
  13. <view class="name">考 勤 组:</view>
  14. <view class="val" @click="goPageGroup">
  15. <view class="ele" v-if="group == '未设置'">{{ group }}</view>
  16. <view class="ele black" v-else>{{ group }}</view>
  17. <view class="right"><img src="../../static/imgs/right.png" /></view>
  18. </view>
  19. </view>
  20. <view class="box">
  21. <view class="name">打卡时间:</view>
  22. <view class="val" @click="goPagePunchTime">
  23. <view class="ele" v-if="time == '未设置'">{{ time }}</view>
  24. <view class="ele black" v-else>
  25. <span v-for="(item, index) in time" :key="index + '1'">
  26. <span v-for="(item_week, index_week) in item.dayOfWeeks" :key="index_week + '2'">{{ arr[item_week] }}</span>
  27. <span v-for="(item_time, index_time) in item.periods" :key="index_time + '3'">
  28. {{ format_time(item_time.beginTime) }}-{{ format_time(item_time.endTime) }}
  29. </span>
  30. </span>
  31. </view>
  32. <view class="right"><img src="../../static/imgs/right.png" /></view>
  33. </view>
  34. </view>
  35. <view class="box">
  36. <view class="name">打卡地点:</view>
  37. <view class="val" @click="goPagePunchLocation">
  38. <view class="ele" v-if="place == '未设置'">{{ place }}</view>
  39. <view class="ele black" v-else>{{ place }}</view>
  40. <view class="right"><img src="../../static/imgs/right.png" /></view>
  41. </view>
  42. </view>
  43. <view class="box">
  44. <view class="name">提前通知:</view>
  45. <picker :value="index" :range="array" @change="changeSelect">
  46. <view class="val">
  47. <view class="ele" v-if="value == '未设置'">{{ value }}</view>
  48. <view class="ele black" v-else>{{ value }}分钟</view>
  49. <view class="right"><img src="../../static/imgs/right.png" /></view>
  50. </view>
  51. </picker>
  52. </view>
  53. <view class="box">
  54. <view class="name">除去法定节假:</view>
  55. <view class="val2"><switch style="transform:scale(0.8)" color="#3396FB" :checked="holiday" @change="switchChange" /></view>
  56. </view>
  57. <view class="box">
  58. <view class="name">是否需要拍摄场景照片:</view>
  59. <view class="val2"><switch style="transform:scale(0.8)" color="#3396FB" :checked="takePicture" @change="switchChange_takePicture" /></view>
  60. </view>
  61. <!-- <view class="box">
  62. <view class="name">
  63. 是否需要人脸识别:
  64. </view>
  65. <view class="val2">
  66. <switch style="transform:scale(0.8)" color="#3396FB" :checked="faceRecognition"
  67. @change="switchChange_faceRecognition" />
  68. </view>
  69. </view> -->
  70. <view class="box">
  71. <view class="name">是否提前通知全部人员:</view>
  72. <view class="val2"><switch style="transform:scale(0.8)" color="#3396FB" :checked="notifyAll" @change="switchChange_notifyAll" /></view>
  73. </view>
  74. <!-- 确认按钮区域 -->
  75. <view class="button" @click="handleConfirm">确认</view>
  76. </view>
  77. </template>
  78. <script>
  79. export default {
  80. data() {
  81. return {
  82. // 规则名称
  83. ruleName: '未设置',
  84. // 考勤组
  85. group: '未设置',
  86. // 打卡时间
  87. time: '未设置',
  88. // 打卡地点
  89. place: '未设置',
  90. // 提前通知时间
  91. value: '未设置',
  92. // 提前通知时间选择数组
  93. array: ['5分钟', '10分钟', '15分钟', '20分钟'],
  94. // 提前通知时间选择数组默认选择的索引
  95. index: 0,
  96. // 考勤组id数组
  97. groupIds: [],
  98. // 打卡地点数组
  99. locations: [],
  100. // 是否同步节假日
  101. holiday: false,
  102. // 是否需要拍摄场景照片
  103. takePicture: false,
  104. // 是否需要人脸识别
  105. faceRecognition: false,
  106. // 是否提前通知全部人员
  107. notifyAll: false,
  108. // 星期映射数组
  109. arr: ['', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天']
  110. }
  111. },
  112. onLoad() {
  113. // 监听updateRuleName事件修改规则名称
  114. uni.$on('updateRuleName', data => {
  115. this.ruleName = data
  116. })
  117. // 监听updateRuleGroup事件修改考勤组
  118. uni.$on('updateRuleGroup', data => {
  119. let temList = []
  120. this.groupIds = []
  121. data.forEach(ele => {
  122. temList.push(ele.name)
  123. this.groupIds.push(ele.id)
  124. })
  125. this.group = temList.join(',')
  126. })
  127. },
  128. onShow() {
  129. // 从缓存获取打卡时间数据
  130. let ruleTime = uni.getStorageSync('ruleTime')
  131. // 从缓存获取打卡时间数据是否为空的标识 true为空数组 false不为空
  132. let flag = uni.getStorageSync('flag')
  133. // 如果打卡时间数组不为空,将数组赋值给time
  134. if (ruleTime) {
  135. this.time = ruleTime
  136. }
  137. // 如果打卡时间数组为空,修改time的值
  138. if (ruleTime.length == 0 && flag) {
  139. this.time = '未设置'
  140. }
  141. // 从缓存获取打卡地点数据
  142. let temPlace = uni.getStorageSync('chooseList')
  143. // 从缓存获取打卡地点数据是否为空的标识 true为空数组 false不为空
  144. let flag_place = uni.getStorageSync('flag_place')
  145. // 如果打卡地点数组不为空,将数组赋值给locations
  146. if (temPlace) {
  147. this.locations = temPlace
  148. let temList = []
  149. temPlace.forEach(ele => {
  150. temList.push(ele.name)
  151. })
  152. this.place = temList.join(',')
  153. }
  154. // 如果打卡地点数组为空,修改place的值
  155. if (temPlace.length == 0 && flag_place) {
  156. this.place = '未设置'
  157. }
  158. },
  159. methods: {
  160. // 点击确认按钮回调
  161. handleConfirm() {
  162. if (this.ruleName == '未设置') {
  163. uni.showToast({
  164. title: '请设置规则名称',
  165. icon: 'none'
  166. })
  167. return
  168. }
  169. if (this.group == '未设置') {
  170. uni.showToast({
  171. title: '请设置考勤组',
  172. icon: 'none'
  173. })
  174. return
  175. }
  176. if (this.time == '未设置') {
  177. uni.showToast({
  178. title: '请设置打卡时间',
  179. icon: 'none'
  180. })
  181. return
  182. }
  183. if (this.place == '未设置') {
  184. uni.showToast({
  185. title: '请设置打卡地点',
  186. icon: 'none'
  187. })
  188. return
  189. }
  190. if (this.value == '未设置') {
  191. uni.showToast({
  192. title: '请设置提前通知时间',
  193. icon: 'none'
  194. })
  195. return
  196. }
  197. uni.showModal({
  198. title: '提示',
  199. content: '确定新增吗?',
  200. success: async res => {
  201. if (res.confirm) {
  202. let res = await this.$myRequest_clockIn({
  203. url: '/attendance/api/settings/rule/add',
  204. method: 'post',
  205. header: {
  206. 'content-type': 'application/json'
  207. },
  208. data: {
  209. // 是否需要人脸识别
  210. faceRecognition: this.faceRecognition,
  211. // 考勤组ID列表
  212. groupIds: this.groupIds,
  213. // 是否同步节假日
  214. holiday: this.holiday,
  215. // 是否可选择本地图片
  216. localPicture: false,
  217. // 规则名称
  218. name: this.ruleName,
  219. // 提前通知时间
  220. noticeTime: this.value,
  221. // 是否需要场景拍照
  222. takePicture: this.takePicture,
  223. // 打卡地点列表
  224. locations: this.locations,
  225. // 打卡时间列表
  226. timeGroups: this.time,
  227. // 是否提前通知全部人员
  228. notifyAll: this.notifyAll
  229. }
  230. })
  231. // console.log(res)
  232. if (res.code == 200) {
  233. uni.showToast({
  234. title: '添加成功',
  235. icon: 'success'
  236. })
  237. setTimeout(() => {
  238. uni.navigateBack({
  239. delta: 1
  240. })
  241. }, 1500)
  242. }
  243. }
  244. }
  245. })
  246. },
  247. // 提前通知选择框点击回调
  248. changeSelect(e) {
  249. let index = e.detail.value
  250. this.value = this.array[index]
  251. let index2 = this.value.indexOf('分', 0)
  252. this.value = this.value.substring(0, index2)
  253. },
  254. // switch的值改变回调
  255. switchChange(e) {
  256. this.holiday = e.detail.value
  257. // console.log(this.holiday);
  258. },
  259. switchChange_takePicture(e) {
  260. this.takePicture = e.detail.value
  261. },
  262. switchChange_faceRecognition(e) {
  263. this.faceRecognition = e.detail.value
  264. },
  265. switchChange_notifyAll(e) {
  266. this.notifyAll = e.detail.value
  267. },
  268. // 点击规则名称跳转回调
  269. goPageRuleName() {
  270. uni.navigateTo({
  271. url: `/pages/ruleName/ruleName`
  272. })
  273. },
  274. // 点击考勤组跳转回调
  275. goPageGroup() {
  276. uni.navigateTo({
  277. url: `/pages/group/group?flag=2`
  278. })
  279. },
  280. // 点击打卡时间跳转回调
  281. goPagePunchTime() {
  282. uni.navigateTo({
  283. url: '/pages/punchTime/punchTime'
  284. })
  285. },
  286. // 点击打卡地点跳转回调
  287. goPagePunchLocation() {
  288. uni.navigateTo({
  289. url: '/pages/punchLocation/punchLocation'
  290. })
  291. },
  292. // 格式化时间
  293. formatTime(val) {
  294. let tem = '2021-11-22 ' + val + ':00'
  295. // console.log(tem);
  296. let date = new Date(tem)
  297. let time = date.getTime()
  298. return time
  299. },
  300. // 格式化时间
  301. format_time(timestamp) {
  302. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  303. var date = new Date(timestamp)
  304. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
  305. var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  306. let strDate = h + m
  307. return strDate
  308. }
  309. }
  310. }
  311. </script>
  312. <style lang="scss" scoped>
  313. .container {
  314. height: 100vh;
  315. background-color: #fff;
  316. .box {
  317. display: flex;
  318. align-items: center;
  319. margin: 0 30rpx;
  320. width: 690rpx;
  321. height: 90rpx;
  322. font-size: 30rpx;
  323. border-bottom: 1rpx solid #cccccc;
  324. .name {
  325. flex: 1;
  326. }
  327. .val {
  328. flex: 3;
  329. display: flex;
  330. align-items: center;
  331. .ele {
  332. margin-right: 20rpx;
  333. display: inline-block;
  334. width: 460rpx;
  335. text-align: end;
  336. color: #a6a6a6;
  337. overflow: hidden;
  338. white-space: nowrap;
  339. text-overflow: ellipsis;
  340. span {
  341. margin-right: 10rpx;
  342. }
  343. }
  344. .black {
  345. color: #000;
  346. }
  347. .right {
  348. width: 40rpx;
  349. display: inline-flex;
  350. justify-content: center;
  351. align-items: center;
  352. img {
  353. width: 16rpx;
  354. height: 25rpx;
  355. }
  356. }
  357. }
  358. .val2 {
  359. flex: 1;
  360. margin-right: 20rpx;
  361. text-align: end;
  362. }
  363. }
  364. .button {
  365. margin: auto;
  366. margin-top: 52rpx;
  367. width: 690rpx;
  368. height: 80rpx;
  369. line-height: 80rpx;
  370. text-align: center;
  371. font-size: 32rpx;
  372. font-weight: 500;
  373. color: #fff;
  374. border-radius: 16rpx;
  375. background-color: #3396fb;
  376. }
  377. }
  378. </style>