signIn.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.position = res;
  64. _this.location = res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum +'靠近' + res.address.poiName
  65. // console.log(_this.location, '城市编码 ', res.address.cityCode)
  66. },
  67. fail: function(error){
  68. console.log(error)
  69. if(JSON.parse(error.errMsg.replace('getLocation:fail ','')).message){
  70. uni.showToast({
  71. icon: 'none',
  72. title: JSON.parse(error.errMsg.replace('getLocation:fail ','')).message
  73. })
  74. }
  75. }
  76. });
  77. },
  78. // 签到拍照
  79. goPhotograph() {
  80. const _this = this;
  81. uni.chooseImage({
  82. count: 1, //最多可以选择的图片张数,默认9
  83. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  84. sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  85. success: function(res) {
  86. // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  87. console.log(JSON.stringify(res.tempFilePaths));
  88. _this.photograph = res.tempFilePaths[0];
  89. }
  90. });
  91. },
  92. // 预览签到图
  93. previewPictures() {
  94. const photograph = [this.photograph];
  95. uni.previewImage({
  96. urls: photograph
  97. });
  98. },
  99. // 删除签到图
  100. cancelPhotograph() {
  101. setTimeout(() => {
  102. this.photograph = '';
  103. }, 500);
  104. },
  105. // 签到
  106. signInFun() {
  107. if(!this.position || !this.position.latitude || !this.position.longitude){
  108. uni.showToast({ icon: 'none', title: '位置获取失败,请重新定位后再进行签到' })
  109. return
  110. }else if(!this.photograph){
  111. uni.showToast({ icon: 'none', title: '请拍照后再进行签到' })
  112. return
  113. }
  114. // 判断是否超出签到范围
  115. validTaskPosition({
  116. storeId: this.stores.id,
  117. point: {
  118. lat: this.position.latitude,
  119. lng: this.position.longitude,
  120. }
  121. }).then(res => {
  122. if (res.status == 200) {
  123. // 跳转开始巡店
  124. uni.redirectTo({
  125. url: '/pages/shopTour/shopTour?storeId=' + this.stores.id + '&types=scene'
  126. })
  127. } else {
  128. uni.showToast({ icon: 'none', title: res.message })
  129. }
  130. });
  131. },
  132. }
  133. };
  134. </script>
  135. <style lang="scss" scoped>
  136. page {
  137. background-color: #f8f8f8;
  138. height: calc(100vh - 44px);
  139. }
  140. .signIn-wrap {
  141. height: 100%;
  142. background-color: #f8f8f8;
  143. .module-con {
  144. padding: 0 30upx 20upx;
  145. .info-main {
  146. margin-top: 14upx;
  147. padding: 20upx;
  148. border-radius: 12upx;
  149. background-color: #fff;
  150. .location-icon {
  151. padding-left: 10upx;
  152. vertical-align: bottom;
  153. }
  154. .photograph-con {
  155. border: 2upx dashed #bfbfbf;
  156. border-radius: 12upx;
  157. width: 160upx;
  158. height: 160upx;
  159. text-align: center;
  160. position: relative;
  161. .photograph-icon {
  162. display: inline-block;
  163. padding-top: 48upx;
  164. }
  165. .close-circle-icon {
  166. background-color: #fff;
  167. border-radius: 50%;
  168. position: absolute;
  169. right: -23upx;
  170. top: -23upx;
  171. z-index: 9;
  172. }
  173. }
  174. }
  175. }
  176. .first-con {
  177. padding-top: 30upx;
  178. }
  179. .submit-btn {
  180. width: 80%;
  181. margin-top: 50upx;
  182. }
  183. }
  184. </style>