signIn.vue 5.0 KB

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