This commit is contained in:
2025-11-18 15:12:24 +08:00
parent c173c425ce
commit a7d2035e70
1361 changed files with 367452 additions and 0 deletions
@@ -0,0 +1,486 @@
package cn.shangyu.gdxzExpert.activity;
import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gyf.immersionbar.ImmersionBar;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
import cn.shangyu.gdxzExpert.R;
import cn.shangyu.gdxzExpert.base.BaseActivity;
import cn.shangyu.gdxzExpert.bean.MonthDetailBean;
import cn.shangyu.gdxzExpert.bean.MonthDetailBean.DataFee;
import cn.shangyu.gdxzExpert.bean.MonthDetailBean.DataTime;
import cn.shangyu.gdxzExpert.ecdemo.ui.SettingItem;
import cn.shangyu.gdxzExpert.http.HttpHelper;
import cn.shangyu.gdxzExpert.utils.Constant;
import cn.shangyu.gdxzExpert.utils.GsonTools;
import cn.shangyu.gdxzExpert.utils.LogUtil;
import cn.shangyu.gdxzExpert.utils.SharePrefUtil;
import cn.shangyu.gdxzExpert.utils.ToastUtil;
import cn.shangyu.gdxzExpert.utils.UIUtils;
import cn.shangyu.gdxzExpert.utils.Url;
import cn.shangyu.gdxzExpert.widget.LoadingPage.ResultState;
/**
*
* @author ssy
* @date 2015-8-31 下午2:47:47
* Copyright (C) 2015 河南商宇科技有限公司
*
* 功能说明:我的-服务设置-电话咨询
*/
public class TelephoneConsultationActivity extends BaseActivity {
private TextView tv_howLong;
private EditText et_ten_price;
private EditText et_twenty_price;
private SettingItem m_consultation;
public static final int RESILTCODE = 99;
private String price = "";
private String howLong = "";
private String isEnable = "";
//电话咨询服务查看
public static String callServiceDetailUrl=Url.getcallServiceDetail;
//电话服务设置1(价格、人次等设置)
public static String callServiceFeeUrl=Url.getcallServiceFee;
//电话服务设置2(时间设置)
public static String callServiceTimeUrl=Url.getcallServiceTime;
private String callWeek = "";
private String startDate = "";
private String hl = "";
private Button bt_ok;
private LinearLayout m_service;
private String startDateArr = "";
@Override
public void setTitle() {
top_title.setText("电话咨询");
}
@Override
public View onCreateSuccessedView() {
ImmersionBar.with(this).keyboardEnable(true).statusBarDarkFont(true).titleBar(mToolbar).init();
View view = UIUtils.inflate(R.layout.activity_telephone_consultation);
m_consultation = (SettingItem) view.findViewById(R.id.switch_telephone_consultation);//是否开启服务
et_ten_price = (EditText) view.findViewById(R.id.et_ten_price);//10分钟价格
et_twenty_price = (EditText) view.findViewById(R.id.et_twenty_price);//20分钟价格
m_service = (LinearLayout) view.findViewById(R.id.rl_setting_howLong);
tv_howLong = (TextView) view.findViewById(R.id.tv_howLong);//服务时段回显
bt_ok = (Button) view.findViewById(R.id.bt_ok);
//初始化是否开启
boolean isOpen = SharePrefUtil.getBoolean(ct, "Telephone_m_consultation", false);
m_consultation.setChecked(isOpen);
//是否开启服务
m_consultation.getCheckedTextView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
m_consultation.toggle();
if (m_consultation.isChecked()) {
setEnable(true);
operaterVIP(1);
} else {
setEnable(false);
operaterVIP(0);
}
}
});
//初始化是否选中
if (m_consultation.isChecked()) {
setEnable(true);
}else{
setEnable(false);
}
m_service.setOnClickListener(this);
bt_ok.setOnClickListener(this);
//从sp里取出缓存
String monthDetail = SharePrefUtil.getString(ct, callServiceDetailUrl, null);
if (!TextUtils.isEmpty(monthDetail)) {
processData(monthDetail, true, 0, true);
}else{
showProgressDialog("正在加载");
}
// showProgressDialog("加载中...");
//查看服务设置
lookAndSetMonth(callServiceDetailUrl, true, 0, false);
return view;
}
/**
* 设置未选中则禁止输入
* setEnable
*
* @param isEnable
* void
*/
private void setEnable(boolean isEnable){
// et_ten_price.setEnabled(isEnable);
// et_twenty_price.setEnabled(isEnable);
// bt_ok.setEnabled(isEnable);
// m_service.setEnabled(isEnable);
if (isEnable) {
bt_ok.setVisibility(View.VISIBLE);
}else{
bt_ok.setVisibility(View.GONE);
}
}
@Override
public ResultState onLoad() {
return ResultState.STATE_SUCCESSED;
}
@Override
protected void processClick(View v) {
switch (v.getId()) {
case R.id.bt_ok:
//确定提交设置
submitSetting();
break;
case R.id.rl_setting_howLong:
// 服务时段
Intent intent = new Intent(ct, SelectDateTimeActivity.class);
intent.putExtra("callWeek", callWeek);//把获取的星期几传过去
intent.putExtra("startDate", startDateArr);//把选择的时间传过去,以便回显设置的时间
LogUtil.i("callWeek = "+callWeek+", startDate = "+startDateArr);
startActivityForResult(intent, RESILTCODE);
break;
default:
break;
}
}
/**
* 修改设置提交
* submitSetting
*
* void
*/
private void submitSetting() {
String ten_price = et_ten_price.getText().toString();//价格
String twenty_price = et_twenty_price.getText().toString();//次数
if (m_consultation.isChecked()) {
isEnable = "1";//开启
}else{
isEnable = "0";//关闭
}
if (TextUtils.isEmpty(ten_price) || TextUtils.isEmpty(twenty_price)) {
ToastUtil.showToast("请输入价格");
return ;
}
if (Double.parseDouble(ten_price) >= Double.parseDouble(twenty_price)) {
ToastUtil.showToast("10分钟的电话咨询价格不可以大于或者等于20分钟的电话咨询价格!");
return ;
}
if (0 > Double.parseDouble(ten_price)) {
ToastUtil.showToast("价格最小0元");
return ;
}
if (100000 < Double.parseDouble(ten_price)) {
ToastUtil.showToast("价格最大100000元");
return ;
}
if (0 > Double.parseDouble(twenty_price)) {
ToastUtil.showToast("价格最小0元");
return ;
}
if (100000 < Double.parseDouble(twenty_price)) {
ToastUtil.showToast("价格最大100000元");
return ;
}
if (TextUtils.isEmpty(callWeek) && TextUtils.isEmpty(startDate)) {
ToastUtil.showToast("请设置电话咨询时间");
return ;
}
showProgressDialog("提交中...");
//价格 (多个价格以逗号隔开) 必填
price = ten_price + "," + twenty_price;
//时长 (多个以逗号隔开,与价格一一对应)必填
howLong = "10,20";//这里按照页面的是10分钟,20分钟,写死,如果以后更改分钟,请注意。
//价格、人次等设置
lookAndSetMonth(callServiceFeeUrl, false, 1, false);
}
private void lookAndSetMonth(final String loadUrl, final boolean isLook, final int type, final boolean isCache) {
String expertUuid = SharePrefUtil.getString(UIUtils.getContext(), Constant.uuid, "");
RequestParams params = new RequestParams();//封装参数
if (isLook && 0 == type) {//判断是查看服务,还是设置服务
params.addBodyParameter("expertUuid", expertUuid);
}else if (!isLook && 1 == type) {//价格,人次设置
params.addBodyParameter("price", price);
params.addBodyParameter("howLong", howLong);
params.addBodyParameter("isEnable", isEnable);
params.addBodyParameter("expertUuid", expertUuid);
}else if (!isLook && 2 == type) {//时间设置
//取出电话咨询uuid
String callServiceUuid = SharePrefUtil.getString(ct, "callServiceUuid","");
params.addBodyParameter("callWeek", callWeek);
params.addBodyParameter("startDate", startDate);
params.addBodyParameter("callServiceUuid", callServiceUuid);
}
//请求数据
HttpHelper.loadData(HttpMethod.POST, loadUrl, params, new RequestCallBack<String>() {
@Override
public void onSuccess(ResponseInfo<String> info) {
if (isCache) {
SharePrefUtil.saveString(ct, callServiceDetailUrl, info.result);
}else{
processData(info.result, isLook, type, false);
}
}
@Override
public void onFailure(HttpException arg0, String arg1) {
LogUtil.i("数据请求失败了: " + arg1);
closeProgressDialog();
ToastUtil.showToast("请求失败,请稍候再试");
}
});
}
//解析数据
protected void processData(String result, boolean isLook, int type, boolean isCache) {
MonthDetailBean bean = GsonTools.fromGsonToBean(result,MonthDetailBean.class);
//判断是查看还是修改
if (isLook) {
SharePrefUtil.saveString(ct, callServiceDetailUrl, result);
closeProgressDialog();
if ("1".equals(bean.code)) {//查询成功
if (bean.data != null && !isCache) {
if (1 == bean.data.isEnable) {//是否开启,1是,0否
m_consultation.setChecked(true);
}else{
m_consultation.setChecked(false);
}
SharePrefUtil.saveBoolean(ct, "Telephone_m_consultation", m_consultation.isChecked());
}
//价格
List<DataFee> fee = bean.fee;
if (fee != null && fee.size() > 0) {
for (int i = 0; i < fee.size(); i++) {
int hl = fee.get(i).howLong;
// int price = Integer.parseInt(fee.get(i).price);
int price = (int) Math.round(Double.parseDouble(fee.get(i).price));
switch (hl) {
case 10://10分钟的价格
et_ten_price.setText(price+"");
break;
case 20://20分钟的
et_twenty_price.setText(price+"");
break;
default:
break;
}
}
}
LogUtil.i("bean.data====="+result);
//时间
List<DataTime> time = bean.time;
tv_howLong.setText("");
callWeek = "";
startDate = "";
if (time != null && time.size() > 0) {
for (int i = 0; i < time.size(); i++) {
String cw = time.get(i).callWeek;
String w = "";
if (!TextUtils.isEmpty(cw)) {
callWeek += cw + ",";
switch (Integer.parseInt(cw)) {
case 1:
w = "星期日 ";
break;
case 2:
w = "星期一 ";
break;
case 3:
w = "星期二 ";
break;
case 4:
w = "星期三 ";
break;
case 5:
w = "星期四 ";
break;
case 6:
w = "星期五 ";
break;
case 7:
w = "星期六 ";
break;
}
}
String sd = time.get(i).startDate;
String ed = time.get(i).endDate;
String m = sd + "-" + ed;
startDate += m + ";";
startDateArr += "#" + sd + ";";
//查看的回显
if (i == time.size() - 1) {
tv_howLong.append(w+m);
}else{
tv_howLong.append(w + m + ",");
}
}
}
//如果返回的code是 3 说明该服务已经被禁用 radiobutton禁用
}else if("3".equals(bean.code)){
SharePrefUtil.saveString(ct, callServiceDetailUrl, null);
m_consultation.setChecked(false);
m_consultation.setEnabled(false);
ToastUtil.showMessage(bean.message, 1);
}
} else {//修改设置
if ("1".equals(bean.code)) {//设置成功
if (1 == type) {
//时间设置
//保存电话uuid到sp
MonthDetailBean b = GsonTools.fromGsonToBean(result,MonthDetailBean.class);
SharePrefUtil.saveString(ct, "callServiceUuid",b.data.uuid);
if (1 == bean.data.isEnable) {//是否开启,1是,0否
SharePrefUtil.saveBoolean(ct, "Telephone_m_consultation", true);
}else{
SharePrefUtil.saveBoolean(ct, "Telephone_m_consultation", false);
}
lookAndSetMonth(callServiceTimeUrl, false, 2, false);
}else if (2 == type) {
closeProgressDialog();
ToastUtil.showToast("设置成功");
lookAndSetMonth(callServiceDetailUrl, true, 0, true);
}
}else{
closeProgressDialog();
ToastUtil.showToast(bean.message);
}
}
//初始化是否选中
if (m_consultation.isChecked()) {
setEnable(true);
}else{
setEnable(false);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
LogUtil.i("onActivityResult=="+requestCode+"==="+resultCode+"=="+data);
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESILTCODE && data != null && resultCode == Activity.RESULT_OK) {
startDate = "";
callWeek = "";
startDateArr = "";
hl = "";
String[] Date = data.getStringArrayExtra("startDates");
String[] Week = data.getStringArrayExtra("callWeeks");
String[] weeks = data.getStringArrayExtra("weeks");
String[] DateArr = data.getStringArrayExtra("DateArr");
//时间(与星期对应,以分号分隔,如当天设置多个时段,时段之间以逗号分隔。
//如周日8:00-9:00,13:00-15:00 周一8:00-15:00 周二 13:00-15:00,
//传参格式为”8:00-9:00,13:00-15:00;8:00-15:00;13:00-15:00;”)
for (int i = 0; i < Date.length; i++) {
if (!TextUtils.isEmpty(Date[i])) {
Date[i] = Date[i].substring(0, Date[i].length() - 1);
startDate += Date[i] + ";";
hl += weeks[i] + Date[i];
startDateArr += DateArr[i] + ";";
}
LogUtil.i("Date=="+Date[i] + "startDateArr="+ startDateArr);
}
//遍历星期,并以星期 (多天以逗号分隔,如周日、周一、周二,传参格式为”1,2,3”)传参
for (int i = 0; i < Week.length; i++) {
if (!TextUtils.isEmpty(Week[i])) {
callWeek += Week[i] + ",";
}
LogUtil.i("Week=="+Week[i]);
}
LogUtil.i("callWeek = "+callWeek+", startDate = "+startDate);
//回显
tv_howLong.setText(hl);
}
}
/**
* 服务是否开启
*/
private void operaterVIP(int type) {
String expertUuid = SharePrefUtil.getString(UIUtils.getContext(), Constant.uuid, "");
RequestParams params = new RequestParams();
params.addBodyParameter("expertUuid", expertUuid);
params.addBodyParameter("VIPType", String.valueOf(1));
params.addBodyParameter("operaterType", String.valueOf(type));
LogUtil.d("expertUuid = " + expertUuid + ", VIPType = 1" + ", operaterType = " + type);
showProgressDialog("操作中...");
HttpHelper.loadData(HttpMethod.POST, Url.operaterVIP, params, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
closeProgressDialog();
// ToastUtil.showToast(arg1);
LogUtil.d("onFailure = " + arg1);
m_consultation.toggle();
setEnable(false);
SharePrefUtil.saveBoolean(ct, "Telephone_m_consultation", m_consultation.isChecked());
}
@Override
public void onSuccess(ResponseInfo<String> info) {
closeProgressDialog();
LogUtil.d("onSuccess = " + info.result);
try {
JSONObject objs = new JSONObject(info.result);
String retcode = objs.getString("code");
String message = objs.getString("message");
if (retcode.equals(String.valueOf(1))) {
//ToastUtil.showToast("开启成功!");
} else if (retcode.equals(String.valueOf(3))) {
//ToastUtil.showToast("关闭成功");
setEnable(false);
//如果返回状态是5 说明该专家所在医院或地区限制开启服务 默认关闭该服务
} else if (retcode.equals(String.valueOf(5))){
ToastUtil.showToast(message);
m_consultation.toggle();
setEnable(false);
m_consultation.setEnabled(false);
}else{
ToastUtil.showToast(message);
m_consultation.toggle();
setEnable(false);
}
SharePrefUtil.saveBoolean(ct, "Telephone_m_consultation", m_consultation.isChecked());
} catch (JSONException e) {
e.printStackTrace();
// ToastUtil.showToast("提交失败!");
m_consultation.toggle();
setEnable(false);
SharePrefUtil.saveBoolean(ct, "Telephone_m_consultation", m_consultation.isChecked());
}
}
});
}
}