hopeaddress.js 5.5 KB
new Vue({
	el:'#hopeaddress',
	data: {	
	province:[],
	city:[],
	county:[],
	street:[],
	detailaddress:'',
	sureinfo:{
		province:"",
		city:"",
		county:"",
		town:"",
		province_id:"",
		city_id:"",
		county_id:"",
		town_id:""
	},
	proce:{},
	ci:{},
	coun:{},
	stre:{}
	},
	created: function() {
		this.details();
	},
	methods: {
		//获取信息
		details: function() {
			var that = this;
            //默认市
            var obcity={
                province_id:'000',
                city_name:'市'
            };
            that.city.push(obcity);
            var len=that.city.length;
            that.ci=that.city[len-1];
            console.log( that.ci);

            //默认区
            var obscounty={
                county_id:'000',
                county_name:'区'
            };
            that.county.push(obscounty);
            var len1=that.county.length;
            that.coun=that.county[len1-1];
            //默认街道
            var obstreet={
               town_id:'000',
               town_name:'街道'
            };
            that.street.push(obstreet);
            var len2=that.street.length;
            that.stre=that.street[len2-1];


			var url = '/AjaxPosition/province'
			var params = {
				
			}
			ajaxsend(url, params, function(res) {
				/*console.log(JSON.stringify(res))*/
				console.log(res);
				var data=res.data;
                var ob={
                    province_id:'000',
                    province_name:'省'
                }
                data.unshift(ob);
                that.province=data;
                that.proce=that.province[0];
			})
		},
		//选择城市

			selectcity:function(res){
				var that = this;
				//var el = event.currentTarget;

				//省
				var proce_name=that.proce.province_name;
				var provinceid =that.proce.province_id;
				that.sureinfo.province=proce_name;
				that.sureinfo.province_id=provinceid;
				//var provinceid=res.value;
			//	console.log(province[index].province_id)
//				var adnum=parseInt(that.carlist[index].goods_num);
				console.log(provinceid)
					var url = '/AjaxPosition/city'
					var params = {
						province_id:provinceid
					}
					ajaxsend(url, params, function(res) {
						/*console.log(JSON.stringify(res))*/
						console.log(res);
                        var obcity={
                            province_id:'000',
                            city_name:'市'
                        };
                        res.data.unshift(obcity)
                        that.city=res.data;
                        that.ci=that.city[0];

					})
			},
		//选择县
		selectcounty:function(res){
			var that = this;
				//市
				var ci_name=that.ci.city_name;
				var cityid=that.ci.city_id;
				that.sureinfo.city=ci_name;
				that.sureinfo.city_id= cityid;
					var url = '/AjaxPosition/county'
					var params = {
						city_id:cityid
					}
					ajaxsend(url, params, function(res) {
						/*console.log(JSON.stringify(res))*/
						console.log(res);
                        var obscounty={
                            county_id:'000',
                            county_name:'区'
                        };
                        res.data.unshift( obscounty);
                        that.county=res.data;
                        that.coun=that.county[0];
		    })
		},
		selectstreet:function(res){
				var that = this;
				console.log(that.coun);
				//区
				var countyid=that.coun.county_id;
				var coun_name=that.coun.county_name;
				that.sureinfo.county=coun_name;
				that.sureinfo.county_id=countyid;
				
					var url = '/AjaxPosition/town';
					var params = {
						county_id:countyid
					}
					ajaxsend(url, params, function(res) {
						/*console.log(JSON.stringify(res))*/
						console.log(res);
                        var obstreet={
                            town_id:'000',
                            town_name:'街道'
                        };
                        res.data.unshift(obstreet);
                        that.street=res.data;
                        that.stre=that.street[0];
		    })
		},
		//街道
		select:function(res){
			var that=this;
			var town_id=that.stre.town_id;
			var town=that.stre.town_name;
			that.sureinfo.town=town;
			that.sureinfo.town_id=town_id;

		},
		sure:function(){
			var that=this;
			var county_id=that.sureinfo.county_id;
			var county=that.sureinfo.county;
			var province=that.sureinfo.province;
			var province_id=that.sureinfo.province_id;
			var city=that.sureinfo.city;
			var city_id=that.sureinfo.city_id;
			var town =that.sureinfo.town;
			var town_id=that.sureinfo.town_id;
			if(province==''){
				alert("请选择省");
				return false;
			}
			if(city==""){
				alert("请选择市");
				return false;
			}
			if(county==""){
				alert("请选择区");
				return false;
			}
			if(town==""){
				alert("请选择街道");
				return false;
			
			}
			if(that.detailaddress==""){
				alert("请选择详细地址");
				return false;
			}
			var url = '/SurveySpot/updateMyHopeSpot'
					var params = {
						county_id:county_id,
						county: county,
						province:province,
						province_id:province_id,
						city:city,
						city_id:city_id,
						town:town,
						town_id:town_id,
                        address:that.detailaddress,
						unique_id: localStorage.getItem('unique_id')
					}
					ajaxsend(url, params, function(res) {
						/*console.log(JSON.stringify(res))*/
						console.log(res);
						if(res.status==true){
							alert("更新成功");
							window.location.reload();
						}else if(res.state==false){
							alert("更新失败")
						}

					})
		}
	}
	
	
});

//});