hopeaddress.js 4.7 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;
				that.province=data;

                var ob={
                    province_id:'000',
                    province_name:'省'
                }
                that.province.push(ob);
                console.log(that.province);
                that.proce=that.province[31];
			})
		},
		//选择城市

			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);
						that.city=res.data;

					})
			},
		//选择县
		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);
						that.county=res.data;
		    })
		},
		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);
						that.street=res.data;
		    })
		},
		//街道
		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,
						detailaddress: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("更新失败")
						}

					})
		}
	}
	
	
});

//});