addRules.vue 9.4 KB

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