editRules.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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>{{time.join(",")}}</span>
  46. <span v-for="(item,index) in periods" :key="index">
  47. {{item.beginTime}}-{{item.endTime}}
  48. </span>
  49. </view>
  50. <view class="right">
  51. <img src="../../static/right.png">
  52. </view>
  53. </view>
  54. </view>
  55. <view class="box">
  56. <view class="name">
  57. 打卡地点:
  58. </view>
  59. <view class="val" @click="goPagePunchLocation">
  60. <view class="ele" v-if="place=='未设置'">
  61. {{place}}
  62. </view>
  63. <view class="ele black" v-else>
  64. {{place}}
  65. </view>
  66. <view class="right">
  67. <img src="../../static/right.png">
  68. </view>
  69. </view>
  70. </view>
  71. <view class="box">
  72. <view class="name">
  73. 提前通知:
  74. </view>
  75. <picker :value="index" :range="array" @change="changeSelect">
  76. <view class="val">
  77. <view class="ele" v-if="value=='未设置'">
  78. {{value}}
  79. </view>
  80. <view class="ele black" v-else>
  81. {{value}}分钟
  82. </view>
  83. <view class="right">
  84. <img src="../../static/right.png">
  85. </view>
  86. </view>
  87. </picker>
  88. </view>
  89. <!-- 确认按钮区域 -->
  90. <view class="button" @click="handleConfirm">
  91. 确认
  92. </view>
  93. <!-- 删除按钮区域 -->
  94. <view class="button2" @click="handleDelete">
  95. 删除
  96. </view>
  97. </view>
  98. </template>
  99. <script>
  100. export default {
  101. data() {
  102. return {
  103. info: {},
  104. // 规则名称
  105. ruleName: "未设置",
  106. // 考勤组
  107. group: "未设置",
  108. // 打卡时间
  109. time: "未设置",
  110. // 打卡地点
  111. place: "未设置",
  112. // 提前通知
  113. value: "未设置",
  114. // 提前通知选项
  115. array: ['5分钟', '10分钟', '15分钟', '20分钟'],
  116. periods: [],
  117. index: 0,
  118. id: "",
  119. groupIds: [],
  120. timeGroups: []
  121. };
  122. },
  123. onLoad(option) {
  124. uni.removeStorageSync("chooseList_edit")
  125. uni.removeStorageSync("ruleTime_edit")
  126. uni.removeStorageSync("flag")
  127. uni.$on('updateRuleName', (data) => {
  128. this.ruleName = data
  129. })
  130. uni.$on('updateRuleGroup', (data) => {
  131. let temList = []
  132. data.forEach((ele) => {
  133. temList.push(
  134. ele.name
  135. )
  136. })
  137. this.group = temList.join(",")
  138. })
  139. this.info = JSON.parse(option.info)
  140. console.log(this.info);
  141. if (this.info) {
  142. this.ruleName = this.info.name
  143. this.group = this.info.groups
  144. this.place = this.info.locations
  145. this.value = this.info.noticeTime
  146. this.id = this.info.id
  147. this.time = this.info.temList
  148. this.periods = []
  149. this.info.periods.forEach((ele) => {
  150. this.periods.push({
  151. beginTime: this.format_time(ele.beginTime),
  152. endTime: this.format_time(ele.endTime)
  153. })
  154. })
  155. }
  156. },
  157. onShow() {
  158. let rulePlace = uni.getStorageSync("chooseList") || uni.getStorageSync("chooseList_edit")
  159. if (rulePlace) {
  160. let temList = []
  161. rulePlace.forEach((ele) => {
  162. temList.push(ele.name)
  163. })
  164. this.place = temList.join(",")
  165. }
  166. // let ruleTime = uni.getStorageSync("ruleTime_edit")
  167. // console.log(ruleTime);
  168. // if (ruleTime) {
  169. // this.time = ruleTime
  170. // let temList = []
  171. // ruleTime.forEach((ele) => {
  172. // temList.push({
  173. // dayOfWeeks: ele.selectedWeeks,
  174. // periods: ele.list
  175. // })
  176. // })
  177. // temList.forEach((item) => {
  178. // item.dayOfWeeks = item.dayOfWeeks.map((element) => {
  179. // if (element == '星期一') {
  180. // return element = 1
  181. // }
  182. // if (element == '星期二') {
  183. // return element = 2
  184. // }
  185. // if (element == '星期三') {
  186. // return element = 3
  187. // }
  188. // if (element == '星期四') {
  189. // return element = 4
  190. // }
  191. // if (element == '星期五') {
  192. // return element = 5
  193. // }
  194. // if (element == '星期六') {
  195. // return element = 6
  196. // }
  197. // if (element == '星期天') {
  198. // return element = 7
  199. // }
  200. // })
  201. // })
  202. // this.timeGroups = temList
  203. // }
  204. // let ruleName = uni.getStorageSync("ruleName")
  205. // if (ruleName) {
  206. // this.ruleName = ruleName
  207. // }
  208. // let ruleGroup = uni.getStorageSync("ruleGroup")
  209. // if (ruleGroup) {
  210. // let temList = []
  211. // this.groupIds = []
  212. // ruleGroup.forEach((ele) => {
  213. // temList.push(ele.name)
  214. // this.groupIds.push(ele.id)
  215. // })
  216. // this.group = temList.join(",")
  217. // }
  218. let ruleTime = uni.getStorageSync("ruleTime")||uni.getStorageSync("ruleTime_edit")
  219. let flag = uni.getStorageSync("flag")
  220. // console.log(ruleTime);
  221. // console.log(flag);
  222. if (ruleTime.length == 0 && flag) {
  223. this.time = "未设置"
  224. }
  225. if (ruleTime.length > 0) {
  226. // this.time = ruleTime[0].selectedWeeks
  227. // this.periods = ruleTime[0].list
  228. // this.time = ruleTime
  229. let temList = []
  230. ruleTime.forEach((ele) => {
  231. temList.push({
  232. dayOfWeeks: ele.selectedWeeks,
  233. periods: ele.list
  234. })
  235. })
  236. // temList.forEach((item) => {
  237. // item.dayOfWeeks = item.dayOfWeeks.map((element) => {
  238. // if (element == '星期一') {
  239. // return element = 1
  240. // }
  241. // if (element == '星期二') {
  242. // return element = 2
  243. // }
  244. // if (element == '星期三') {
  245. // return element = 3
  246. // }
  247. // if (element == '星期四') {
  248. // return element = 4
  249. // }
  250. // if (element == '星期五') {
  251. // return element = 5
  252. // }
  253. // if (element == '星期六') {
  254. // return element = 6
  255. // }
  256. // if (element == '星期天') {
  257. // return element = 7
  258. // }
  259. // })
  260. // })
  261. this.periods = []
  262. this.time = []
  263. temList.forEach((element)=>{
  264. this.time.push(element.dayOfWeeks.join(","))
  265. this.periods.push(element.periods[0])
  266. })
  267. this.timeGroups = temList
  268. console.log(temList);
  269. }
  270. console.log(this.periods);
  271. console.log(this.time);
  272. },
  273. methods: {
  274. // 点击确认按钮回调
  275. handleConfirm() {
  276. if (this.ruleName == '未设置') {
  277. uni.showToast({
  278. title: "请设置规则名称",
  279. icon: 'none'
  280. })
  281. return
  282. }
  283. if (this.group == '未设置') {
  284. uni.showToast({
  285. title: "请设置考勤组",
  286. icon: 'none'
  287. })
  288. return
  289. }
  290. if (this.time == '未设置') {
  291. uni.showToast({
  292. title: "请设置打卡时间",
  293. icon: 'none'
  294. })
  295. return
  296. }
  297. if (this.place == '未设置' || this.place == "") {
  298. uni.showToast({
  299. title: "请设置打卡地点",
  300. icon: 'none'
  301. })
  302. return
  303. }
  304. if (this.value == '未设置') {
  305. uni.showToast({
  306. title: "请设置提前通知时间",
  307. icon: 'none'
  308. })
  309. return
  310. }
  311. uni.showModal({
  312. title: '提示',
  313. content: '确定修改吗?',
  314. success: (res) => {
  315. if (res.confirm) {
  316. console.log('用户点击确定');
  317. } else if (res.cancel) {}
  318. }
  319. });
  320. },
  321. // 点击删除按钮回调
  322. handleDelete() {
  323. uni.showModal({
  324. title: '提示',
  325. content: '确定删除吗?',
  326. success: async (res) => {
  327. if (res.confirm) {
  328. let res = await this.$myRequest({
  329. url: "/attendance/api/settings/rule/delete",
  330. method: "delete",
  331. data: {
  332. ids: [this.id]
  333. }
  334. })
  335. // console.log(res);
  336. if (res.code == 200) {
  337. uni.showToast({
  338. title: "删除成功"
  339. })
  340. setTimeout(() => {
  341. uni.navigateBack({
  342. delta: 1
  343. })
  344. }, 1500)
  345. }
  346. } else if (res.cancel) {}
  347. }
  348. });
  349. },
  350. // 提前通知选择框点击回调
  351. changeSelect(e) {
  352. let index = e.detail.value
  353. this.value = this.array[index]
  354. let index2 = this.value.indexOf("分", 0)
  355. this.value = this.value.substring(0, index2);
  356. },
  357. // 点击规则名称跳转回调
  358. goPageRuleName() {
  359. uni.navigateTo({
  360. url: `/pages/ruleName/ruleName?type=1`
  361. })
  362. },
  363. // 点击考勤组跳转回调
  364. goPageGroup() {
  365. uni.navigateTo({
  366. url: `/pages/group/group?flag=2&type=1`
  367. })
  368. },
  369. // 点击打卡时间跳转回调
  370. goPagePunchTime() {
  371. if (this.time == "未设置") {
  372. let periods = []
  373. let time = []
  374. uni.navigateTo({
  375. url: `/pages/punchTime/punchTime?time=${time}&periods=${periods}&type=1`
  376. })
  377. } else {
  378. let periods = JSON.stringify(this.periods)
  379. let time = JSON.stringify(this.time)
  380. uni.navigateTo({
  381. url: `/pages/punchTime/punchTime?time=${time}&periods=${periods}&type=1`
  382. })
  383. }
  384. },
  385. // 点击打卡地点跳转回调
  386. goPagePunchLocation() {
  387. uni.navigateTo({
  388. url: `/pages/punchLocation/punchLocation?id=${this.id}&type=1`
  389. })
  390. },
  391. // 格式化时间
  392. format_time(timestamp) {
  393. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  394. var date = new Date(timestamp);
  395. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  396. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  397. let strDate = h + m;
  398. return strDate;
  399. }
  400. }
  401. }
  402. </script>
  403. <style lang="scss" scoped>
  404. .container {
  405. height: 100vh;
  406. background-color: #fff;
  407. .box {
  408. display: flex;
  409. align-items: center;
  410. margin: 0 30rpx;
  411. width: 690rpx;
  412. height: 90rpx;
  413. font-size: 30rpx;
  414. border-bottom: 1rpx solid #CCCCCC;
  415. background-color: #fff;
  416. .name {
  417. flex: 1;
  418. }
  419. .val {
  420. flex: 3;
  421. display: flex;
  422. align-items: center;
  423. .ele {
  424. display: inline-block;
  425. width: 460rpx;
  426. text-align: end;
  427. color: #A6A6A6;
  428. overflow: hidden;
  429. white-space: nowrap;
  430. text-overflow: ellipsis;
  431. span {
  432. margin-right: 10rpx;
  433. }
  434. }
  435. .black {
  436. color: #000;
  437. }
  438. .right {
  439. margin-left: 20rpx;
  440. width: 40rpx;
  441. display: inline-flex;
  442. justify-content: center;
  443. align-items: center;
  444. img {
  445. width: 16rpx;
  446. height: 25rpx;
  447. }
  448. }
  449. }
  450. }
  451. .button {
  452. margin: auto;
  453. margin-top: 52rpx;
  454. width: 690rpx;
  455. height: 80rpx;
  456. line-height: 80rpx;
  457. text-align: center;
  458. font-size: 32rpx;
  459. font-weight: 500;
  460. color: #fff;
  461. border-radius: 16rpx;
  462. background-color: #3396FB;
  463. }
  464. .button2 {
  465. margin: auto;
  466. margin-top: 30rpx;
  467. width: 690rpx;
  468. height: 80rpx;
  469. line-height: 80rpx;
  470. text-align: center;
  471. font-size: 32rpx;
  472. font-weight: 500;
  473. color: #FF5733;
  474. border-radius: 16rpx;
  475. background-color: #fff;
  476. }
  477. }
  478. </style>