addRules.vue 10 KB

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