|
@@ -0,0 +1,264 @@
|
|
|
|
|
+package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
|
|
+
|
|
|
|
|
+import android.app.AlertDialog;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
|
|
+import android.content.Intent;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.os.Handler;
|
|
|
|
|
+import android.os.Message;
|
|
|
|
|
+import android.util.Log;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.widget.Button;
|
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.andreabaccega.widget.FormEditText;
|
|
|
|
|
+import com.lidroid.xutils.ViewUtils;
|
|
|
|
|
+import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
|
|
+import com.xzjmyk.pm.activity.MyApplication;
|
|
|
|
|
+import com.xzjmyk.pm.activity.R;
|
|
|
|
|
+import com.xzjmyk.pm.activity.bean.oa.SelectBean;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
|
|
+import com.xzjmyk.pm.activity.wxapi.ApiConfig;
|
|
|
|
|
+import com.xzjmyk.pm.activity.wxapi.ApiUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Created by FANGlh on 2017/4/12.
|
|
|
|
|
+ * function:
|
|
|
|
|
+ */
|
|
|
|
|
+public class PlatContactAddPeopleActivity extends BaseActivity implements View.OnClickListener{
|
|
|
|
|
+ private static final int SAVE_REQUEST = 0x41301;
|
|
|
|
|
+ @ViewInject(R.id.user_name_tv)
|
|
|
|
|
+ private FormEditText user_name_tv;
|
|
|
|
|
+ @ViewInject(R.id.user_sex_tv)
|
|
|
|
|
+ private FormEditText user_sex_tv;
|
|
|
|
|
+ @ViewInject(R.id.user_department_tv)
|
|
|
|
|
+ private FormEditText user_department_tv;
|
|
|
|
|
+ @ViewInject(R.id.user_job_tv)
|
|
|
|
|
+ private FormEditText user_job_tv;
|
|
|
|
|
+ @ViewInject(R.id.user_tel_tv)
|
|
|
|
|
+ private FormEditText user_tel_tv;
|
|
|
|
|
+ @ViewInject(R.id.user_email_tv)
|
|
|
|
|
+ private FormEditText user_email_tv;
|
|
|
|
|
+ @ViewInject(R.id.btn_save)
|
|
|
|
|
+ private Button btn_save;
|
|
|
|
|
+ private int mSex = 1;
|
|
|
|
|
+ private String[] mDepartment = {"总经办", "采购部","销售部","财务部", "人事行政部", "研发部"};
|
|
|
|
|
+ private String [][] mJobs = {
|
|
|
|
|
+ {"总经理","副总经理","秘书"},
|
|
|
|
|
+ {"经理","采购员"},
|
|
|
|
|
+ {"经理","业务员"},
|
|
|
|
|
+ {"经理","会计","出纳"},
|
|
|
|
|
+ {"经理","人事专员","行政专员"},
|
|
|
|
|
+ {"经理","工程师"}
|
|
|
|
|
+ };
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+ setContentView(R.layout.plat_add_people);
|
|
|
|
|
+ ViewUtils.inject(this);
|
|
|
|
|
+ initView();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void initView() {
|
|
|
|
|
+ user_sex_tv.setKeyListener(null);
|
|
|
|
|
+ user_sex_tv.setFocusable(false);
|
|
|
|
|
+ user_sex_tv.setOnClickListener(this);
|
|
|
|
|
+
|
|
|
|
|
+ user_department_tv.setKeyListener(null);
|
|
|
|
|
+ user_department_tv.setFocusable(false);
|
|
|
|
|
+ user_department_tv.setOnClickListener(this);
|
|
|
|
|
+
|
|
|
|
|
+ user_job_tv.setKeyListener(null);
|
|
|
|
|
+ user_job_tv.setFocusable(false);
|
|
|
|
|
+ user_job_tv.setOnClickListener(this);
|
|
|
|
|
+ btn_save.setOnClickListener(this);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ switch (v.getId()){
|
|
|
|
|
+ case R.id.user_sex_tv:
|
|
|
|
|
+ showSelectSexDialog();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.btn_save:
|
|
|
|
|
+ saveJudge();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.user_department_tv:
|
|
|
|
|
+ doSelectDepartment();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case R.id.user_job_tv:
|
|
|
|
|
+ if (StringUtils.isEmpty(user_department_tv.getText().toString())){
|
|
|
|
|
+ ToastMessage("请先选择部门");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ doSelectJob();
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void doSelectJob() {
|
|
|
|
|
+ ArrayList<SelectBean> formBeaan = new ArrayList<>();
|
|
|
|
|
+ SelectBean selectBean;
|
|
|
|
|
+ int item = -1;
|
|
|
|
|
+ switch (user_department_tv.getText().toString()){
|
|
|
|
|
+ case "总经办":
|
|
|
|
|
+ item = 0;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "采购部":
|
|
|
|
|
+ item = 1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "销售部":
|
|
|
|
|
+ item = 2;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "财务部":
|
|
|
|
|
+ item = 3;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "人事行政部":
|
|
|
|
|
+ item = 4;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "研发部":
|
|
|
|
|
+ item = 5;
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ }
|
|
|
|
|
+ for (int i = 0; i < mJobs[item].length; i++) {
|
|
|
|
|
+ selectBean = new SelectBean();
|
|
|
|
|
+ selectBean.setName(mJobs[item][i]);
|
|
|
|
|
+ formBeaan.add(selectBean);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
|
+ intent.setClass(this, SelectActivity.class);
|
|
|
|
|
+ intent.putExtra("type", 2);
|
|
|
|
|
+ intent.putExtra("title", "选择岗位");
|
|
|
|
|
+ intent.putParcelableArrayListExtra("data", formBeaan);
|
|
|
|
|
+ startActivityForResult(intent, 0x12);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void doSelectDepartment() {
|
|
|
|
|
+ ArrayList<SelectBean> formBeaan = new ArrayList<>();
|
|
|
|
|
+ SelectBean selectBean;
|
|
|
|
|
+ for (int i = 0; i < mDepartment.length; i++) {
|
|
|
|
|
+ selectBean = new SelectBean();
|
|
|
|
|
+ selectBean.setName(mDepartment[i]);
|
|
|
|
|
+ formBeaan.add(selectBean);
|
|
|
|
|
+ }
|
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
|
+ intent.setClass(this, SelectActivity.class);
|
|
|
|
|
+ intent.putExtra("type", 2);
|
|
|
|
|
+ intent.putExtra("title", "选择部门");
|
|
|
|
|
+ intent.putParcelableArrayListExtra("data", formBeaan);
|
|
|
|
|
+ startActivityForResult(intent, 0x11);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
+ if (data == null) return;
|
|
|
|
|
+ if (resultCode == 0x20){
|
|
|
|
|
+ SelectBean b = data.getParcelableExtra("data");
|
|
|
|
|
+ if (b != null){
|
|
|
|
|
+ switch (requestCode){
|
|
|
|
|
+ case 0x11:
|
|
|
|
|
+ user_department_tv.setText(b.getName());
|
|
|
|
|
+ user_job_tv.setText("");
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 0x12:
|
|
|
|
|
+ user_job_tv.setText(b.getName());
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
+ }
|
|
|
|
|
+ private void saveJudge() {
|
|
|
|
|
+ if (user_name_tv.testValidity() && user_sex_tv.testValidity()
|
|
|
|
|
+ && user_department_tv.testValidity() && user_job_tv.testValidity()
|
|
|
|
|
+ && user_email_tv.testValidity() && user_tel_tv.testValidity()
|
|
|
|
|
+ ){
|
|
|
|
|
+ saveRequest();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void saveRequest() {
|
|
|
|
|
+ progressDialog.show();
|
|
|
|
|
+ btn_save.setEnabled(false);
|
|
|
|
|
+ Map<String,Object> formStoreMap = new HashMap<>();
|
|
|
|
|
+ formStoreMap.put("userName",user_name_tv.getText().toString());
|
|
|
|
|
+ formStoreMap.put("userSex","男".equals(user_sex_tv.getText().toString()) ? "M" : "F");
|
|
|
|
|
+ formStoreMap.put("userTel",user_tel_tv.getText().toString());
|
|
|
|
|
+ formStoreMap.put("userEmail",user_email_tv.getText().toString());
|
|
|
|
|
+
|
|
|
|
|
+ String url = ApiConfig.getInstance(ApiUtils.getApiModel()).getmApiBase().add_people;
|
|
|
|
|
+ HashMap<String,Object> param = new HashMap<>();
|
|
|
|
|
+ String formStore = JSON.toJSONString(formStoreMap);
|
|
|
|
|
+ param.put("formStore",formStore);
|
|
|
|
|
+ param.put("dept",user_department_tv.getText().toString());
|
|
|
|
|
+ param.put("role",user_job_tv.getText().toString());
|
|
|
|
|
+ param.put("enuu", CommonUtil.getSharedPreferences(MyApplication.getInstance().getApplicationContext(), "companyEnUu"));
|
|
|
|
|
+ param.put("emcode",CommonUtil.getSharedPreferences(MyApplication.getInstance().getApplicationContext(), "b2b_uu"));
|
|
|
|
|
+ LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
|
|
+ headers.put("Cookie", "JSESSIONID=" + ApiConfig.getInstance(ApiUtils.getApiModel()).getmApiBase().getCookie());
|
|
|
|
|
+ ViewUtil.httpSendRequest(this, url, param, handler, headers, SAVE_REQUEST, null, null, "post");
|
|
|
|
|
+ }
|
|
|
|
|
+ private Handler handler = new Handler(){
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
|
|
+ super.handleMessage(msg);
|
|
|
|
|
+ switch (msg.what){
|
|
|
|
|
+ case SAVE_REQUEST:
|
|
|
|
|
+ if (msg.getData() != null){
|
|
|
|
|
+ String save_result = msg.getData().getString("result");
|
|
|
|
|
+ Log.i("save_result",save_result);
|
|
|
|
|
+ if (!StringUtils.isEmpty(save_result)){
|
|
|
|
|
+ if (JSON.parseObject(save_result).containsKey("success") && JSON.parseObject(save_result).getBoolean("success")){
|
|
|
|
|
+ Toast.makeText(getApplicationContext(), "新增成功", Toast.LENGTH_LONG);
|
|
|
|
|
+ finish();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ progressDialog.dismiss();
|
|
|
|
|
+ btn_save.setEnabled(true);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ if (msg.getData() != null) {
|
|
|
|
|
+ if (!StringUtils.isEmpty(msg.getData().getString("result"))) {
|
|
|
|
|
+ ToastMessage(msg.getData().getString("result"));
|
|
|
|
|
+ progressDialog.dismiss();
|
|
|
|
|
+ btn_save.setEnabled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ private void showSelectSexDialog() {
|
|
|
|
|
+ // 1是男,0是女,2是全部
|
|
|
|
|
+ String[] sexs = new String[]{ getString(R.string.sex_man), getString(R.string.sex_woman)};
|
|
|
|
|
+ int checkItem = 0;
|
|
|
|
|
+ new AlertDialog.Builder(this).setTitle(getString(R.string.select_sex))
|
|
|
|
|
+ .setSingleChoiceItems(sexs, checkItem, new DialogInterface.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+ if (which == 0) {
|
|
|
|
|
+ user_sex_tv.setText(R.string.sex_man);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ user_sex_tv.setText(R.string.sex_woman);
|
|
|
|
|
+ }
|
|
|
|
|
+ dialog.dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ }).setCancelable(true).create().show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|