addRules.vue 10 KB

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