s_store.js 6.07 KB
//logs.js
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
import App from '../../utils/api.js'
Page({
    data:{
		circles:[{}],
    },
    onLoad:function(){
       this.setData({
           sellerid:util.cache('sellerid')
       })
	   
    },
    onShow:function(){
		this.getsellerinfo();
        this.alert=this.selectComponent('#alert');
        // this.getUserinfo();
        var that=this;
        util.postSuccessFun=function(json,uri_code){
            switch (uri_code) {
                case uri.CGI__USER_GETSELLERBYID__CODE:
                    console.log(json)
                    if(json.ret==200){
                        var seller_tel=json.data.data.seller_tel ? json.data.data.seller_tel.split(',') : null;
                        var contacttel;
                        if(json.data.data.seller_tel){
                            if(seller_tel.length>1){
                                contacttel=seller_tel[0]+'/'+seller_tel[1]
                            }else{
                                contacttel=seller_tel[0]
                            }
                        }
						let circle={
							latitude:json.data.data.lat,
							longitude:json.data.data.long,
							color:"#199095AA",
							fillColor:"#FFFFFFAA",
							radius:5000,
							strokeWidth:5,
						}
						console.log(circle);
						let setkey='circles['+0+']'
                        that.setData({
                            storeInfo:json.data.data,
                            seller_tel:json.data.data.seller_tel ? contacttel : null,
							[setkey]:circle
                        })
						// that.getCrlcle();
                    }
                break;
                case uri.CGI__USER_SETSELLERBYID__CODE:
                    console.log(json)
                    that.getUserinfo();
                break;
            }
        }
    },
    addimage:function(){
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
            success:  (res)=> {
                console.log('chooseImage:',res)// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
                var tempFilePaths = res.tempFilePaths
                console.log(res);
                this.setData({
                    tempimage:tempFilePaths[0]
                })
                wx.uploadFile({
                    url: "https://zywm.colorcun.com?service=App.Seller.SetSellerById",
                    filePath: this.data.tempimage,
                    name: "image",
                    formData:{
                        id:this.data.sellerid
                    },
                    header: {
                        'content-type': 'multipart/form-data'
                    }, // 设置请求的 header
                    success: (res)=>{
                        console.log(res,'kkkkkk')
                        if(res.statusCode==200) {
                            var img = JSON.parse(res.data).data[0];
                            this.getsellerinfo();
                        }
                    }
                })
            }
        })

    },
    detail:function(e){
        var type=e.currentTarget.dataset.type;
        var info=e.currentTarget.dataset.info;
        var typeinfo=e.currentTarget.dataset.typeinfo;
        wx.navigateTo({
            url:'../store/s_detail?type='+type+'&info='+info+'&typeinfo='+typeinfo
        })
    },
    chooselocation:function(){
        wx.chooseLocation({
            success:(res)=>{
        		console.log(res,'uuuu')
                let formdata={};
                formdata.id=this.data.sellerid;
                formdata.map_address=res.address;
                formdata.long=res.longitude;
                formdata.lat=res.latitude;
        		this.setseller(formdata);
            }
        })

    },
    editseller:function(formdata){
        util.post(uri.CGI__USER_SETSELLERBYID,formdata,uri.CGI__USER_SETSELLERBYID__CODE);
    },
    netchange:function(){
        this.onShow();
    },
	getCrlcle(){
	    this.wxmap = wx.createMapContext('map')
	    this.wxmap.getRegion({
	      success: res => {
	        console.log(res,'get');
	        let lng1 = res.northeast.longitude;
	        let lat1 = res.northeast.latitude;
	        let lng2 = res.southwest.longitude;
	        let lat2 = res.southwest.latitude;
	
	        let longitude = lng1 - lng2;
	        let latitude = lat1 - lat2;
	        let flag = longitude > latitude ? true : false;
	        let radius = 0;
	        //计算得到短边,然后再通过*1000转变为m,除2得到半径,*0.8优化显示,让圈圈只占界面的80%
	        if (flag) {
				console.log('kkkkk',this.getDistance(lng1, lat1, lng1, lat2)*1000)
	          // radius = this.getDistance(lng1, lat1, lng1, lat2) * 1000 / 2;
	        } else {
				console.log('kkkkk',this.getDistance(lng1, lat1, lng1, lat2)*1000)
	          // radius = this.getDistance(lng1, lat1, lng2, lat1) * 1000 / 2;
	        }
	        // this.setData({
	        //   "circles[0].radius": radius
	        // });
	      }
	    });
	},
	getDistance(lng1, lat1, lng2, lat2) {
		var EARTH_RADIUS = 6378.137;
	    var radLat1 = this.rad(lat1);
	    var radLat2 = this.rad(lat2);
	    var a = radLat1 - radLat2;
	    var b = this.rad(lng1) - this.rad(lng2);
	    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
	      + Math.cos(radLat1) * Math.cos(radLat2)
	      * Math.pow(Math.sin(b / 2), 2)));
	    s = s * EARTH_RADIUS;
	    s = Math.round(s * 10000) / 10000;
	    return s;//返回数值单位:公里
	},
	rad(d) {
	  return d * Math.PI / 180.0;
	},
	getsellerinfo(){
		App.Seller.GetSellerById({sellerid:this.data.sellerid}).then((json)=>{
			console.log(json)
			if(json.ret==200){
				this.setData({
					seller:json.data.seller,
				})
			}
			
		})
	},
	setseller(formdata){
		App.Seller.SetSellerById(formdata).then((json)=>{
			console.log(json);
			if(json.ret==200){
				this.data.getsellerinfo();
			}
		})
	}
})