editRules.vue 11 KB

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