signIn.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. const datas = {
  115. storeId: this.stores.id,
  116. point: {
  117. lat: this.position.latitude,
  118. lng: this.position.longitude,
  119. }
  120. }
  121. console.log(datas)
  122. validTaskPosition(datas).then(res => {
  123. if (res.status == 200) {
  124. // 跳转开始巡店
  125. let item = this.stores
  126. // 重新开始巡店
  127. if(item.taskId&&item.restart){
  128. uni.redirectTo({
  129. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&taskId='+ item.taskId + '&restart=1&types=scene'
  130. })
  131. }else{
  132. // 首次巡店
  133. uni.redirectTo({
  134. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&types=scene'
  135. })
  136. }
  137. } else {
  138. uni.showToast({ icon: 'none', title: res.message })
  139. }
  140. });
  141. },
  142. }
  143. };
  144. </script>
  145. <style lang="scss" scoped>
  146. page {
  147. background-color: #f8f8f8;
  148. height: calc(100vh - 44px);
  149. }
  150. .signIn-wrap {
  151. height: 100%;
  152. background-color: #f8f8f8;
  153. .module-con {
  154. padding: 0 30upx 20upx;
  155. .info-main {
  156. margin-top: 14upx;
  157. padding: 20upx;
  158. border-radius: 12upx;
  159. background-color: #fff;
  160. .location-icon {
  161. padding-left: 10upx;
  162. vertical-align: bottom;
  163. }
  164. .photograph-con {
  165. border: 2upx dashed #bfbfbf;
  166. border-radius: 12upx;
  167. width: 160upx;
  168. height: 160upx;
  169. text-align: center;
  170. position: relative;
  171. .photograph-icon {
  172. display: inline-block;
  173. padding-top: 48upx;
  174. }
  175. .close-circle-icon {
  176. background-color: #fff;
  177. border-radius: 50%;
  178. position: absolute;
  179. right: -23upx;
  180. top: -23upx;
  181. z-index: 9;
  182. }
  183. }
  184. }
  185. }
  186. .first-con {
  187. padding-top: 30upx;
  188. }
  189. .submit-btn {
  190. width: 80%;
  191. margin-top: 50upx;
  192. }
  193. }
  194. </style>