setPunchTime.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <view class="container">
  3. <!-- 选择星期区域 -->
  4. <view class="week_title">
  5. 选择星期
  6. </view>
  7. <view class="week">
  8. <jlk-week :value="selectedWeeks" @change="changeWeek"></jlk-week>
  9. </view>
  10. <!-- 选择打卡时间段区域 -->
  11. <view class="time_list">
  12. <view class="title">
  13. 选择打卡时间段
  14. </view>
  15. <view class="add" @click="handleAddTime">
  16. 添加时段
  17. </view>
  18. </view>
  19. <view class="list">
  20. <uni-swipe-action>
  21. <!-- 每一个时间段区域 -->
  22. <uni-swipe-action-item :auto-close="true" :right-options="options" @click="onClick(index)"
  23. v-for="(item,index) in list" :key="index">
  24. <view class="item">
  25. <view class="item_box">
  26. <picker mode="time" :value="item.startTime" @change="bindTimeChange($event,1,item)">
  27. <view class="uni-input">
  28. <view class="input_time">
  29. {{item.startTime}}
  30. </view>
  31. <view class="input_icon">
  32. <img src="../../static/time.png">
  33. </view>
  34. </view>
  35. </picker>
  36. </view>
  37. --
  38. <view class="item_box">
  39. <picker mode="time" :value="item.endTime" @change="bindTimeChange($event,2,item)">
  40. <view class="uni-input">
  41. <view class="input_time">
  42. {{item.endTime}}
  43. </view>
  44. <view class="input_icon">
  45. <img src="../../static/time.png">
  46. </view>
  47. </view>
  48. </picker>
  49. </view>
  50. </view>
  51. </uni-swipe-action-item>
  52. </uni-swipe-action>
  53. <!-- <view class="edit">
  54. 编辑
  55. </view> -->
  56. </view>
  57. <!-- switch区域 -->
  58. <view class="switch">
  59. <view class="switch_title">
  60. 除去法定节假日
  61. </view>
  62. <view class="switch_button">
  63. <switch color="#2A82E4" :checked="holiday" @change="switchChange" />
  64. </view>
  65. </view>
  66. <view class="button" @click="handleSave">
  67. 保存
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import JlkWeek from '@/uni_modules/jlk-week/components/jlk-week/jlk-week.vue';
  73. export default {
  74. components: {
  75. JlkWeek
  76. },
  77. data() {
  78. return {
  79. // 选中的星期
  80. selectedWeeks: [],
  81. // 打卡时间段列表
  82. list: [{
  83. startTime: "00:00",
  84. endTime: "00:00",
  85. }],
  86. // 是否同步法定节假日
  87. holiday: false,
  88. // 编辑打卡时间页面带过来的对象
  89. info: {},
  90. // 左滑配置
  91. options: [{
  92. text: '删除',
  93. style: {
  94. backgroundColor: '#D43030'
  95. }
  96. }],
  97. }
  98. },
  99. onLoad(options) {
  100. if (options.flag == 1) {
  101. uni.setNavigationBarTitle({
  102. title: '添加打卡时间'
  103. });
  104. } else {
  105. uni.setNavigationBarTitle({
  106. title: '编辑打卡时间'
  107. });
  108. this.info = JSON.parse(options.info)
  109. // console.log(this.info);
  110. this.list = this.info.list
  111. this.holiday = this.info.holiday
  112. this.selectedWeeks = this.info.selectedWeeks.map((ele) => {
  113. if (ele == '星期一') {
  114. return ele = 1
  115. }
  116. if (ele == '星期二') {
  117. return ele = 2
  118. }
  119. if (ele == '星期三') {
  120. return ele = 3
  121. }
  122. if (ele == '星期四') {
  123. return ele = 4
  124. }
  125. if (ele == '星期五') {
  126. return ele = 5
  127. }
  128. if (ele == '星期六') {
  129. return ele = 6
  130. }
  131. if (ele == '星期天') {
  132. return ele = 0
  133. }
  134. })
  135. }
  136. },
  137. methods: {
  138. // 保存按钮回调
  139. handleSave() {
  140. if (!this.selectedWeeks.length) {
  141. uni.showToast({
  142. title: "请选择需要打卡的星期",
  143. icon: 'none'
  144. })
  145. return
  146. }
  147. if (!this.list.length) {
  148. uni.showToast({
  149. title: "请添加需要打卡的时间段",
  150. icon: 'none'
  151. })
  152. return
  153. }
  154. uni.showModal({
  155. title: '提示',
  156. content: '确定保存吗?',
  157. success: (res) => {
  158. if (res.confirm) {
  159. uni.showToast({
  160. title: "保存成功",
  161. icon: 'success'
  162. })
  163. setTimeout(() => {
  164. let temList = uni.getStorageSync("ruleTime") || []
  165. // console.log(temList);
  166. temList.push({
  167. selectedWeeks: this.selectedWeeks,
  168. list: this.list,
  169. holiday: this.holiday
  170. })
  171. uni.setStorageSync("ruleTime", temList)
  172. uni.navigateBack({
  173. delta: 1
  174. })
  175. }, 1500)
  176. } else if (res.cancel) {}
  177. }
  178. });
  179. },
  180. // 选择星期回调
  181. changeWeek(value) {
  182. // 把0变成7
  183. value = value.map((ele) => {
  184. if (ele == 0) {
  185. return ele = 7
  186. } else {
  187. return ele
  188. }
  189. })
  190. // 从小到大排序
  191. value.sort((a, b) => {
  192. return a - b
  193. })
  194. // 把数字转换成星期
  195. let arr = ["", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
  196. this.selectedWeeks = value.map((ele) => {
  197. return ele = arr[ele]
  198. })
  199. },
  200. // 选择时间段回调
  201. bindTimeChange(e, val, item) {
  202. if (val == 1) {
  203. item.startTime = e.detail.value
  204. } else {
  205. item.endTime = e.detail.value
  206. }
  207. },
  208. // 添加时段回调
  209. handleAddTime() {
  210. this.list.push({
  211. startTime: "00:00",
  212. endTime: "00:00",
  213. })
  214. },
  215. // switch改变回调
  216. switchChange(e) {
  217. // console.log('switch1 发生 change 事件,携带值为', e.detail.value)
  218. this.holiday = e.detail.value
  219. },
  220. // 点击右侧删除按钮回调
  221. onClick(index) {
  222. // console.log(index);
  223. uni.showModal({
  224. title: '提示',
  225. content: '确定删除该打卡时间段吗?',
  226. success: (res) => {
  227. if (res.confirm) {
  228. this.list.splice(index, 1)
  229. uni.showToast({
  230. title: "删除成功",
  231. icon: 'success'
  232. })
  233. } else if (res.cancel) {}
  234. }
  235. });
  236. },
  237. }
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .container {
  242. padding-top: 33rpx;
  243. .week_title {
  244. margin-left: 35rpx;
  245. font-size: 34rpx;
  246. font-weight: 500;
  247. }
  248. .week {
  249. margin: 0 auto;
  250. margin-top: 12rpx;
  251. width: 690rpx;
  252. height: 107rpx;
  253. border-radius: 10rpx;
  254. background-color: #fff;
  255. }
  256. .time_list {
  257. display: flex;
  258. align-items: center;
  259. margin: 0 auto;
  260. margin-top: 32rpx;
  261. width: 690rpx;
  262. height: 60rpx;
  263. font-weight: 500;
  264. .title {
  265. flex: 4;
  266. font-size: 34rpx;
  267. }
  268. .add {
  269. flex: 1;
  270. text-align: end;
  271. font-size: 24rpx;
  272. color: #3396FB;
  273. }
  274. }
  275. .list {
  276. margin: 0 auto;
  277. margin-top: 13rpx;
  278. padding-top: 20rpx;
  279. padding-bottom: 20rpx;
  280. width: 690rpx;
  281. border-radius: 10rpx;
  282. background-color: #fff;
  283. .item {
  284. display: flex;
  285. justify-content: space-between;
  286. margin: 0 20rpx 20rpx 20rpx;
  287. width: 650rpx;
  288. height: 60rpx;
  289. .item_box {
  290. width: 291rpx;
  291. height: 60rpx;
  292. border-radius: 8rpx;
  293. border: 1rpx solid #CCCCCC;
  294. .uni-input {
  295. display: flex;
  296. align-items: center;
  297. width: 291rpx;
  298. height: 60rpx;
  299. .input_time {
  300. flex: 2;
  301. margin-left: 34rpx;
  302. font-size: 28rpx;
  303. color: #707070;
  304. }
  305. .input_icon {
  306. flex: 1;
  307. display: flex;
  308. justify-content: center;
  309. align-items: center;
  310. img {
  311. width: 26rpx;
  312. height: 26rpx;
  313. }
  314. }
  315. }
  316. }
  317. }
  318. // .edit {
  319. // margin-left: 20rpx;
  320. // padding-top: 10rpx;
  321. // width: 70rpx;
  322. // height: 60rpx;
  323. // color: #3396FB;
  324. // font-size: 24rpx;
  325. // font-weight: 500;
  326. // }
  327. }
  328. .switch {
  329. box-sizing: border-box;
  330. display: flex;
  331. align-items: center;
  332. margin: 0 auto;
  333. margin-top: 20rpx;
  334. padding: 0 20rpx;
  335. width: 690rpx;
  336. height: 86rpx;
  337. border-radius: 10rpx;
  338. background: #FFFFFF;
  339. .switch_title {
  340. flex: 5;
  341. font-size: 34rpx;
  342. font-weight: 500;
  343. }
  344. .switch_button {
  345. flex: 1;
  346. }
  347. }
  348. .button {
  349. margin: 0 auto;
  350. margin-top: 50rpx;
  351. width: 690rpx;
  352. height: 80rpx;
  353. line-height: 80rpx;
  354. text-align: center;
  355. color: #fff;
  356. font-size: 32rpx;
  357. border-radius: 16rpx;
  358. background-color: #3396FB;
  359. }
  360. }
  361. // 选择星期区域圆角效果
  362. ::v-deep .weeks-outer {
  363. border-radius: 10rpx;
  364. }
  365. // 解决左滑区域突出问题
  366. ::v-deep .uni-swipe_button-group {
  367. margin-bottom: 20rpx;
  368. }
  369. </style>