punchTime.vue 5.0 KB

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