signIn.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. // 判断是否超出签到范围
  86. validTaskPosition({
  87. storeId: this.stores.id,
  88. lat: this.position.latitude,
  89. lng: this.position.longitude
  90. }).then(res => {
  91. if (res.status == 200) {
  92. // 跳转开始巡店
  93. uni.redirectTo({
  94. url: '/pages/shopTour/shopTour?storeId=' + this.stores.id + '&types=scene'
  95. })
  96. uni.$emit("closeTour",1)
  97. } else {
  98. this.isOutRange();
  99. }
  100. });
  101. },
  102. // 超出范围 提示
  103. isOutRange() {
  104. clzConfirm({
  105. title: '提示',
  106. content: '您所在的位置超出门店签到范围,无法开启巡店!',
  107. showCancel: false,
  108. success: function(res) {
  109. if (res.confirm || res.index == 0) {
  110. }
  111. }
  112. });
  113. },
  114. // 预览签到图
  115. previewPictures() {
  116. const photograph = [this.photograph];
  117. uni.previewImage({
  118. urls: photograph
  119. });
  120. },
  121. // 删除签到图
  122. cancelPhotograph() {
  123. setTimeout(() => {
  124. this.photograph = '';
  125. }, 500);
  126. }
  127. }
  128. };
  129. </script>
  130. <style lang="scss" scoped>
  131. page {
  132. background-color: #f8f8f8;
  133. height: calc(100vh - 44px);
  134. }
  135. .signIn-wrap {
  136. height: 100%;
  137. .module-con {
  138. padding: 0 30upx 20upx;
  139. .info-main {
  140. margin-top: 14upx;
  141. padding: 20upx;
  142. border-radius: 12upx;
  143. background-color: #fff;
  144. .location-icon {
  145. padding-left: 10upx;
  146. vertical-align: bottom;
  147. }
  148. .photograph-con {
  149. border: 2upx dashed #bfbfbf;
  150. border-radius: 12upx;
  151. width: 160upx;
  152. height: 160upx;
  153. text-align: center;
  154. position: relative;
  155. .photograph-icon {
  156. display: inline-block;
  157. padding-top: 48upx;
  158. }
  159. .close-circle-icon {
  160. background-color: #fff;
  161. border-radius: 50%;
  162. position: absolute;
  163. right: -23upx;
  164. top: -23upx;
  165. z-index: 9;
  166. }
  167. }
  168. }
  169. }
  170. .first-con {
  171. padding-top: 30upx;
  172. }
  173. .submit-btn {
  174. width: 80%;
  175. margin-top: 50upx;
  176. }
  177. }
  178. </style>