punchLocation.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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">
  21. <view class="icon">
  22. <img src="../static/imgs/location2.png">
  23. </view>
  24. <view class="place">
  25. <view class="top">
  26. {{item.name}}
  27. </view>
  28. <view class="center">
  29. 地址:{{item.name}}
  30. </view>
  31. <view class="bottom">
  32. 范围:{{item.radius}}米
  33. </view>
  34. </view>
  35. <view class="right">
  36. <img src="../static/imgs/right.png">
  37. </view>
  38. </view>
  39. </uni-swipe-action-item>
  40. </uni-swipe-action>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. // 地点数组
  49. list: [],
  50. // 左滑选项配置
  51. options: [{
  52. text: '删除',
  53. style: {
  54. backgroundColor: '#D43030'
  55. }
  56. }],
  57. }
  58. },
  59. onLoad(options) {
  60. if (options.locations) {
  61. this.list = JSON.parse(options.locations)
  62. uni.setStorageSync("chooseList", this.list)
  63. }
  64. },
  65. onShow() {
  66. uni.removeStorageSync("flag_place")
  67. let arr = uni.getStorageSync("chooseList")
  68. if (arr) {
  69. this.list = arr
  70. }
  71. if (arr.lenght == 0) {
  72. uni.setStorageSync("flag_place", true)
  73. }
  74. },
  75. methods: {
  76. // 点击添加打卡位置回调
  77. handleAdd() {
  78. // 获取用户位置权限
  79. uni.authorize({
  80. scope: 'scope.userLocation',
  81. success: () => {
  82. uni.navigateTo({
  83. url: `/pagesClockIn/addLocation/addLocation`
  84. })
  85. },
  86. fail() {
  87. uni.showModal({
  88. title: '提示',
  89. content: '请先开启定位权限,否则将无法使用定位功能',
  90. cancelText: '不授权',
  91. confirmText: '授权',
  92. success: function(res) {
  93. if (res.confirm) {
  94. uni.openSetting({
  95. success(res) {}
  96. })
  97. }
  98. }
  99. });
  100. }
  101. })
  102. },
  103. // 点击右侧删除按钮回调
  104. onClick(index) {
  105. uni.showModal({
  106. title: '提示',
  107. content: '确定删除该打卡位置吗?',
  108. success: (res) => {
  109. if (res.confirm) {
  110. uni.showToast({
  111. title: "删除成功",
  112. icon: 'success'
  113. })
  114. this.list.splice(index, 1)
  115. if (this.list.length == 0) {
  116. uni.setStorageSync("flag_place", true)
  117. }
  118. uni.setStorageSync("chooseList", this.list)
  119. }
  120. }
  121. });
  122. },
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .container {
  128. min-width: 100vw;
  129. min-height: 100vh;
  130. background-color: #F2F2F2;
  131. .placeholder {
  132. height: 20rpx;
  133. }
  134. .add {
  135. display: flex;
  136. margin: 0 auto;
  137. width: 690rpx;
  138. height: 87rpx;
  139. line-height: 87rpx;
  140. border-radius: 14rpx;
  141. background-color: #fff;
  142. .icon {
  143. flex: 1;
  144. display: flex;
  145. justify-content: center;
  146. align-items: center;
  147. img {
  148. width: 36rpx;
  149. height: 36rpx;
  150. }
  151. }
  152. .title {
  153. flex: 3;
  154. font-size: 30rpx;
  155. color: #0082FC;
  156. }
  157. .none {
  158. flex: 5;
  159. }
  160. }
  161. .list {
  162. margin-top: 20rpx;
  163. padding-bottom: 30rpx;
  164. .box {
  165. display: flex;
  166. align-items: center;
  167. margin: 0 auto;
  168. margin-bottom: 20rpx;
  169. width: 690rpx;
  170. height: 137rpx;
  171. border-radius: 14rpx;
  172. background-color: #fff;
  173. .icon {
  174. margin-top: 10rpx;
  175. width: 75rpx;
  176. text-align: center;
  177. img {
  178. width: 40rpx;
  179. height: 40rpx;
  180. }
  181. }
  182. .place {
  183. width: 540rpx;
  184. .top {
  185. font-size: 32rpx;
  186. overflow: hidden;
  187. white-space: nowrap;
  188. text-overflow: ellipsis;
  189. }
  190. .center {
  191. font-size: 24rpx;
  192. color: #999999;
  193. overflow: hidden;
  194. white-space: nowrap;
  195. text-overflow: ellipsis;
  196. }
  197. .bottom {
  198. font-size: 24rpx;
  199. color: #999999;
  200. overflow: hidden;
  201. white-space: nowrap;
  202. text-overflow: ellipsis;
  203. }
  204. }
  205. .right {
  206. width: 75rpx;
  207. text-align: center;
  208. img {
  209. width: 15rpx;
  210. height: 28rpx;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. // 解决左滑区域突出问题
  217. ::v-deep .uni-swipe_button-group {
  218. margin-bottom: 20rpx;
  219. }
  220. </style>