punchTime.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. type: "",
  55. options: [{
  56. text: '删除',
  57. style: {
  58. backgroundColor: '#D43030'
  59. }
  60. }],
  61. }
  62. },
  63. onLoad(options) {
  64. this.type = options.type
  65. if (options.time) {
  66. let time = JSON.parse(options.time)
  67. let periods = JSON.parse(options.periods)
  68. console.log(time);
  69. console.log(periods);
  70. // let temArr = []
  71. // periods.forEach((ele) => {
  72. // temArr.push({
  73. // beginTime: this.format_time(ele.beginTime),
  74. // endTime: this.format_time(ele.endTime)
  75. // })
  76. // })
  77. // periods = temArr
  78. let temList = []
  79. temList.push({
  80. selectedWeeks: time,
  81. list: periods
  82. })
  83. this.list = temList
  84. uni.setStorageSync("ruleTime_edit", this.list)
  85. }
  86. },
  87. onShow() {
  88. let ruleTime = uni.getStorageSync("ruleTime_edit")
  89. if (ruleTime) {
  90. this.list = ruleTime
  91. }
  92. },
  93. methods: {
  94. // 点击添加打卡时间回调 跳转到添加页面
  95. handleAdd() {
  96. uni.navigateTo({
  97. url: `/pages/setPunchTime/setPunchTime?flag=1&type=${this.type}`
  98. })
  99. },
  100. // 点击每一个时间段回调 跳转到编辑页面
  101. handleEdit(item, index) {
  102. let info = JSON.stringify(item)
  103. uni.navigateTo({
  104. url: `/pages/setPunchTime/setPunchTime?flag=2&info=${info}&index=${index}`
  105. })
  106. },
  107. // 点击右侧删除按钮回调
  108. onClick(index) {
  109. // console.log(index);
  110. uni.showModal({
  111. title: '提示',
  112. content: '确定删除该打卡时间吗?',
  113. success: (res) => {
  114. if (res.confirm) {
  115. uni.showToast({
  116. title: "删除成功",
  117. icon: 'success'
  118. })
  119. this.list.splice(index, 1)
  120. if (this.type == 1) {
  121. uni.setStorageSync("ruleTime_edit", this.list)
  122. } else {
  123. uni.setStorageSync("ruleTime", this.list)
  124. }
  125. var flag = uni.getStorageSync("ruleTime")
  126. if (flag == []) {
  127. uni.setStorageSync("flag", true)
  128. }
  129. } else if (res.cancel) {}
  130. }
  131. });
  132. },
  133. // 格式化时间
  134. // format_time(timestamp) {
  135. // //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  136. // var date = new Date(timestamp);
  137. // var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  138. // var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
  139. // let strDate = h + m;
  140. // return strDate;
  141. // }
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .container {
  147. padding-top: 20rpx;
  148. .add {
  149. display: flex;
  150. margin: 0 auto;
  151. width: 690rpx;
  152. height: 87rpx;
  153. line-height: 87rpx;
  154. border-radius: 14rpx;
  155. background-color: #fff;
  156. .icon {
  157. flex: 1;
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. img {
  162. width: 36rpx;
  163. height: 36rpx;
  164. }
  165. }
  166. .title {
  167. flex: 3;
  168. font-size: 30rpx;
  169. color: #0082FC;
  170. }
  171. .none {
  172. flex: 5;
  173. }
  174. }
  175. .list {
  176. margin-top: 20rpx;
  177. padding-bottom: 30rpx;
  178. .box {
  179. display: flex;
  180. margin: 0 auto;
  181. margin-bottom: 20rpx;
  182. width: 690rpx;
  183. height: 132rpx;
  184. border-radius: 14rpx;
  185. background-color: #fff;
  186. overflow: hidden;
  187. .left {
  188. display: flex;
  189. flex-direction: column;
  190. margin-left: 17rpx;
  191. width: 492rpx;
  192. .week {
  193. flex: 1;
  194. display: flex;
  195. align-items: center;
  196. font-size: 24rpx;
  197. .key {
  198. flex: 1;
  199. margin-left: 8rpx;
  200. color: #A6A6A6;
  201. }
  202. .value {
  203. flex: 5;
  204. overflow: hidden;
  205. white-space: nowrap;
  206. text-overflow: ellipsis;
  207. span {
  208. margin-right: 10rpx;
  209. }
  210. }
  211. }
  212. }
  213. .right {
  214. display: flex;
  215. justify-content: flex-end;
  216. align-items: center;
  217. width: 198rpx;
  218. img {
  219. margin-right: 20rpx;
  220. width: 20rpx;
  221. height: 30rpx;
  222. }
  223. }
  224. }
  225. }
  226. }
  227. // 解决左滑区域突出问题
  228. ::v-deep .uni-swipe_button-group {
  229. margin-bottom: 20rpx;
  230. }
  231. </style>