punchTime.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="container">
  3. <view class="placeholder"></view>
  4. <!-- 头部添加打卡时间区域 -->
  5. <view class="add">
  6. <view class="icon" @click="handleAdd">
  7. <img src="../static/imgs/add.png">
  8. </view>
  9. <view class="title" @click="handleAdd">
  10. 添加打卡时间
  11. </view>
  12. <view class="none"></view>
  13. </view>
  14. <!-- 打卡时间列表 -->
  15. <view class="list">
  16. <uni-swipe-action>
  17. <!-- 每一个时间段区域 -->
  18. <uni-swipe-action-item :auto-close="true" :right-options="options" @click="onClick(index)"
  19. v-for="(item,index) in list" :key="index">
  20. <view class="box" @click="handleEdit(item,index)">
  21. <view class="left">
  22. <view class="week">
  23. <view class="key">
  24. 星期
  25. </view>
  26. <view class="value">
  27. <span v-for="(item_week,index_week) in item.dayOfWeeks" :key="index_week">
  28. {{arr[item_week]}}
  29. </span>
  30. </view>
  31. </view>
  32. <view class="week">
  33. <view class="key">
  34. 时段
  35. </view>
  36. <view class="value">
  37. <span v-for="(item_time,index_time) in item.periods" :key="index_time">
  38. {{format_time(item_time.beginTime)}}-{{format_time(item_time.endTime)}}
  39. </span>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="right">
  44. <img src="../static/imgs/right.png">
  45. </view>
  46. </view>
  47. </uni-swipe-action-item>
  48. </uni-swipe-action>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. // 时间数组
  57. list: [],
  58. // 左滑选项配置
  59. options: [{
  60. text: '删除',
  61. style: {
  62. backgroundColor: '#D43030'
  63. }
  64. }],
  65. // 星期映射数组
  66. arr: ["", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
  67. }
  68. },
  69. onLoad(options) {
  70. if (options.time) {
  71. if (JSON.parse(options.time) != '未设置') {
  72. this.list = JSON.parse(options.time)
  73. uni.setStorageSync("ruleTime", this.list)
  74. }
  75. }
  76. },
  77. onShow() {
  78. uni.removeStorageSync("flag")
  79. let ruleTime = uni.getStorageSync("ruleTime")
  80. if (ruleTime) {
  81. this.list = ruleTime
  82. }
  83. if (ruleTime.lenght == 0) {
  84. uni.setStorageSync("flag", true)
  85. }
  86. },
  87. methods: {
  88. // 点击添加打卡时间回调 跳转到添加页面
  89. handleAdd() {
  90. uni.navigateTo({
  91. url: `/pagesClockIn/setPunchTime/setPunchTime?flag=1`
  92. })
  93. },
  94. // 点击每一个时间段回调 跳转到编辑页面
  95. handleEdit(item, index) {
  96. let info = JSON.stringify(item)
  97. uni.navigateTo({
  98. url: `/pagesClockIn/setPunchTime/setPunchTime?flag=2&info=${info}&index=${index}`
  99. })
  100. },
  101. // 点击右侧删除按钮回调
  102. onClick(index) {
  103. // console.log(index);
  104. uni.showModal({
  105. title: '提示',
  106. content: '确定删除该打卡时间吗?',
  107. success: (res) => {
  108. if (res.confirm) {
  109. uni.showToast({
  110. title: "删除成功",
  111. icon: 'success'
  112. })
  113. this.list.splice(index, 1)
  114. if (this.list.length == 0) {
  115. uni.setStorageSync("flag", true)
  116. }
  117. uni.setStorageSync("ruleTime", this.list)
  118. } else if (res.cancel) {}
  119. }
  120. });
  121. },
  122. // 格式化时间
  123. format_time(timestamp) {
  124. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  125. var date = new Date(timestamp);
  126. var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  127. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  128. let strDate = h + m;
  129. return strDate;
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .container {
  136. min-width: 100vw;
  137. min-height: 100vh;
  138. background-color: #F2F2F2;
  139. .placeholder {
  140. height: 20rpx;
  141. }
  142. .add {
  143. display: flex;
  144. margin: 0 auto;
  145. width: 690rpx;
  146. height: 87rpx;
  147. line-height: 87rpx;
  148. border-radius: 14rpx;
  149. background-color: #fff;
  150. .icon {
  151. flex: 1;
  152. display: flex;
  153. justify-content: center;
  154. align-items: center;
  155. img {
  156. width: 36rpx;
  157. height: 36rpx;
  158. }
  159. }
  160. .title {
  161. flex: 3;
  162. font-size: 30rpx;
  163. color: #0082FC;
  164. }
  165. .none {
  166. flex: 5;
  167. }
  168. }
  169. .list {
  170. margin-top: 20rpx;
  171. padding-bottom: 30rpx;
  172. .box {
  173. display: flex;
  174. margin: 0 auto;
  175. margin-bottom: 20rpx;
  176. width: 690rpx;
  177. height: 132rpx;
  178. border-radius: 14rpx;
  179. background-color: #fff;
  180. overflow: hidden;
  181. .left {
  182. display: flex;
  183. flex-direction: column;
  184. margin-left: 17rpx;
  185. width: 492rpx;
  186. .week {
  187. flex: 1;
  188. display: flex;
  189. align-items: center;
  190. font-size: 24rpx;
  191. .key {
  192. flex: 1;
  193. margin-left: 8rpx;
  194. color: #A6A6A6;
  195. }
  196. .value {
  197. flex: 5;
  198. overflow: hidden;
  199. white-space: nowrap;
  200. text-overflow: ellipsis;
  201. span {
  202. margin-right: 10rpx;
  203. }
  204. }
  205. }
  206. }
  207. .right {
  208. display: flex;
  209. justify-content: flex-end;
  210. align-items: center;
  211. width: 198rpx;
  212. img {
  213. margin-right: 20rpx;
  214. width: 20rpx;
  215. height: 30rpx;
  216. }
  217. }
  218. }
  219. }
  220. }
  221. // 解决左滑区域突出问题
  222. ::v-deep .uni-swipe_button-group {
  223. margin-bottom: 20rpx;
  224. }
  225. </style>