package com.zhilin.patrol.ui.fragment;

import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.google.gson.Gson;
import com.zhilin.patrol.R;
import com.zhilin.patrol.bean.AddressAreaEntity;
import com.zhilin.patrol.bean.LoginEntity;
import com.zhilin.patrol.bean.MapLocationInfo;
import com.zhilin.patrol.bean.PatrolFormEntity;
import com.zhilin.patrol.bean.PointFormEntity;
import com.zhilin.patrol.bean.PointInfoEntity;
import com.zhilin.patrol.bean.QuestionKindEntity;
import com.zhilin.patrol.http.HttpUrl;
import com.zhilin.patrol.tool.CheckPermissionUtils;
import com.zhilin.patrol.tool.DialogUtil;
import com.zhilin.patrol.tool.GetJsonDataUtil;
import com.zhilin.patrol.tool.IpUtils;
import com.zhilin.patrol.tool.JsonUtils;
import com.zhilin.patrol.tool.LocationUtils;
import com.zhilin.patrol.tool.Utils;
import com.zhilin.patrol.ui.activity.AddressSelectActivity;
import com.zhilin.patrol.ui.activity.InfoUploadActivity;
import com.zhilin.patrol.ui.activity.MainActivity;
import com.zhilin.patrol.ui.activity.PatrolUploadActivity;
import com.zhilin.patrol.views.AlertDialog;
import com.zhilin.patrol.views.CustomProgressDialog;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class PointRecordFragment extends Fragment {

    public static final String TYPE = "type";
    public String TAG="PointRecordFragment";
    private int mType;
    @BindView(R.id.ll_point)
    LinearLayout mPointLayout;
    @BindView(R.id.et_content)
    EditText mRemarkEt;//备注
    @BindView(R.id.et_district)
    TextView mDistrictEt;
    @BindView(R.id.et_stree)
    TextView mStreeEt;
    @BindView(R.id.tv_default_community)
    TextView mDefCommTv;
    @BindView(R.id.tv_actual_point)
    TextView mActualTv;
    @BindView(R.id.et_shequ)
    TextView mShequEt;
    @BindView(R.id.et_community)
    EditText mCummEt;
    @BindView(R.id.et_area)
    EditText mAreaEt;
    @BindView(R.id.ll_area)
    LinearLayout llAreaEt;
    @BindView(R.id.tv_default_address)
    TextView mAddressTv;
    @BindView(R.id.tv_content_num)
    TextView mContentNumTv;//备注长度
    @BindView(R.id.btn_submit)
    Button btnSubmit;

    /** 客户文件目录 */
    private String mImageDir = Environment.getExternalStorageDirectory() + "/patrol/";

    String[] mPermissions = {
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.CAMERA,
            Manifest.permission.READ_PHONE_STATE};
    /** 附近小区集合 */
    private ArrayList mAddressAreaList;
    private LocationUtils mLocationUtils;
    private List<PointInfoEntity.InfoListBean> infoList;
    private List<String> options1Items=new ArrayList<>(); //区
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();//街道
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();//社区
    private CustomProgressDialog mProgressDialog;
    /** 选中的小区 */
    private AddressAreaEntity.InfoListBean mListBean;
    /** 定位信息 */
    private MapLocationInfo mMapLocationInfo;
    private LoginEntity.InfoListBean.UserInfoBean mUserInfo;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle arguments = getArguments();

        mType = arguments.getInt(TYPE);
        Log.i("111","aaarrra"+mType);
        initData();
//        requestInfo();
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_point_upload, container, false);
        ButterKnife.bind(this, view);
        mUserInfo = (LoginEntity.InfoListBean.UserInfoBean) getActivity().getIntent().getSerializableExtra("userInfo");
        mRemarkEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void afterTextChanged(Editable editable) {
                mContentNumTv.setText(mRemarkEt.getText().length() + "/200");
            }
        });
        mProgressDialog = new CustomProgressDialog(getActivity());
//        mLocationUtils = LocationUtils.getInstance();
        mLocationUtils=new LocationUtils();
        Log.i(TAG,"去定位");
        mLocationUtils.onCreate(new LocationUtils.LocationListener() {
            @Override
            public void locationSuccess(MapLocationInfo mapLocationInfo, String message) {
                if (TextUtils.isEmpty(mapLocationInfo.getAddress())) {

                } else {
                    mMapLocationInfo = mapLocationInfo;
                }
                mProgressDialog.dismiss();
                Log.i(TAG,"定位ok");
                Log.i(TAG,mMapLocationInfo.toString());
                defalutAddress();//确定默认小区
            }
            @Override
            public void locationFail(String message) {
                mProgressDialog.dismiss();
            }
        });
        checkPermissions();

        return view;
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        for (int i = 0; i < grantResults.length; i++) {
            if (PackageManager.PERMISSION_GRANTED != grantResults[i]) {
                new AlertDialog(getActivity()).builder()
                        .setTitle(PointRecordFragment.this.getString(R.string.tv_tishi))
                        .setMsg("获取权限失败，是否重新尝试？")
                        .setPositiveButton("重试", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                checkPermissions();
                            }
                        })
                        .setNegativeButton("取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        }).show();
                return;
            }
        }
        locationAddress();
        //申请权限后创建图片文件夹
        Utils.createDir(mImageDir);
    }

    public void requestAddress2() {
        Log.i(TAG,"requestAddress2");
        mProgressDialog.showDialog("正在获取附近小区...");
        Log.i(TAG,"getIpAddress");
        String ipAddress = IpUtils.getIpAddress(getActivity());
        Log.i(TAG,"post");
        OkHttpUtils.post()
                .url(HttpUrl.GET_NEAR_ADDRESS_URL)
                .addParams("userCode", mUserInfo.getUserCode())
                .addParams("userRole", mUserInfo.getUserRole() + "")
                .addParams("userIP", ipAddress)
                .addParams("disName", mMapLocationInfo.getDistrict())
                .addParams("longitude", mMapLocationInfo.getLongitude() + "")
                .addParams("latitude", mMapLocationInfo.getLatitude() + "")
                .build().execute(new Callback<AddressAreaEntity>() {
            @Override
            public AddressAreaEntity parseNetworkResponse(Response response, int id) throws Exception {
                Log.i(TAG,"jsonStr");
                String jsonStr = response.body().string();
                Log.i(TAG,jsonStr);
                return (AddressAreaEntity) JsonUtils.parseJson2Obj(jsonStr, AddressAreaEntity.class);
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                mProgressDialog.dismiss();
                DialogUtil.showNetFailDialog(getActivity());
            }

            @Override
            public void onResponse(AddressAreaEntity entity, int id) {
                mProgressDialog.dismiss();
                List<AddressAreaEntity.InfoListBean> infoList = entity.getInfoList();
                int mindDistancenumber=0;
                String addressdefault="附近没有小区";
                Log.i(TAG,"循环遍历");
                Log.i(TAG, infoList.toString());
                Log.i(TAG, infoList.size()+" ");
                if(infoList.size()!=0) {
                    int[] arr=new int[infoList.size()];
                    for (int i = 0; i <= infoList.size()-1; i++) {
                        arr[i]=Integer.parseInt(infoList.get(i).getDistance());
                        Log.i(TAG, infoList.get(i).getDistance()+"distance");
                    }
                    Log.i(TAG, arr+"arr1");
                    for(int i=0;i<=infoList.size()-1;i++){
                        for (int j = 0; j <= infoList.size() - i-2; j++) {
                            if (arr[j]>arr[j+1]) {
                                int itemp3=arr[j];
                                arr[j]= arr[j+1];
                                arr[j+1]=itemp3;
                            }
                        }
                    }
                    Log.i(TAG, arr+"arr");
                    int minddistance=0;
                    Log.i(TAG, "得到最小距离");
                    for (int n = 0; n <= infoList.size()-1; n++) {
                        int Distancenumber = arr[0];
                        if (Integer.parseInt(infoList.get(n).getDistance())==Distancenumber) {
                            mindDistancenumber=Distancenumber;
                            addressdefault = infoList.get(n).getAddress();
                            infoList.get(n).setSelected(true);
                            mListBean=infoList.get(n);
                            Log.i(TAG, infoList.get(n).isSelected() +"==isSelected");
                            Log.i(TAG, addressdefault+"addressdefault");
                        }
                    }
                }

                if(infoList.size()==0&&mindDistancenumber==0) {
                    Log.i(TAG,"附近没有小区");
//                    mDefCommTv.setText(addressdefault);
                    init();
                }else{
                    Log.i(TAG,"默认小区地址");
                    mDefCommTv.setText(addressdefault+"   "+mindDistancenumber+"m");
                    mAddressTv.setText(mListBean.toStingTv());
                    if(!mAddressTv.getText().toString().isEmpty()){
                        mAddressTv.setVisibility(View.VISIBLE);
                    }
                    mShequEt.setText(mListBean.getArea());
                    mDistrictEt.setText(mListBean.getDisName()+"/"+mListBean.getStreet()+"/"+mListBean.getArea());
                    mStreeEt.setText(mListBean.getStreet());
//                    mCummEt.setText(mListBean.getAddress());
                    init();
                }
            }
        });
        Log.i(TAG, "退出requestAddress2");
        mProgressDialog.dismiss();
    }
    private void defalutAddress(){
        Log.i(TAG,"准备获取小区");
        Log.i(TAG,mMapLocationInfo.toString());
        requestAddress2();
        Log.i(TAG,"获取到小区");
//
    }
    private void toAddressSelect() {
        if (mAddressAreaList == null) {
            requestAddress();
        } else {
            Log.i(TAG,mAddressAreaList.toString()+"附近小区list");
            toAddressSelectActivity();
        }
    }
    /**
     * 跳转到选择小区页面
     */
    private void toAddressSelectActivity() {
        Intent intent = new Intent(getActivity(), AddressSelectActivity.class);
        intent.putExtra("userInfo", mUserInfo);
        intent.putExtra("AddressAreaList", mAddressAreaList);
        startActivityForResult(intent, 2);
    }
    /**
     * 请求地址
     */
    public void requestAddress() {
        Log.i(TAG,"requestAddress");
        mProgressDialog.showDialog("正在获取附近小区...");
        String ipAddress = IpUtils.getIpAddress(getActivity());
        Log.i(TAG,mUserInfo.getUserCode());
        Log.i(TAG,mUserInfo.getUserRole() + "");
        Log.i(TAG,ipAddress);
        Log.i(TAG,mMapLocationInfo.getDistrict());
        Log.i(TAG,mMapLocationInfo.getLongitude() + "");
        Log.i(TAG,mMapLocationInfo.getLatitude() + "");

        OkHttpUtils.post()
                .url(HttpUrl.GET_NEAR_ADDRESS_URL)
                .addParams("userCode", mUserInfo.getUserCode())
                .addParams("userRole", mUserInfo.getUserRole() + "")
                .addParams("userIP", ipAddress)
                .addParams("disName", mMapLocationInfo.getDistrict())
                .addParams("longitude", mMapLocationInfo.getLongitude() + "")
                .addParams("latitude", mMapLocationInfo.getLatitude() + "")
                .build().execute(new Callback<AddressAreaEntity>() {
            @Override
            public AddressAreaEntity parseNetworkResponse(Response response, int id) throws Exception {
                String jsonStr = response.body().string();
                return (AddressAreaEntity) JsonUtils.parseJson2Obj(jsonStr, AddressAreaEntity.class);
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                mProgressDialog.dismiss();
                DialogUtil.showNetFailDialog(getActivity());
            }

            @Override
            public void onResponse(AddressAreaEntity entity, int id) {
                mProgressDialog.dismiss();
                if (entity == null) {
                    DialogUtil.showErrDialog(getActivity(), "返回信息为空");
                    return;
                }
                if (!"1000".endsWith(entity.getReturnCode())) {
                    DialogUtil.showErrDialog(getActivity(), entity.getReturnMsg());
                    return;
                }
                List<AddressAreaEntity.InfoListBean> infoList = entity.getInfoList();

                if (infoList == null) {
                    DialogUtil.showErrDialog(getActivity(), "返回数组为空");
                    return;
                }
                if (infoList != null) {
                    mAddressAreaList = new ArrayList();
                    for (AddressAreaEntity.InfoListBean bean : infoList) {
                        mAddressAreaList.add(bean);
                    }
                }
                Log.i(TAG,mAddressAreaList.toString()+"得到附近小区list");
                toAddressSelectActivity();
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 2 && resultCode == 1) {//返回小区选择
            mListBean = (AddressAreaEntity.InfoListBean) data.getSerializableExtra("ListBean");
            mAddressAreaList = (ArrayList) data.getSerializableExtra("AddressAreaList");
            mDefCommTv.setText(mListBean.getAddress() + "    " + mListBean.getDistance() + "m");
            mAddressTv.setText(mListBean.toStingTv());
            if(!mAddressTv.getText().toString().isEmpty()){
                mAddressTv.setVisibility(View.VISIBLE);
            }
            mShequEt.setText(mListBean.getArea());
            mDistrictEt.setText(mListBean.getDisName()+"/"+mListBean.getStreet()+"/"+mListBean.getArea());
            mStreeEt.setText(mListBean.getStreet());
        }
    }
    /**
     * 定位
     */
    private void locationAddress() {
//        mProgressDialog.showDialog("正在定位...");
        mLocationUtils.startLocationInfo();
    }
    @TargetApi(Build.VERSION_CODES.M)
    private void checkPermissions() {
        mPermissions = CheckPermissionUtils.getNeededPermission(getActivity(), mPermissions);
        if (mPermissions.length > 0) {
            requestPermissions(mPermissions, 999);
        }
        if (mPermissions.length == 0) {
            //申请过一次这里的permissions.length就为0 了
            //申请权限后创建图片文件夹
            Utils.createDir(mImageDir);
            locationAddress();
        }
    }
    private void init() {
        Log.i("111","aaaa"+mType);

        if(mType==1){
            mPointLayout.setVisibility(View.VISIBLE);
                Log.i("111","aaaa"+mMapLocationInfo.toStringTv());
                mProgressDialog.dismiss();

//                mDistrictEt.setText(mMapLocationInfo.getDistrict()+"/"+mMapLocationInfo.getStreet());
//                mStreeEt.setText(mMapLocationInfo.getStreet());
        }
        else if(mType==2){
            mPointLayout.setVisibility(View.GONE);
            mActualTv.setText("新增点位信息：");
                Log.i("111","aaaa"+mMapLocationInfo.toStringTv());
                mProgressDialog.dismiss();
//                mDistrictEt.setText(mMapLocationInfo.getDistrict()+"/"+mMapLocationInfo.getStreet());
//                mStreeEt.setText(mMapLocationInfo.getStreet());

        }

    }
    @SuppressLint("WrongConstant")
    @OnClick({R.id.tv_default_community,R.id.btn_submit,R.id.et_district})//R.id.et_stree,R.id.et_shequ
    public void onClick(View view) {
        if (view.getId() == R.id.tv_default_community) {//选择小区
            Log.i("1","1");
            toAddressSelect();
        }
        if(view.getId() ==R.id.et_district){//||view.getId() ==R.id.et_stree||view.getId() ==R.id.et_shequ
            showPickerView();
        }
        if (view.getId() == R.id.btn_submit) {//提交
            String cummEt = mCummEt.getText().toString().trim();
//            String shequEt=mShequEt.getText().toString().trim();
//            String streetEt=mStreeEt.getText().toString().trim();
            String districtEt=mDistrictEt.getText().toString().trim();
            String areaEt=mAreaEt.getText().toString().trim();
            if (TextUtils.isEmpty(districtEt)) {
                Utils.showToast(getActivity(), "请选择区/街道/社区");
                return;
            }

//            if (TextUtils.isEmpty(shequEt)) {
//                Utils.showToast(getActivity(), "请输入社区名");
//                return;
//            }
            if(llAreaEt.getVisibility()!=8){//选了其他社区
                if (TextUtils.isEmpty(areaEt)) {
                    Utils.showToast(getActivity(), "请输入社区名");
                    return;
                }
            }
            if (TextUtils.isEmpty(cummEt)) {
                Utils.showToast(getActivity(), "请输入小区名");
                return;
            }

            postPoint();
        }

    }
    private void postPoint(){
        mProgressDialog.showDialog("正在提交...");
        String areaText=mShequEt.getText().toString();
        if (mShequEt.getText().toString().equals("其他")){
            areaText=mAreaEt.getText().toString().trim();
        }

        if(mType==1){
            OkHttpUtils.post()
                    .url(HttpUrl.ADDADDRESS_POST)
                    //用户名，能看见谁提交的，备注，
                    .addParams("userCode",mUserInfo.getUserCode())
                    .addParams("district", mListBean == null ? "" : mListBean.getDisName())
                    .addParams("street", mListBean == null ? "" : mListBean.getStreet())
                    .addParams("area", areaText+"")
                    .addParams("addrCode", mListBean == null ? "" : mListBean.getAddrCode())
                    .addParams("longitude", mMapLocationInfo.getLongitude() + "")
                    .addParams("latitude", mMapLocationInfo.getLatitude() + "")
                    .addParams("address", mCummEt.getText().toString().trim()+"")
                    .build().execute(new Callback<PointFormEntity>() {
                @Override
                public PointFormEntity parseNetworkResponse(Response response, int id) throws Exception {
                    String jsonStr = response.body().string();
                    return (PointFormEntity) JsonUtils.parseJson2Obj(jsonStr, PointFormEntity.class);
                }

                @Override
                public void onError(Call call, Exception e, int id) {
                    mProgressDialog.dismiss();
                    DialogUtil.showNetFailDialog(getActivity());
                }

                @Override
                public void onResponse(PointFormEntity entity, int id) {
                    mProgressDialog.dismiss();
                    if (entity == null) {
                        DialogUtil.showErrDialog(getActivity(), "返回信息为空");
                        return;
                    }
                    if (!"1000".endsWith(entity.getReturnCode())) {
                        DialogUtil.showErrDialog(getActivity(), entity.getReturnMsg());
                        return;
                    }
                    DialogUtil.showErrDialog(getActivity(), "点位修改成功!");

                }
            });
        }else if(mType==2){
            OkHttpUtils.post()
                    .url(HttpUrl.ADDADDRESS_POST)
                    ////用户名，能看见谁提交的，备注，
                    .addParams("userCode",mUserInfo.getUserCode())
                    .addParams("district", mListBean == null ? "" : mListBean.getDisName())
                    .addParams("street", mListBean == null ? "" : mListBean.getStreet())
                    .addParams("area", areaText+"")
                    .addParams("longitude", mMapLocationInfo.getLongitude() + "")
                    .addParams("latitude", mMapLocationInfo.getLatitude() + "")
                    .addParams("address", mCummEt.getText().toString().trim()+"")
                    .build().execute(new Callback<PatrolFormEntity>() {
                @Override
                public PatrolFormEntity parseNetworkResponse(Response response, int id) throws Exception {
                    String jsonStr = response.body().string();
                    return (PatrolFormEntity) JsonUtils.parseJson2Obj(jsonStr, PatrolFormEntity.class);
                }

                @Override
                public void onError(Call call, Exception e, int id) {
                    mProgressDialog.dismiss();
                    DialogUtil.showNetFailDialog(getActivity());
                }

                @Override
                public void onResponse(PatrolFormEntity entity, int id) {
                    mProgressDialog.dismiss();
                    if (entity == null) {
                        DialogUtil.showErrDialog(getActivity(), "返回信息为空");
                        return;
                    }
                    if (!"1000".endsWith(entity.getReturnCode())) {
                        DialogUtil.showErrDialog(getActivity(), entity.getReturnMsg());
                        return;
                    }
                    DialogUtil.showErrDialog(getActivity(), "新增点位成功!");

                }
            });
        }

    }
    public static PointRecordFragment newInstance(int type) {
        PointRecordFragment fragment = new PointRecordFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(TYPE, type);
        fragment.setArguments(bundle);
        return fragment;
    }

    private void requestInfo(){
        OkHttpUtils.post()
                .url(HttpUrl.FINDPOINT_POST)

                .build().execute(new Callback<PointInfoEntity>() {
            @Override
            public PointInfoEntity parseNetworkResponse(Response response, int id) throws Exception {
                String jsonStr = response.body().string();
                return (PointInfoEntity) JsonUtils.parseJson2Obj(jsonStr, PointInfoEntity.class);
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                mProgressDialog.dismiss();
                DialogUtil.showNetFailDialog(getActivity());
            }

            @Override
            public void onResponse(PointInfoEntity entity, int id) {
                mProgressDialog.dismiss();
                if (entity == null) {
                    DialogUtil.showErrDialog(getActivity(), "返回信息为空");
                    return;
                }
                if (!"1000".endsWith(entity.getReturnCode())) {
                    DialogUtil.showErrDialog(getActivity(), entity.getReturnMsg());
                    return;
                }
                infoList = entity.getInfoList();
//                initData(infoList);
            }
        });
    }

//    private void initData(List<PointInfoEntity.InfoListBean> jsonBean) {

    private void initData() {
        /**
         * 注意：assets 目录下的Json文件仅供参考，实际使用可自行替换文件
         * 关键逻辑在于循环体
         * */


//        String JsonData = new GetJsonDataUtil().getJson(getActivity(), "pointInfo.json");//获取assets目录下的json文件数据
//        ArrayList<PointInfoEntity.InfoListBean> jsonBean = parseData(JsonData);//用Gson 转成实体
        String jsonStr = new GetJsonDataUtil().getJson(getActivity(), "pointInfo.json");

        PointInfoEntity pointEntity = (PointInfoEntity) JsonUtils.parseJson2Obj(jsonStr, PointInfoEntity.class);//序列化
        ArrayList<PointInfoEntity.InfoListBean> jsonBean = (ArrayList<PointInfoEntity.InfoListBean>) pointEntity.getInfoList();



        /**
         * 添加省份数据
         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
         * PickerView会通过getPickerViewText方法获取字符串显示出来。
         */
//        options1Items = jsonBean;//

        for (int i = 0; i < jsonBean.size(); i++) {//遍历区
            ArrayList<String> streetList = new ArrayList<>();//该区的街道列表（第二级）
            ArrayList<ArrayList<String>> district_sheQuList = new ArrayList<>();//该区所有社区列表（第三级）
            Log.i("111",jsonBean.get(i).getName()+"****-");

            options1Items.add(jsonBean.get(i).getName());
            for (int c = 0; c < jsonBean.get(i).getStreetList().size(); c++) {//遍历该区所有街道
                String streetName = jsonBean.get(i).getStreetList().get(c).getName();
                streetList.add(streetName);//添加街道
                ArrayList<String> street_sheQuList = new ArrayList<>();//该街道所有社区列表

                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (jsonBean.get(i).getStreetList().get(c).getArea() == null
                        || jsonBean.get(i).getStreetList().get(c).getArea().size() == 0) {
                    street_sheQuList.add("");
                } else {
                    street_sheQuList.addAll(jsonBean.get(i).getStreetList().get(c).getArea());
                }
                district_sheQuList.add(street_sheQuList);//添加该省所有地区数据
            }
            //添加城市数据
            options2Items.add(streetList);
            //添加地区数据
            options3Items.add(district_sheQuList);
        }


    }
    public ArrayList<PointInfoEntity.InfoListBean> parseData(String result) {//Gson 解析
        ArrayList<PointInfoEntity.InfoListBean> detail = new ArrayList<>();
        try {
            JSONArray data = new JSONArray(result);
            Gson gson = new Gson();
            for (int i = 0; i < data.length(); i++) {
                PointInfoEntity entity = gson.fromJson(data.optJSONObject(i).toString(), PointInfoEntity.class);
                detail.add(entity.getInfoList().get(i));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return detail;
    }
    private void showPickerView() {
        OptionsPickerView pvOptions = new OptionsPickerBuilder(getActivity(), new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置

                mDistrictEt.setText(options1Items.get(options1)+"/"+options2Items.get(options1).get(options2)+"/"+options3Items.get(options1).get(options2).get(options3));
                mStreeEt.setText(options2Items.get(options1).get(options2));
                mShequEt.setText(options3Items.get(options1).get(options2).get(options3));
                if (mShequEt.getText().toString().equals("其他")){
                    llAreaEt.setVisibility(View.VISIBLE);
                }else {
                    llAreaEt.setVisibility(View.GONE);
                }
            }
        })
                .setTitleText("位置选择")
                .setTitleBgColor(Color.WHITE)//设置标题的背景颜色
                .setDividerColor(Color.BLACK)//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .build();
        pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
        pvOptions.show();
    }


}
