package com.ttj.activity;
import java.lang.reflect.Type;
import java.util.HashMap;
import lib.view.ViewUtils;
import lib.view.annotation.ViewInject;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ttj.MyApplication;
import com.ttj.NetActivity;
import com.ttj.R;
import com.ttj.bean.SendMethodBean;
import com.ttj.bean.StatusBean;
import com.ttj.constants.Url;
import com.ttj.utils.CheckUtil;
import com.ttj.utils.JsonUtils;
import com.ttj.utils.MD5;
import com.ttj.utils.SPUtils;
import com.ttj.utils.TextUtils;
import com.ttj.utils.ToastUtil;
/**
* 添加收货地址 弃用
*
* @author Admin
*
*/
public class RecMode_ChangeAddAty extends NetActivity {
@ViewInject(R.id.p2_img_regist_title_back)
private ImageView imgBack;
@ViewInject(R.id.p2_text_regist_title)
private TextView textTitle;
@ViewInject(R.id.p2_edit_regist_consignee)
private EditText editConsignee;
@ViewInject(R.id.p2_edit_regist_phone)
private EditText editPhone;
@ViewInject(R.id.p2_text_regist_area)
private TextView textArea;
@ViewInject(R.id.p2_text_regist_delete)
private TextView textDelete;
@ViewInject(R.id.p2_edit_regist_address)
private EditText editAddr;
@ViewInject(R.id.p2_btn_regist_regist)
private Button btnRegist;
// private String longitude = "", latitude = "";
//
// private UserInfoBean infoBean;
private String ParentID, Rec_Mode, Ship_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyApplication.getInstance().addActivity(this);
setContentView(R.layout.p2_main_change_add_layout);
ViewUtils.inject(this);
// infoBean = (UserInfoBean)
// getIntent().getSerializableExtra("infoBean");
// editConsignee.setText(infoBean.getH_consignee());
// editPhone.setText(infoBean.getH_consigneePhone());
// editAddr.setText(infoBean.getH_consigneeAddress());
// if (!TextUtils.isBlank(infoBean.getH_latitude())
// && !TextUtils.isBlank(infoBean.getH_longitude())) {
// textMap.setText("已选择,点击更改");
// }
// longitude = infoBean.getH_longitude();
// latitude = infoBean.getH_latitude();
btnRegist.setOnClickListener(this);
imgBack.setOnClickListener(this);
textArea.setOnClickListener(this);
textDelete.setOnClickListener(this);
// textMap.setOnClickListener(this);
Rec_Mode = getIntent().getStringExtra("rec_mode");
if (!TextUtils.isBlank(Rec_Mode)) {
textTitle.setText("修改配送方式");
btnRegist.setText("确认修改");
Gson gson = new Gson();
Type type = new TypeToken<SendMethodBean>() {
}.getType();
SendMethodBean bean = gson.fromJson(Rec_Mode, type);
Ship_id = bean.getShip_id();
editConsignee.setText(bean.getShip_user());
editPhone.setText(bean.getShip_phone());
String str = bean.getShip_address();
String area = str.substring(0, str.lastIndexOf(","));
String add = str.substring(str.lastIndexOf(",") + 1, str.length());
editAddr.setText(add);
textArea.setText(area);
} else {
textDelete.setVisibility(View.GONE);
}
}
@Override
public void success(String result, int tag) {
StatusBean bean = JsonUtils.parseAryNetResult(result).getStatus();
if (bean.getCode() == 200) {
if (tag == 1) {
ToastUtil.show(getApplicationContext(), "添加成功", 500);
} else if (tag == 2) {
ToastUtil.show(getApplicationContext(), "修改成功", 500);
} else if (tag == 3) {
ToastUtil.show(getApplicationContext(), "删除成功", 500);
}
finish();
} else {
ToastUtil.show(getApplicationContext(), bean.getMessage(), 500);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data != null) {
switch (resultCode) {
case 100:
// longitude = String.valueOf(data.getDoubleExtra("longitude",
// 0));
// latitude = String.valueOf(data.getDoubleExtra("latitude",
// 0));
// textMap.setText("已选择,点击更改");
ParentID = data.getStringExtra("areaId");
textArea.setText(data.getStringExtra("areaName"));
break;
default:
break;
}
}
}
@Override
public void onclick(View v) {
if (v == imgBack) {
RecMode_ChangeAddAty.this.finish();
// } else if (v == textMap) {
// Intent intent = new Intent(User_ChangeAddAty.this,
// User_RegPosiAty.class);
// startActivityForResult(intent, 100);
} else if (v == textDelete) {
HashMap<String, String> params = new HashMap<String, String>();
params.put("sp_userid", SPUtils.getUid(this));
params.put("ship_id", Ship_id);
params.put("port_password",
MD5.getMD5ofStr(Url.KET + SPUtils.getUid(this)));
asynNet(Url.Area_Delete, params, 3);
} else if (v == textArea) {
Intent intent = new Intent(RecMode_ChangeAddAty.this,
Area_AddAty.class);
startActivityForResult(intent, 100);
} else if (v == btnRegist) {
String sh_name = editConsignee.getText().toString()
.replace(" ", "");
String sh_phone = editPhone.getText().toString().replace(" ", "");
String sh_area = textArea.getText().toString().replace(" ", "");
String sh_addres = editAddr.getText().toString().replace(" ", "");
if (TextUtils.isBlank(sh_name)) {
ToastUtil.show(RecMode_ChangeAddAty.this, "收货人不能为空,请输入", 500);
editConsignee.requestFocus();
return;
}
if (TextUtils.isBlank(sh_phone)) {
ToastUtil.show(RecMode_ChangeAddAty.this, "手机号码不能为空,请输入", 500);
editPhone.requestFocus();
return;
}
if (!CheckUtil.isMobile(sh_phone)) {
ToastUtil.show(RecMode_ChangeAddAty.this, "请输入正确的手机号", 500);
editPhone.setText("");
editPhone.requestFocus();
return;
}
if (TextUtils.isBlank(sh_area)) {
ToastUtil.show(RecMode_ChangeAddAty.this, "地区不能为空,请点击选择", 500);
return;
}
if (TextUtils.isBlank(sh_addres)) {
ToastUtil
.show(RecMode_ChangeAddAty.this, "详细地址不能为空,请点击填空", 500);
editAddr.requestFocus();
return;
}
// if (TextUtils.isBlank(longitude) || TextUtils.isBlank(latitude))
// {
// Intent intent = new Intent(User_ChangeAddAty.this,
// User_RegPosiAty.class);
// startActivityForResult(intent, 100);
// return;
// }
HashMap<String, String> params = new HashMap<String, String>();
params.put("sp_userid", SPUtils.getUid(this));
params.put("ship_user", sh_name);
params.put("ship_phone", sh_phone);
params.put("ship_address", sh_addres);
// params.put("sh_longitude", longitude + "");
// params.put("sh_latitude", latitude + "");
params.put("port_password",
MD5.getMD5ofStr(Url.KET + SPUtils.getUid(this)));
if (TextUtils.isBlank(Rec_Mode)) {
params.put("TAreaID", ParentID);
asynNet(Url.Area_Add, params, 1);
} else {
params.put("ship_id", Ship_id);
asynNet(Url.Area_Edit, params, 2);
}
}
}
}