signIn.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="signIn-wrap">
  3. <!-- 门店名称 -->
  4. <view class="module-con first-con">
  5. <text class="info-tit">门店名称:</text>
  6. <view class="info-main">
  7. <text class="location-addr">{{ stores && stores.name }}</text>
  8. </view>
  9. </view>
  10. <!-- 定位 -->
  11. <view class="module-con">
  12. <text class="info-tit">当前位置:</text>
  13. <view class="info-main" @click="getLocation">
  14. <text class="location-addr">{{ location }}</text>
  15. <u-icon name="map" color="#2979ff" size="34" class="location-icon"></u-icon>
  16. </view>
  17. </view>
  18. <!-- 拍照签到 -->
  19. <view class="module-con">
  20. <text class="info-tit">拍照签到:</text>
  21. <view class="info-main">
  22. <view class="photograph-con" @click="photograph ? null : goPhotograph()">
  23. <u-icon v-show="photograph" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph"></u-icon>
  24. <u-icon v-show="!photograph" name="camera" color="#bfbfbf" size="60" class="photograph-icon"></u-icon>
  25. <u-image v-show="photograph" width="100%" height="100%" :src="photograph" @click="previewPictures"></u-image>
  26. </view>
  27. </view>
  28. </view>
  29. <u-button type="primary" class="submit-btn" @click="signInFun">签到并开始巡店</u-button>
  30. </view>
  31. </template>
  32. <script>
  33. import { clzConfirm } from '@/libs/tools.js';
  34. import { validTaskPosition } from '@/api/task.js';
  35. export default {
  36. data() {
  37. return {
  38. stores: null, // 门店信息
  39. location: '', // 当前位置地址
  40. photograph: '', // 拍照
  41. position: null // 位置信息
  42. };
  43. },
  44. onShow() {
  45. this.init();
  46. },
  47. onLoad(opts) {
  48. this.stores = JSON.parse(opts.item);
  49. },
  50. methods: {
  51. // 初始化
  52. init() {
  53. this.getLocation();
  54. },
  55. // 获取当前位置
  56. getLocation() {
  57. const _this = this;
  58. uni.getLocation({
  59. type: 'gcj02',
  60. geocode: true,
  61. success: function(res) {
  62. console.log(res);
  63. // _this.location = res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum +'靠近' + res.address.poiName
  64. // console.log(_this.location, '城市编码 ', res.address.cityCode)
  65. _this.position = res;
  66. }
  67. });
  68. },
  69. // 签到拍照
  70. goPhotograph() {
  71. const _this = this;
  72. uni.chooseImage({
  73. count: 1, //最多可以选择的图片张数,默认9
  74. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  75. sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  76. success: function(res) {
  77. // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  78. console.log(JSON.stringify(res.tempFilePaths));
  79. _this.photograph = res.tempFilePaths[0];
  80. }
  81. });
  82. },
  83. // 签到
  84. signInFun() {
  85. if(!this.position.latitude || !this.position.longitude){
  86. uni.showToast({ icon: 'none', title: '位置获取失败,请重新定位后再进行签到' })
  87. return
  88. }else if(!this.photograph){
  89. uni.showToast({ icon: 'none', title: '请拍照后再进行签到' })
  90. return
  91. }
  92. // 判断是否超出签到范围
  93. validTaskPosition({
  94. storeId: this.stores.id,
  95. lat: this.position.latitude,
  96. lng: this.position.longitude
  97. }).then(res => {
  98. if (res.status == 200) {
  99. // 跳转开始巡店
  100. uni.redirectTo({
  101. url: '/pages/shopTour/shopTour?storeId=' + this.stores.id + '&types=scene'
  102. })
  103. uni.$emit("closeTour",1)
  104. } else {
  105. this.isOutRange();
  106. }
  107. });
  108. },
  109. // 超出范围 提示
  110. isOutRange() {
  111. clzConfirm({
  112. title: '提示',
  113. content: '您所在的位置超出门店签到范围,无法开启巡店!',
  114. showCancel: false,
  115. success: function(res) {
  116. if (res.confirm || res.index == 0) {
  117. }
  118. }
  119. });
  120. },
  121. // 预览签到图
  122. previewPictures() {
  123. const photograph = [this.photograph];
  124. uni.previewImage({
  125. urls: photograph
  126. });
  127. },
  128. // 删除签到图
  129. cancelPhotograph() {
  130. setTimeout(() => {
  131. this.photograph = '';
  132. }, 500);
  133. }
  134. }
  135. };
  136. </script>
  137. <style lang="scss" scoped>
  138. page {
  139. background-color: #f8f8f8;
  140. height: calc(100vh - 44px);
  141. }
  142. .signIn-wrap {
  143. height: 100%;
  144. .module-con {
  145. padding: 0 30upx 20upx;
  146. .info-main {
  147. margin-top: 14upx;
  148. padding: 20upx;
  149. border-radius: 12upx;
  150. background-color: #fff;
  151. .location-icon {
  152. padding-left: 10upx;
  153. vertical-align: bottom;
  154. }
  155. .photograph-con {
  156. border: 2upx dashed #bfbfbf;
  157. border-radius: 12upx;
  158. width: 160upx;
  159. height: 160upx;
  160. text-align: center;
  161. position: relative;
  162. .photograph-icon {
  163. display: inline-block;
  164. padding-top: 48upx;
  165. }
  166. .close-circle-icon {
  167. background-color: #fff;
  168. border-radius: 50%;
  169. position: absolute;
  170. right: -23upx;
  171. top: -23upx;
  172. z-index: 9;
  173. }
  174. }
  175. }
  176. }
  177. .first-con {
  178. padding-top: 30upx;
  179. }
  180. .submit-btn {
  181. width: 80%;
  182. margin-top: 50upx;
  183. }
  184. }
  185. </style>