addRules.vue 9.1 KB

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