signIn.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. <view class="info-tit">
  13. <text class="require-tip"></text>
  14. 当前位置:
  15. </view>
  16. <view class="info-main" @click="getLocation">
  17. <text class="location-addr">{{ location }}</text>
  18. <u-icon name="map" color="#2979ff" size="34" class="location-icon"></u-icon>
  19. </view>
  20. </view>
  21. <!-- 拍照签到 -->
  22. <view class="module-con">
  23. <view class="info-tit">
  24. <text class="require-tip"></text>
  25. 拍照签到:
  26. </view>
  27. <view class="info-main">
  28. <view class="photograph-con" @click="photograph ? null : goPhotograph()">
  29. <u-icon v-show="photograph" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph"></u-icon>
  30. <u-icon v-show="!photograph" name="camera" color="#bfbfbf" size="60" class="photograph-icon"></u-icon>
  31. <u-image v-show="photograph" width="100%" height="100%" :src="photograph" @click="previewPictures"></u-image>
  32. </view>
  33. </view>
  34. </view>
  35. <u-button type="primary" :style="{background: $config('buttonColors')}" class="submit-btn" @click="signInFun">签到并开始巡店</u-button>
  36. </view>
  37. </template>
  38. <script>
  39. import { clzConfirm, saveImgToAliOss,getGpsLocation } from '@/libs/tools.js';
  40. import { validTaskPosition, tencentAddressInfo } from '@/api/task.js';
  41. export default {
  42. data() {
  43. return {
  44. stores: null, // 门店信息
  45. location: '', // 当前位置地址
  46. photograph: '', // 拍照临时地址
  47. position: null // 位置信息
  48. };
  49. },
  50. onShow() {
  51. this.init();
  52. },
  53. onLoad(opts) {
  54. this.stores = JSON.parse(opts.item);
  55. },
  56. methods: {
  57. // 初始化
  58. init() {
  59. this.getLocation();
  60. },
  61. // 获取当前位置
  62. getLocation() {
  63. const _this = this;
  64. // 获取系统信息同步接口
  65. const res = uni.getSystemInfoSync()
  66. getGpsLocation(function(gps){
  67. console.log(gps)
  68. // 安卓手机需要转格式,ios不需要
  69. if(res.platform == 'android'){ // 安卓
  70. _this.position = { latitude: gps[1], longitude: gps[0] }
  71. // 反解析拿到地址
  72. _this.getAddressInfo({ lat: gps[1], lng: gps[0] })
  73. }else if(res.platform == 'ios'){ // ios
  74. _this.position = { latitude: gps.latitude, longitude: gps.longitude }
  75. const province = gps.address.province ? gps.address.province : '' // 省份名称
  76. const city = gps.address.city ? gps.address.city : '' // 城市名称
  77. const district = gps.address.district ? gps.address.district : '' // 区(县)名称
  78. const poiName = gps.address.poiName ? gps.address.poiName : '' // POI信息
  79. const street = gps.address.street ? gps.address.street : '' // 街道信息
  80. const streetNum = gps.address.streetNum ? gps.address.streetNum : '' // 获取街道门牌号信息
  81. _this.location = province + city + district + poiName + '(' + street + streetNum + ')'
  82. }
  83. })
  84. },
  85. // 根据经纬度获取具体位置
  86. getAddressInfo(params) {
  87. tencentAddressInfo(params).then(res => {
  88. console.log(res)
  89. if (res.status == 200) {
  90. this.location = res.data.province + res.data.city + res.data.district + res.data.address;
  91. }
  92. });
  93. },
  94. // 签到拍照
  95. goPhotograph() {
  96. const _this = this;
  97. uni.chooseImage({
  98. count: 1, //最多可以选择的图片张数,默认9
  99. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  100. sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  101. success: function(res) {
  102. // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  103. console.log(JSON.stringify(res.tempFilePaths));
  104. uni.showLoading({
  105. title: '保存中,请稍后...',
  106. mask: true
  107. })
  108. saveImgToAliOss(res.tempFilePaths[0],function(ret){
  109. console.log(ret)
  110. _this.photograph = ret.data
  111. uni.hideLoading()
  112. })
  113. }
  114. });
  115. },
  116. // 预览签到图
  117. previewPictures() {
  118. const photograph = [this.photograph];
  119. uni.previewImage({
  120. urls: photograph
  121. });
  122. },
  123. // 删除签到图
  124. cancelPhotograph() {
  125. setTimeout(() => {
  126. this.photograph = '';
  127. }, 500);
  128. },
  129. // 签到
  130. signInFun() {
  131. if(!this.position || !this.position.latitude || !this.position.longitude){
  132. uni.showToast({ icon: 'none', title: '位置获取失败,请重新定位后再进行签到' })
  133. return
  134. }else if(!this.photograph){
  135. uni.showToast({ icon: 'none', title: '请拍照后再进行签到' })
  136. return
  137. }
  138. // 存储当前签到信息
  139. this.$u.vuex('vuex_sceneTaskSignIn',{
  140. inspectorPositionAddr: this.location,
  141. inspectorPositionPhotoPath: this.photograph
  142. })
  143. // 判断是否超出签到范围
  144. const datas = {
  145. storeId: this.stores.id,
  146. point: {
  147. lat: this.position.latitude,
  148. lng: this.position.longitude,
  149. }
  150. }
  151. console.log(datas)
  152. validTaskPosition(datas).then(res => {
  153. if (res.status == 200) {
  154. // 跳转开始巡店
  155. let item = this.stores
  156. // 重新开始巡店
  157. if(item.taskId&&item.restart){
  158. uni.redirectTo({
  159. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&taskId='+ item.taskId + '&restart=1&types=scene'
  160. })
  161. }else{
  162. // 首次巡店
  163. uni.redirectTo({
  164. url: '/pages/shopTour/shopTour?storeId=' + item.id + '&types=scene'
  165. })
  166. }
  167. } else {
  168. uni.showToast({ icon: 'none', title: res.message })
  169. }
  170. });
  171. },
  172. }
  173. };
  174. </script>
  175. <style lang="scss" scoped>
  176. .signIn-wrap {
  177. height: 100vh;
  178. background-color: #f8f8f8;
  179. .module-con {
  180. padding: 0 30upx 20upx;
  181. .info-tit{
  182. .require-tip::before{
  183. content: '*';
  184. color: #F56C6C;
  185. width: 30upx;
  186. height: 30upx;
  187. display: inline-block;
  188. }
  189. }
  190. .info-main {
  191. margin-top: 14upx;
  192. padding: 20upx;
  193. border-radius: 12upx;
  194. background-color: #fff;
  195. .location-icon {
  196. padding-left: 10upx;
  197. vertical-align: sub;
  198. }
  199. .photograph-con {
  200. border: 2upx dashed #bfbfbf;
  201. border-radius: 12upx;
  202. width: 160upx;
  203. height: 160upx;
  204. text-align: center;
  205. position: relative;
  206. .photograph-icon {
  207. display: inline-block;
  208. padding-top: 48upx;
  209. }
  210. .close-circle-icon {
  211. background-color: #fff;
  212. border-radius: 50%;
  213. position: absolute;
  214. right: -23upx;
  215. top: -23upx;
  216. z-index: 9;
  217. }
  218. }
  219. }
  220. }
  221. .first-con {
  222. padding-top: 30upx;
  223. }
  224. .submit-btn {
  225. width: 80%;
  226. margin-top: 50upx;
  227. }
  228. }
  229. </style>