punchLocation.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. uni.showToast({
  118. title: "删除成功",
  119. icon: 'success'
  120. })
  121. this.list.splice(index, 1)
  122. if (this.type == 1) {
  123. uni.setStorageSync("chooseList_edit", this.list)
  124. } else {
  125. uni.setStorageSync("chooseList", this.list)
  126. }
  127. var flag = uni.getStorageSync("chooseList")
  128. if (flag == []) {
  129. uni.setStorageSync("flag_place", true)
  130. }
  131. } else if (res.cancel) {}
  132. }
  133. });
  134. },
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .container {
  140. padding-top: 20rpx;
  141. .add {
  142. display: flex;
  143. margin: 0 auto;
  144. width: 690rpx;
  145. height: 87rpx;
  146. line-height: 87rpx;
  147. border-radius: 14rpx;
  148. background-color: #fff;
  149. .icon {
  150. flex: 1;
  151. display: flex;
  152. justify-content: center;
  153. align-items: center;
  154. img {
  155. width: 36rpx;
  156. height: 36rpx;
  157. }
  158. }
  159. .title {
  160. flex: 3;
  161. font-size: 30rpx;
  162. color: #0082FC;
  163. }
  164. .none {
  165. flex: 5;
  166. }
  167. }
  168. .list {
  169. margin-top: 20rpx;
  170. padding-bottom: 30rpx;
  171. .box {
  172. display: flex;
  173. align-items: center;
  174. margin: 0 auto;
  175. margin-bottom: 20rpx;
  176. width: 690rpx;
  177. height: 137rpx;
  178. border-radius: 14rpx;
  179. background-color: #fff;
  180. .icon {
  181. margin-top: 10rpx;
  182. width: 75rpx;
  183. text-align: center;
  184. img {
  185. width: 40rpx;
  186. height: 40rpx;
  187. }
  188. }
  189. .place {
  190. width: 540rpx;
  191. .top {
  192. font-size: 32rpx;
  193. overflow: hidden;
  194. white-space: nowrap;
  195. text-overflow: ellipsis;
  196. }
  197. .center {
  198. font-size: 24rpx;
  199. color: #999999;
  200. overflow: hidden;
  201. white-space: nowrap;
  202. text-overflow: ellipsis;
  203. }
  204. .bottom {
  205. font-size: 24rpx;
  206. color: #999999;
  207. overflow: hidden;
  208. white-space: nowrap;
  209. text-overflow: ellipsis;
  210. }
  211. }
  212. .right {
  213. width: 75rpx;
  214. text-align: center;
  215. img {
  216. width: 15rpx;
  217. height: 28rpx;
  218. }
  219. }
  220. }
  221. }
  222. }
  223. // 解决左滑区域突出问题
  224. ::v-deep .uni-swipe_button-group {
  225. margin-bottom: 20rpx;
  226. }
  227. </style>