123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <template>
- <view class="signIn-wrap">
- <!-- 门店名称 -->
- <view class="module-con first-con">
- <text class="info-tit">门店名称:</text>
- <view class="info-main">
- <text class="location-addr">{{ stores && stores.name }}</text>
- </view>
- </view>
- <!-- 定位 -->
- <view class="module-con">
- <text class="info-tit">当前位置:</text>
- <view class="info-main" @click="getLocation">
- <text class="location-addr">{{ location }}</text>
- <u-icon name="map" color="#2979ff" size="34" class="location-icon"></u-icon>
- </view>
- </view>
- <!-- 拍照签到 -->
- <view class="module-con">
- <text class="info-tit">拍照签到:</text>
- <view class="info-main">
- <view class="photograph-con" @click="photograph ? null : goPhotograph()">
- <u-icon v-show="photograph" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph"></u-icon>
- <u-icon v-show="!photograph" name="camera" color="#bfbfbf" size="60" class="photograph-icon"></u-icon>
- <u-image v-show="photograph" width="100%" height="100%" :src="photograph" @click="previewPictures"></u-image>
- </view>
- </view>
- </view>
- <u-button type="primary" class="submit-btn" @click="signInFun">签到并开始巡店</u-button>
- </view>
- </template>
- <script>
- import { clzConfirm, saveImgToAliOss } from '@/libs/tools.js';
- import { validTaskPosition } from '@/api/task.js';
- //定义一些常量
- var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
- var PI = 3.1415926535897932384626;
- var a = 6378245.0;
- var ee = 0.00669342162296594323;
- /**
- * 判断是否在国内,不在国内则不做偏移
- * @param lng
- * @param lat
- * @returns {boolean}
- */
- function out_of_china(lng, lat) {
- return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false);
- }
- function transformlat(lng, lat) {
- var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
- ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
- ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
- ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
- return ret
- }
-
- function transformlng(lng, lat) {
- var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
- ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
- ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
- ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
- return ret
- }
- /**
- * WGS84转GCj02
- * @param lng
- * @param lat
- * @returns {*[]}
- */
- function wgs84togcj02(lng, lat) {
- if (out_of_china(lng, lat)) {
- return [lng, lat]
- }
- else {
- var dlat = transformlat(lng - 105.0, lat - 35.0);
- var dlng = transformlng(lng - 105.0, lat - 35.0);
- var radlat = lat / 180.0 * PI;
- var magic = Math.sin(radlat);
- magic = 1 - ee * magic * magic;
- var sqrtmagic = Math.sqrt(magic);
- dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
- dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
- var mglat = lat + dlat;
- var mglng = lng + dlng;
- return [mglng, mglat]
- }
- }
- export default {
- data() {
- return {
- stores: null, // 门店信息
- location: '', // 当前位置地址
- photograph: '', // 拍照临时地址
- position: null // 位置信息
- };
- },
- onShow() {
- this.init();
- },
- onLoad(opts) {
- this.stores = JSON.parse(opts.item);
- },
- methods: {
- // 初始化
- init() {
- this.getLocation();
- },
- // 获取当前位置
- getLocation() {
- const _this = this;
- uni.getLocation({
- type: 'gcj02',
- geocode: true,
- success: function(res) {
- console.log(res);
- _this.position = res;
- //_this.location = res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum +'靠近' + res.address.poiName
- // console.log(_this.location, '城市编码 ', res.address.cityCode)
- console.log(wgs84togcj02(res.longitude,res.latitude))
- },
- fail: function(error){
- console.log(error)
- if(JSON.parse(error.errMsg.replace('getLocation:fail ','')).message){
- uni.showToast({
- icon: 'none',
- title: JSON.parse(error.errMsg.replace('getLocation:fail ','')).message
- })
- }
- }
- });
- },
- // 签到拍照
- goPhotograph() {
- const _this = this;
- uni.chooseImage({
- count: 1, //最多可以选择的图片张数,默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
- success: function(res) {
- // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
- console.log(JSON.stringify(res.tempFilePaths));
- saveImgToAliOss(res.tempFilePaths[0],function(ret){
- console.log(ret)
- _this.photograph = ret.data
- })
- }
- });
- },
- // 预览签到图
- previewPictures() {
- const photograph = [this.photograph];
- uni.previewImage({
- urls: photograph
- });
- },
- // 删除签到图
- cancelPhotograph() {
- setTimeout(() => {
- this.photograph = '';
- }, 500);
- },
- // 签到
- signInFun() {
- if(!this.position || !this.position.latitude || !this.position.longitude){
- uni.showToast({ icon: 'none', title: '位置获取失败,请重新定位后再进行签到' })
- return
- }else if(!this.photograph){
- uni.showToast({ icon: 'none', title: '请拍照后再进行签到' })
- return
- }
- // 存储当前签到信息
- this.$u.vuex('vuex_sceneTaskSignIn',{
- inspectorPositionAddr: '',
- inspectorPositionPhotoBasePath:'',
- inspectorPositionPhotoPath: this.photograph
- })
- // 判断是否超出签到范围
- validTaskPosition({
- storeId: this.stores.id,
- point: {
- lat: this.position.latitude,
- lng: this.position.longitude,
- }
- }).then(res => {
- if (res.status == 200) {
- // 跳转开始巡店
- let item = this.stores
- // 重新开始巡店
- if(item.taskId&&item.restart){
- uni.navigateTo({
- url: '/pages/shopTour/shopTour?storeId=' + item.id + '&taskId='+ item.taskId + '&restart=1&types=scene'
- })
- }else{
- // 首次巡店
- uni.navigateTo({
- url: '/pages/shopTour/shopTour?storeId=' + item.id + '&types=scene'
- })
- }
- } else {
- uni.showToast({ icon: 'none', title: res.message })
- }
- });
- },
- }
- };
- </script>
- <style lang="scss" scoped>
- page {
- background-color: #f8f8f8;
- height: calc(100vh - 44px);
- }
- .signIn-wrap {
- height: 100%;
- background-color: #f8f8f8;
- .module-con {
- padding: 0 30upx 20upx;
- .info-main {
- margin-top: 14upx;
- padding: 20upx;
- border-radius: 12upx;
- background-color: #fff;
- .location-icon {
- padding-left: 10upx;
- vertical-align: bottom;
- }
- .photograph-con {
- border: 2upx dashed #bfbfbf;
- border-radius: 12upx;
- width: 160upx;
- height: 160upx;
- text-align: center;
- position: relative;
- .photograph-icon {
- display: inline-block;
- padding-top: 48upx;
- }
- .close-circle-icon {
- background-color: #fff;
- border-radius: 50%;
- position: absolute;
- right: -23upx;
- top: -23upx;
- z-index: 9;
- }
- }
- }
- }
- .first-con {
- padding-top: 30upx;
- }
- .submit-btn {
- width: 80%;
- margin-top: 50upx;
- }
- }
- </style>
|