punchTime.vue 4.9 KB

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