punchLocation.vue 4.6 KB

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