editRules.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. this.info = JSON.parse(option.info)
  125. console.log(this.info);
  126. if (this.info) {
  127. this.ruleName = this.info.name
  128. this.group = this.info.groups
  129. this.place = this.info.locations
  130. this.value = this.info.noticeTime
  131. this.id = this.info.id
  132. this.time = this.info.temList
  133. this.periods = []
  134. this.info.periods.forEach((ele) => {
  135. this.periods.push({
  136. beginTime: this.format_time(ele.beginTime),
  137. endTime: this.format_time(ele.endTime)
  138. })
  139. })
  140. }
  141. },
  142. onShow() {
  143. let ruleName = uni.getStorageSync("ruleName")
  144. if (ruleName) {
  145. this.ruleName = ruleName
  146. }
  147. let ruleGroup = uni.getStorageSync("ruleGroup")
  148. if (ruleGroup) {
  149. let temList = []
  150. this.groupIds = []
  151. ruleGroup.forEach((ele) => {
  152. temList.push(ele.name)
  153. this.groupIds.push(ele.id)
  154. })
  155. this.group = temList.join(",")
  156. }
  157. let ruleTime = uni.getStorageSync("ruleTime")
  158. let flag = uni.getStorageSync("flag")
  159. console.log(ruleTime);
  160. console.log(flag);
  161. if (ruleTime.length == 0 && flag) {
  162. this.time = "未设置"
  163. }
  164. if (ruleTime.length > 0) {
  165. this.time = ruleTime[0].selectedWeeks
  166. this.periods = ruleTime[0].list
  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. },
  203. methods: {
  204. // 点击确认按钮回调
  205. handleConfirm() {
  206. uni.showModal({
  207. title: '提示',
  208. content: '确定修改吗?',
  209. success: (res) => {
  210. if (res.confirm) {
  211. console.log('用户点击确定');
  212. } else if (res.cancel) {}
  213. }
  214. });
  215. },
  216. // 点击删除按钮回调
  217. handleDelete() {
  218. uni.showModal({
  219. title: '提示',
  220. content: '确定删除吗?',
  221. success: async (res) => {
  222. if (res.confirm) {
  223. let res = await this.$myRequest({
  224. url: "/attendance/api/settings/rule/delete",
  225. method: "delete",
  226. data: {
  227. ids: [this.id]
  228. }
  229. })
  230. // console.log(res);
  231. if (res.code == 200) {
  232. uni.showToast({
  233. title: "删除成功"
  234. })
  235. setTimeout(() => {
  236. uni.navigateBack({
  237. delta: 1
  238. })
  239. }, 1500)
  240. }
  241. } else if (res.cancel) {}
  242. }
  243. });
  244. },
  245. // 提前通知选择框点击回调
  246. changeSelect(e) {
  247. let index = e.detail.value
  248. this.value = this.array[index]
  249. let index2 = this.value.indexOf("分", 0)
  250. this.value = this.value.substring(0, index2);
  251. uni.setStorageSync("ruleValue", this.value)
  252. },
  253. // 点击规则名称跳转回调
  254. goPageRuleName() {
  255. uni.navigateTo({
  256. url: `/pages/ruleName/ruleName`
  257. })
  258. },
  259. // 点击考勤组跳转回调
  260. goPageGroup() {
  261. uni.navigateTo({
  262. url: `/pages/group/group?flag=2`
  263. })
  264. },
  265. // 点击打卡时间跳转回调
  266. goPagePunchTime() {
  267. if (this.time == "未设置") {
  268. let periods = []
  269. let time = []
  270. uni.navigateTo({
  271. url: `/pages/punchTime/punchTime?time=${time}&periods=${periods}`
  272. })
  273. } else {
  274. let periods = JSON.stringify(this.periods)
  275. let time = JSON.stringify(this.time)
  276. uni.navigateTo({
  277. url: `/pages/punchTime/punchTime?time=${time}&periods=${periods}`
  278. })
  279. }
  280. },
  281. // 点击打卡地点跳转回调
  282. goPagePunchLocation() {
  283. uni.navigateTo({
  284. url: "/pages/punchLocation/punchLocation"
  285. })
  286. },
  287. // 格式化时间
  288. format_time(timestamp) {
  289. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  290. var date = new Date(timestamp);
  291. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  292. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  293. let strDate = h + m;
  294. return strDate;
  295. }
  296. }
  297. }
  298. </script>
  299. <style lang="scss" scoped>
  300. .container {
  301. height: 100vh;
  302. background-color: #fff;
  303. .box {
  304. display: flex;
  305. align-items: center;
  306. margin: 0 30rpx;
  307. width: 690rpx;
  308. height: 90rpx;
  309. font-size: 30rpx;
  310. border-bottom: 1rpx solid #CCCCCC;
  311. background-color: #fff;
  312. .name {
  313. flex: 1;
  314. }
  315. .val {
  316. flex: 3;
  317. display: flex;
  318. align-items: center;
  319. .ele {
  320. display: inline-block;
  321. width: 460rpx;
  322. text-align: end;
  323. color: #A6A6A6;
  324. overflow: hidden;
  325. white-space: nowrap;
  326. text-overflow: ellipsis;
  327. span {
  328. margin-right: 10rpx;
  329. }
  330. }
  331. .black {
  332. color: #000;
  333. }
  334. .right {
  335. margin-left: 20rpx;
  336. width: 40rpx;
  337. display: inline-flex;
  338. justify-content: center;
  339. align-items: center;
  340. img {
  341. width: 16rpx;
  342. height: 25rpx;
  343. }
  344. }
  345. }
  346. }
  347. .button {
  348. margin: auto;
  349. margin-top: 52rpx;
  350. width: 690rpx;
  351. height: 80rpx;
  352. line-height: 80rpx;
  353. text-align: center;
  354. font-size: 32rpx;
  355. font-weight: 500;
  356. color: #fff;
  357. border-radius: 16rpx;
  358. background-color: #3396FB;
  359. }
  360. .button2 {
  361. margin: auto;
  362. margin-top: 30rpx;
  363. width: 690rpx;
  364. height: 80rpx;
  365. line-height: 80rpx;
  366. text-align: center;
  367. font-size: 32rpx;
  368. font-weight: 500;
  369. color: #FF5733;
  370. border-radius: 16rpx;
  371. background-color: #fff;
  372. }
  373. }
  374. </style>