<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/ll_title"
layout="@layout/title" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ll_title"
android:background="#fff"
android:orientation="vertical"
android:overScrollMode="never"
android:padding="@dimen/px10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_etid_reimburse_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_save"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="50dp"
android:layout_marginRight="5dp"
android:background="#ff336699"
android:gravity="center"
android:text="保 存"
android:textColor="@android:color/white" />
LinearLayout>
android.support.v4.widget.NestedScrollView>
RelativeLayout>
package com.example.zxingdemo1.ui.reimbursement.activity;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.zxingdemo1.R;
import com.example.zxingdemo1.base.BaseActivity;
import com.example.zxingdemo1.ui.bean.production.OtherWorkOrderEntity;
import com.example.zxingdemo1.ui.production.adapter.OtherWorkOrderListAdapter;
import com.example.zxingdemo1.ui.reimbursement.adapter.ReimburseEditDetailAdapter;
import com.example.zxingdemo1.ui.reimbursement.entity.DbBaoxiaoDetail;
import com.example.zxingdemo1.util.SpacesItemDecoration;
import com.example.zxingdemo1.util.ToastUitl;
import java.io.Serializable;
import java.math.BigDecimal;
import java.security.spec.ECField;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.addapp.pickers.common.LineConfig;
import cn.addapp.pickers.listeners.OnItemPickListener;
import cn.addapp.pickers.picker.DateTimePicker;
import cn.addapp.pickers.picker.SinglePicker;
public class AddReimbursementDetailActivity extends BaseActivity implements View.OnClickListener {
private RecyclerView rv;
private Button btn_save;
private String[] reimburseType = {"客户招待费(在联系任务/跟进、客户来访跟进、产生销售机会、签订合同订单)的情况下产生的客户招待费",
"销售代表交通费(必须有出差客户住址的跟进活动的交通费用)", "销售代表误餐费", "销售代表车辆补助费", "销售代表住宿费",
"分公司房租水电费", "展位费、电气租赁、搭建费、运输费、试机材料费、", "展会人员交通、住宿、伙食费",
"展会客户招待费(包含住宿,吃饭,交通)", "广告费(包含网络推广,网站建设,维护,所有形式的广告)",
"广告礼品费(包括节日礼品,展会礼品,平时交际礼品,推广礼品)", "宣传品费(包含画册,U盘,宣传喷绘等)", "交货叉(吊)车费"};
private ReimburseEditDetailAdapter adapter;
private List<DbBaoxiaoDetail> mList = new ArrayList<>();
private List<DbBaoxiaoDetail> saveDetail = new ArrayList<>();
@Override
protected int setLayoutResId() {
return R.layout.activity_add_reimbursement_detail;
}
@Override
public void initView() {
setTitle("新建-费用报销明细");
setTitleLeftImg(R.mipmap.back_white);
rv = findViewById(R.id.rv_etid_reimburse_detail);
btn_save = findViewById(R.id.btn_save);
btn_save.setOnClickListener(this);
DbBaoxiaoDetail detail = new DbBaoxiaoDetail();
mList.add(detail);
LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
rv.setItemViewCacheSize(500);
rv.setLayoutManager(mLinearLayoutManager);
rv.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
adapter = new ReimburseEditDetailAdapter(mList);
rv.setAdapter(adapter);
adapter.replaceData(mList);
adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
if (view.getId() == R.id.img_add) {
mList.add(detail);
adapter.setNewData(mList);
} else if (view.getId() == R.id.img_delete) {
mList.remove(position);
adapter.setNewData(mList);
} else if (view.getId() == R.id.iv_shenqingriqi||view.getId() == R.id.tv_fashengriqi) {
onYearMonthDayTimePicker(position);
} else if (view.getId() == R.id.ll_zhuti) {
onRoadPicker(reimburseType, 1, position);
}
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_save:
for (int i = 0; i < mList.size(); i++) {
View itemView = rv.getLayoutManager().findViewByPosition(i);
String tv_zhuti = ((TextView) itemView.findViewById(R.id.tv_zhuti)).getText().toString();
String tv_fashengriqi = ((TextView) itemView.findViewById(R.id.tv_fashengriqi)).getText().toString();
String et_jine = ((TextView) itemView.findViewById(R.id.et_jine)).getText().toString().trim();
BigDecimal jine=new BigDecimal("0");
try {
jine = new BigDecimal(et_jine);
} catch (Exception e) {
e.printStackTrace();
}
String et_piaojuzhangshu = ((EditText) itemView.findViewById(R.id.et_piaojuzhangshu)).getText().toString().trim();
String et_yongtu = ((EditText) itemView.findViewById(R.id.et_yongtu)).getText().toString().trim();
if (!TextUtils.isEmpty(tv_zhuti) &&
!TextUtils.isEmpty(tv_fashengriqi) &&
!TextUtils.isEmpty(et_jine)&&
!TextUtils.isEmpty(et_piaojuzhangshu)
) {
DbBaoxiaoDetail detail = new DbBaoxiaoDetail(tv_zhuti, tv_fashengriqi, jine, Integer.valueOf(et_piaojuzhangshu), et_yongtu);
saveDetail.add(detail);
} else {
ToastUitl.showShort(getString(R.string.string_wtite_all));
return;
}
}
BigDecimal allJinE = new BigDecimal("0");
int piaoJuZhangshu = 0;
for (int i = 0; i < saveDetail.size(); i++) {
allJinE = allJinE.add(saveDetail.get(i).getJine());
piaoJuZhangshu += saveDetail.get(i).getPiaojuzhangshu();
}
Intent intent = new Intent();
intent.putExtra("details", (Serializable) saveDetail);
intent.putExtra("allJinE", allJinE.toPlainString());
intent.putExtra("piaoJuZhangshu", piaoJuZhangshu);
setResult(Activity.RESULT_OK, intent);
finish();
break;
}
}
public void onRoadPicker(String[] list, int type, int position) {
SinglePicker<String> picker = new SinglePicker<>(this, list);
picker.setCanLoop(false);
picker.setTopBackgroundColor(Color.WHITE);
picker.setTopHeight(50);
picker.setTitleText("请选择");
picker.setSelectedTextColor(getResources().getColor(R.color.base_color));
picker.setWheelModeEnable(false);
LineConfig config = new LineConfig();
config.setColor(getResources().getColor(R.color.base_color));
config.setAlpha(120);
picker.setLineConfig(config);
picker.setItemWidth(200);
picker.setOnItemPickListener(new OnItemPickListener<String>() {
@Override
public void onItemPicked(int index, String item) {
if (type == 1) {
View itemView = rv.getLayoutManager().findViewByPosition(position);
TextView tv_zhuti = itemView.findViewById(R.id.tv_zhuti);
tv_zhuti.setText(item);
} else if (type == 2) {
}
}
});
picker.show();
}
public void onYearMonthDayTimePicker(int position) {
DateTimePicker picker = new DateTimePicker(this, DateTimePicker.HOUR_24);
picker.setCanLoop(false);
picker.setTopBackgroundColor(Color.WHITE);
picker.setTopHeight(50);
picker.setTitleText("请选择");
LineConfig config = new LineConfig();
config.setColor(getResources().getColor(R.color.base_color));
config.setAlpha(120);
picker.setLineConfig(config);
picker.setSelectedTextColor(getResources().getColor(R.color.base_color));
picker.setTopPadding(15);
picker.setCanLinkage(true);
picker.setDateRangeStart(2017, 1, 1);
picker.setDateRangeEnd(2050, 12, 31);
Calendar cal = Calendar.getInstance();
picker.setSelectedItem(cal.get(Calendar.YEAR), (cal.get(Calendar.MONTH) + 1), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
picker.setTimeRangeStart(9, 0);
picker.setTimeRangeEnd(20, 30);
picker.setWeightEnable(true);
picker.setWheelModeEnable(true);
picker.setOnDateTimePickListener(new DateTimePicker.OnYearMonthDayTimePickListener() {
@Override
public void onDateTimePicked(String year, String month, String day, String hour, String minute) {
View itemView = rv.getLayoutManager().findViewByPosition(position);
TextView tv_fashengriqi = itemView.findViewById(R.id.tv_fashengriqi);
tv_fashengriqi.setText(year + "-" + month + "-" + day);
}
});
picker.show();
}
}
package com.example.zxingdemo1.ui.reimbursement.adapter;
import android.view.View;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.zxingdemo1.R;
import com.example.zxingdemo1.ui.bean.DbCustomXiaoshoujihui;
import com.example.zxingdemo1.ui.reimbursement.entity.DbBaoxiaoDetail;
import java.util.ArrayList;
import java.util.List;
public class ReimburseEditDetailAdapter extends BaseQuickAdapter<DbBaoxiaoDetail, BaseViewHolder> {
private List<DbBaoxiaoDetail> mList;
public ReimburseEditDetailAdapter(List<DbBaoxiaoDetail> list) {
super(R.layout.item_edit_reimburse_detail);
this.mList = list;
}
@Override
protected void convert(BaseViewHolder helper, DbBaoxiaoDetail item) {
if ((mList.size() - 1) == helper.getPosition()) {
helper.getView(R.id.img_add).setVisibility(View.VISIBLE);
helper.getView(R.id.img_delete).setVisibility(View.GONE);
}else{
helper.getView(R.id.img_add).setVisibility(View.GONE);
helper.getView(R.id.img_delete).setVisibility(View.VISIBLE);
}
helper.addOnClickListener(R.id.img_add);
helper.addOnClickListener(R.id.img_delete);
helper.addOnClickListener(R.id.iv_shenqingriqi);
helper.addOnClickListener(R.id.tv_fashengriqi);
helper.addOnClickListener(R.id.ll_zhuti);
}
}