package com.example.administrator.zhapp.activity.ydckgl;

import android.content.DialogInterface;
import android.content.Intent;
import androidx.appcompat.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

import com.example.administrator.zhapp.BaseListViewAdapter.CommonAdapter;
import com.example.administrator.zhapp.BaseListViewAdapter.ViewHolder;
import com.example.administrator.zhapp.R;
import com.example.administrator.zhapp.activity.BaseActivity;
import com.example.administrator.zhapp.adapter.SpinnerAdapter;
import com.example.administrator.zhapp.adapter.WlffAdapter;
import com.example.administrator.zhapp.contans.Contans;
import com.example.administrator.zhapp.entity.FfjlInfo;
import com.example.administrator.zhapp.entity.HgInfo;
import com.example.administrator.zhapp.entity.LlrInfo;
import com.example.administrator.zhapp.entity.StatusInfo;
import com.example.administrator.zhapp.entity.WebServiceResult;
import com.example.administrator.zhapp.entity.WlffInfo;
import com.example.administrator.zhapp.utils.EditTextListener;
import com.example.administrator.zhapp.utils.GsonUtils;
import com.example.administrator.zhapp.utils.HttpListener;
import com.example.administrator.zhapp.utils.KsoapUtils;
import com.example.administrator.zhapp.utils.NohttpUtils;
import com.example.administrator.zhapp.utils.SPUtils;
import com.example.administrator.zhapp.utils.UiUtlis;
import com.example.administrator.zhapp.weight.WaitDialog;
import com.orhanobut.logger.Logger;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.RequestMethod;
import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.Response;
import org.ksoap2.serialization.SoapObject;
import java.util.ArrayList;
import java.util.List;

/**
 * 移动仓库管理-物料发放
 */
public class MaterialIssue extends BaseActivity implements WlffAdapter.CallBack {

    EditText gdh;
    Button btn_query;
    ListView lv;
    Spinner sp_hg;
    TextView sp_sx;
    TextView tv_yl;
    EditText et_ffsl;
    Button btn_save;
    Button btn_cancle;
    LinearLayout ll;
    TextView et_llr;
    EditText xm;
    Button btn_yyl;
    ListView yyl;
    Button btn_ffjl;
    Button btn_it;
    TextView tvPch;

    private View headView;
    private View yylHeadView;
    private WlffInfo info;
    private List<WlffInfo.Wlff> lists;
    private List<WlffInfo.Wlff> ylxms;
    private WlffAdapter adapter;
    private LlrInfo.Llr llr;
    private String num;
    private EditTextListener etlistener;
    private List<HgInfo.Hg> hgs;
    private SpinnerAdapter sadapter;
    private double klsl;//可领取数量
    private CommonAdapter<WlffInfo.Wlff> cAdapter;
    private List<FfjlInfo.Ffjl> ffjls;


    private WaitDialog laoding;

    private int seletcitem = -1;

    private void findView() {
        gdh = findViewById(R.id.gdh);
        btn_query = findViewById(R.id.btn_query);
        lv = findViewById(R.id.lv);
        sp_hg = findViewById(R.id.sp_hg);
        sp_sx = findViewById(R.id.sp_sx);
        tv_yl = findViewById(R.id.tv_yl);
        et_ffsl = findViewById(R.id.et_ffsl);
        btn_save = findViewById(R.id.btn_save);
        btn_cancle = findViewById(R.id.btn_cancel);
        ll = findViewById(R.id.ll);
        et_llr = findViewById(R.id.et_llr);
        xm = findViewById(R.id.xm);
        btn_yyl = findViewById(R.id.btn_yyl);
        yyl = findViewById(R.id.yyl);
        btn_ffjl = findViewById(R.id.btn_ffjl);
        btn_it = findViewById(R.id.btn_it);
        tvPch = findViewById(R.id.tv_pch);
        btn_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (hgs.size() == 0) {
                    showToast("你还没有选择项目");
                    return;
                }

                if (et_llr.getText().toString().isEmpty()) {
                    showToast("领料人不能为空");
                    return;
                }

                if (UiUtlis.isEmpty(et_ffsl)) {
                    showToast("发放数量不能为空");
                    return;
                }

                double ffsl = UiUtlis.getNum(et_ffsl.getText().toString());
                HgInfo.Hg hg = (HgInfo.Hg) sp_hg.getSelectedItem();
                double yl = UiUtlis.getNum(hg.getCurbal());
                if (ffsl > yl) {
                    showToast("发放数量不能大于余量");
                    return;
                }

                matuIssue();
            }
        });
        btn_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        btn_query.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //隐藏软键盘
                UiUtlis.hideInput(gdh, context);
                num = gdh.getText().toString().trim();
                if (!TextUtils.isEmpty(num) || !TextUtils.isEmpty(UiUtlis.getText(xm))) {
                    sendNoHttpRequest(UiUtlis.getString(context, R.string.loading), "wonum", num, CX_FLAG);
                } else {
                    showToast("请输入物料编码或项目号");
                }
            }
        });
        et_llr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MaterialIssue.this, LlrActivity.class);
                startActivityForResult(intent, 0);
            }
        });
        btn_yyl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendNoHttpRequest(UiUtlis.getString(context, R.string.loading), "record", "all", 3);
                gdh.setText("");
                xm.setText("");
            }
        });
        btn_ffjl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (seletcitem != -1 && lists.size() != 0 || ylxms.size() != 0) {
                    if (lv.getVisibility() == View.VISIBLE) {
                        requestFfjl(lists.get(seletcitem).getItemnum());
                    } else {
//                        requestFfjl(ylxms.get(seletcitem).getItemnum());
                    }
                } else {
                    requestFfjl(UiUtlis.getText(xm));
                }
            }
        });
        btn_it.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                xm.setText("IT");
                xm.setSelection(2);
            }
        });
    }

    @Override
    public int getContentViewID() {
        return R.layout.activity_material_issue;
    }

    protected void initView() {
        findView();
    }

    public void initData() {

        laoding = new WaitDialog(context, "加载中...");


        hgs = new ArrayList<>();
        lists = new ArrayList<>();
        ylxms = new ArrayList<>();
        llr = new LlrInfo.Llr();
        ffjls = new ArrayList<>();
        setTitle("物料发放");
        setBack();
        //gdh.setText("ZHP1363");
        yylHeadView = View.inflate(this, R.layout.ylxm_item, null);
        yylHeadView.findViewById(R.id.head).setVisibility(View.VISIBLE);
        yylHeadView.findViewById(R.id.cb_isprint).setEnabled(false);
        headView = View.inflate(this, R.layout.receive_list, null);
        headView.findViewById(R.id.head).setVisibility(View.VISIBLE);
        headView.findViewById(R.id.cb_isprint).setEnabled(false);
//        headView.findViewById(R.id.ll).setVisibility(View.GONE);
        TextView tv = (TextView) headView.findViewById(R.id.tv_count);
        tv.setText("已预留数量");
        TextView tv1 = (TextView) headView.findViewById(R.id.tv_kjs);
        tv1.setText("工单");
        etlistener = new EditTextListener(MaterialIssue.this);
//        et_ffsl.addTextChangedListener(etlistener);
        et_ffsl.setEnabled(false);
    }

    private void showFfjl() {

        laoding.dismiss();

        final View view = View.inflate(context, R.layout.fljl_list, null);
        ListView lv = (ListView) view.findViewById(R.id.lv);

        CommonAdapter<FfjlInfo.Ffjl> ffjhadapter = new CommonAdapter<FfjlInfo.Ffjl>(context, R.layout.ffjl_item, ffjls) {
            @Override
            protected void convert(ViewHolder viewHolder, FfjlInfo.Ffjl item, int position) {
                viewHolder.setText(R.id.tv_xh, (position + 1) + "");
                viewHolder.setText(R.id.tv_ms, item.getDescription());
                viewHolder.setText(R.id.tv_date, item.getTransdate());
                viewHolder.setText(R.id.tv_ffd, item.getIssueto());
                viewHolder.setText(R.id.tv_name, item.getDisplayname());
                viewHolder.setText(R.id.tv_gd, item.getRefwo());
                viewHolder.setText(R.id.tv_wz, item.getLocation());
                viewHolder.setText(R.id.tv_zc, item.getAssetnum());
                viewHolder.setText(R.id.tv_sl, item.getQuantity());
                viewHolder.setText(R.id.tv_dwcb, item.getUnitcost());
                viewHolder.setText(R.id.tv_hcb, item.getLinecost());
                viewHolder.setText(R.id.tv_jylx, item.getIssuetype());
                viewHolder.setText(R.id.tv_hg, item.getBinnum());
                viewHolder.setText(R.id.tv_srr, item.getEnterby());
                viewHolder.setText(R.id.tv_xm, item.getItemnum());
            }
        };
        View head = View.inflate(context, R.layout.ffjl_item, null);
        head.findViewById(R.id.head).setVisibility(View.VISIBLE);
        lv.addHeaderView(head, null, false);
        lv.setAdapter(ffjhadapter);
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setView(view);
        builder.setCancelable(false);
        builder.setTitle("发放记录");
        builder.setPositiveButton("返回", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.create().show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0 && resultCode == 0) {
            if (data != null) {
                try {
                    llr = data.getExtras().getParcelable("LLR");
                    et_llr.setText(llr.getUsername());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 发送请求
     */
    private void sendNoHttpRequest(String msg, String param, String value, int what) {
        Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.WLFF);
        request.set(param, value);
        if (!param.equals("itemnum") && !param.equals("record")) {
            request.set("itemnum1", xm.getText().toString());
        }
        NohttpUtils.getInstance().add(this, what, request, listener, true, true, msg);
    }


    //调用webservice  发放接口
    private void matuIssue() {

        final WaitDialog dialog = new WaitDialog(context, "保存中...");
        dialog.show();

        KsoapUtils.callWebService(Contans.CK_BASE_IP + Contans.MATUSER_IP, "matuIssue", properties(), new KsoapUtils.CallBack() {
            @Override
            public void callBack(SoapObject result) {

                dialog.dismiss();

                if (result != null) {
                    WebServiceResult webServiceResult = GsonUtils.GsonToBean(result.getProperty(0).toString(), WebServiceResult.class);

                    if (webServiceResult.getStatus().equals("success")) {

                        showToast("保存成功");
                        clearView();
                        if (lv.getVisibility() == View.VISIBLE) {
                            sendNoHttpRequest(UiUtlis.getString(context, R.string.refresh), "wonum", num, CX_FLAG);
                        } else {
                            sendNoHttpRequest(UiUtlis.getString(context, R.string.loading), "record", "all", 3);
                        }

                    } else {
                        showToast("保存失败");
                    }
                } else {
                    showToast(UiUtlis.getString(context, R.string.data_error));
                }
            }
        });
    }


    /**
     * 上传数据
     */
    private void sendNoHttpRequestPost() {
        Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.WLFFSC, RequestMethod.POST);
        request.setDefineRequestBodyForJson(toJson());
        Logger.v(toJson());
        NohttpUtils.getInstance().add(this, SC_FLAG, request, listener, true, true, "上传中...");
    }

    private void requestFfjl(String itemnum) {
        laoding.show();
        Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.WLFFJL);
        request.set("itemnum", itemnum);
        request.set("status", "1");
        NohttpUtils.getInstance().add(this, 4, request, listener, true, true, "加载中...");
    }

    private HttpListener<String> listener = new HttpListener<String>() {
        @Override
        public void onSucceed(int what, Response<String> response) {

            System.out.println("json" + response.get());
            Logger.json(response.get());
            switch (what) {
                case CX_FLAG:
                    info = GsonUtils.GsonToBean(response.get(), WlffInfo.class);
                    if (info != null) {
                        if (info.getTotal() != 0) {
                            lists.clear();
                            lists.addAll(info.getRows());
                            initListData();
                        } else {

                            lists.clear();
                            seletcitem = -1;

                            if (adapter != null) {
                                if (lv.getHeaderViewsCount() == 1) {
                                    lv.removeHeaderView(headView);
                                }
                                adapter.notifyDataSetChanged();
                            }

                            showToast("没有查到符合条件记录");
                            ll.setVisibility(View.GONE);
                        }
                        clearView();
                    } else {
                        showToast(UiUtlis.getString(context, R.string.data_error));
                    }
                    break;
                case SC_FLAG:
                    StatusInfo info = GsonUtils.GsonToBean(response.get(), StatusInfo.class);
                    if (info != null) {
                        String status = info.getRows().get(0).getStatus();
                        if (status.equals("1")) {
                            showToast(UiUtlis.getString(context, R.string.upload_success));
                            clearView();
                            if (lv.getVisibility() == View.VISIBLE) {
                                sendNoHttpRequest(UiUtlis.getString(context, R.string.refresh), "wonum", num, CX_FLAG);
                            } else {
                                sendNoHttpRequest(UiUtlis.getString(context, R.string.loading), "record", "all", 3);
                            }
                        } else if (status.equals("0")) {
                            showToast(UiUtlis.getString(context, R.string.upload_error));
                        }
                    } else {
                        showToast(UiUtlis.getString(context, R.string.data_error));
                    }
                    break;
                case 2:
                    HgInfo hg = GsonUtils.GsonToBean(response.get(), HgInfo.class);
                    if (hg != null) {
                        hgs.clear();
                        hgs.addAll(hg.getRows());
                        setSpinnerData();
                    } else {
                        showToast(UiUtlis.getString(context, R.string.data_error));
                    }
                    break;
                case 3:
                    WlffInfo wlffInfo = GsonUtils.GsonToBean(response.get(), WlffInfo.class);
                    if (wlffInfo != null) {
                        if (wlffInfo.getTotal() != 0) {
                            ylxms.clear();
                            ylxms.addAll(wlffInfo.getRows());
                            setylxmList();
                        } else {
                            ylxms.clear();
                            seletcitem = -1;
                            setylxmList();
                        }
                        clearView();
                    } else {
                        showToast("数据解析出错");
                    }
                    break;
                //物料发放
                case 4:
                    FfjlInfo ffjlInfo = GsonUtils.GsonToBean(response.get(), FfjlInfo.class);
                    if (ffjlInfo != null) {
                        if (!ffjlInfo.getTotal().equals("0")) {
                            ffjls.clear();
                            ffjls.addAll(ffjlInfo.getRows());
                            showFfjl();
                        } else {
                            showToast("没有发放记录");
                            laoding.dismiss();
                        }

                    } else {
                        showToast("数据出错");
                        laoding.dismiss();
                    }
                    break;
            }
        }

        @Override
        public void onFailed(int what, Response<String> response) {

            if (laoding.isShowing() && laoding != null) {
                laoding.dismiss();
            }
        }
    };

    //设置货柜列表adapter
    private void setSpinnerData() {
        if (sadapter == null && hgs.size() != 0) {
            sadapter = new SpinnerAdapter(hgs, context);
            sp_hg.setAdapter(sadapter);
            tv_yl.setText(hgs.get(0).getCurbal());
            tvPch.setText(hgs.get(0).getLotnum());
//            etlistener.setNum(hgs.get(0).getCurbal());
//            etlistener.setMsg("发放数量不能大于当前余量");
            et_ffsl.setText(lv.getVisibility() == View.VISIBLE ? lists.get(seletcitem).getItemqty() : ylxms.get(seletcitem).getItemqty());
            sp_hg.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                    tv_yl.setText(hgs.get(position).getCurbal());
                    tvPch.setText(hgs.get(position).getLotnum());
//                    etlistener.setNum(hgs.get(position).getCurbal());
//                    etlistener.setMsg("发放数量不能大于当前余量");

                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                }
            });
        } else if (sadapter != null) {
            sadapter.notifyDataSetChanged();
            if (hgs.size() != 0) {
                tv_yl.setText(hgs.get(0).getCurbal());
                tvPch.setText(hgs.get(0).getLotnum());
//                etlistener.setNum(hgs.get(0).getCurbal());
//                etlistener.setMsg("发放数量不能大于当前余量");
                et_ffsl.setText(lv.getVisibility() == View.VISIBLE ? lists.get(seletcitem).getItemqty() : ylxms.get(seletcitem).getItemqty());
            } else {
                tv_yl.setText("");
                tvPch.setText("");
            }
        }
    }

    /**
     * 有数据，给listview填充数据
     */
    private void initListData() {
        ll.setVisibility(View.VISIBLE);
        yyl.setVisibility(View.GONE);
        lv.setVisibility(View.VISIBLE);
        if (lv.getHeaderViewsCount() == 0) {
            lv.addHeaderView(headView, null, false);
        }
        if (adapter == null) {
            adapter = new WlffAdapter(lists, this, this);
            lv.setAdapter(adapter);
        } else {
            adapter.notifyDataSetChanged();
        }
    }

    /**
     * checkbox点击事件
     *
     * @param view
     */
    @Override
    public void onClick(View view) {
        CheckBox cb = (CheckBox) view;
        int index = (int) cb.getTag();
        //如果没有选中。
        if (cb.isChecked() == false) {
            lists.get(index).setPrint(false);
            Logger.v("执行到这里..click" + index);
            clearView();
            seletcitem = -1;
        } else {
            seletcitem = index;
            lists.get(index).setPrint(true);
            for (int a = 0; a < lists.size(); a++) {
                if (a != index) {
                    lists.get(a).setPrint(false);
                }
            }
            updateView(lists.get(index));
//            etlistener.setNum();
//            etlistener.setMsg("发放数量不能大于当前余量");
        }
        adapter.notifyDataSetChanged();
    }

    private void updateView(WlffInfo.Wlff wlff) {
        sendNoHttpRequest("加载货柜中...", "itemnum", wlff.getItemnum(), 2);
        //sp_hg.setText(wlff.getBinnum());
        sp_sx.setText(wlff.getStocktype());
        et_ffsl.setEnabled(true);
//        et_ffsl.setText(wlff.getItemqty());
        et_llr.setEnabled(true);
    }

    //设置预留项目列表
    private void setylxmList() {
        ll.setVisibility(View.VISIBLE);
        lv.setVisibility(View.GONE);
        yyl.setVisibility(View.VISIBLE);
        if (yyl.getHeaderViewsCount() == 0) {
            yyl.addHeaderView(yylHeadView, null, false);
        }
        if (cAdapter == null) {
            cAdapter = new CommonAdapter<WlffInfo.Wlff>(context, R.layout.ylxm_item, ylxms) {
                @Override
                protected void convert(ViewHolder viewHolder, final WlffInfo.Wlff item, final int position) {
                    viewHolder.setOnClickListener(R.id.cb_isprint, new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            CheckBox cb = (CheckBox) v;
                            if (cb.isChecked() == false) {
                                ylxms.get(position).setPrint(false);
                                clearView();
                                seletcitem = -1;
                            } else {
                                ylxms.get(position).setPrint(true);
                                for (int a = 0; a < ylxms.size(); a++) {
                                    if (a != position) {
                                        ylxms.get(a).setPrint(false);
                                    }
                                }
                                updateView(item);
                                seletcitem = position;
//                                etlistener.setNum("");
//                                etlistener.setMsg("发放数量不能大于当前余量");
                            }
                            cAdapter.notifyDataSetChanged();
                        }
                    });
                    viewHolder.setText(R.id.tv_xh, (position + 1) + "");
                    viewHolder.setChecked(R.id.cb_isprint, item.isPrint());
                    viewHolder.setText(R.id.tv_xm, item.getItemnum());//项目
                    viewHolder.setText(R.id.tv_ms, item.getDescription());//描述
                    viewHolder.setText(R.id.tv_count, item.getItemqty());//已预留数量
                    viewHolder.setText(R.id.tv_gd, item.getWonum());//工单
                    viewHolder.setText(R.id.tv_gzlx, item.getWtypedesc());//工作类型
                    viewHolder.setText(R.id.tv_bz, item.getCrewid());//班组
                    viewHolder.setText(R.id.tv_fzr, item.getReportedby());//工作负责人
                    viewHolder.setText(R.id.tv_pzr, item.getRequestedby());//批准人
                    viewHolder.setText(R.id.tv_date, item.getRequireddate());//申请日期
                    viewHolder.setText(R.id.tv_xgzy, item.getIn6());//相关专业
                    viewHolder.setText(R.id.tv_dw, item.getRestype());//单位
                }
            };
            yyl.setAdapter(cAdapter);
        } else {
            cAdapter.notifyDataSetChanged();
        }
    }

    private void clearView() {
        sp_sx.setText("");
        tv_yl.setText("");
        tvPch.setText("");
        et_llr.setText("");
        et_llr.setEnabled(false);
        et_ffsl.setText("");
        et_ffsl.setEnabled(false);
        hgs.clear();
        setSpinnerData();
    }

    private String toJson() {
        String json = "";
        if (lv.getVisibility() == View.VISIBLE) {
            for (int i = 0; i < lists.size(); i++) {
                if (lists.get(i).isPrint()) {
                    WlffInfo info = new WlffInfo();
                    List<WlffInfo.Wlff> list = new ArrayList<>();
                    info.setTotal(1);
                    WlffInfo.Wlff wlff = new WlffInfo.Wlff();
                    wlff = lists.get(i);
                    HgInfo.Hg hg = (HgInfo.Hg) sp_hg.getSelectedItem();
                    wlff.setBinnum(hg.getBinnum());
                    wlff.setFfsl(et_ffsl.getText().toString());
                    wlff.setIssueto(llr.getUserid());
                    wlff.setEnterby((String) SPUtils.get(MaterialIssue.this, Contans.USERNAME, ""));
                    list.add(wlff);
                    info.setRows(list);
                    json = GsonUtils.GsonString(info);
                }
            }
        } else {
            for (int i = 0; i < ylxms.size(); i++) {
                if (ylxms.get(i).isPrint()) {
                    WlffInfo info = new WlffInfo();
                    List<WlffInfo.Wlff> list = new ArrayList<>();
                    info.setTotal(1);
                    WlffInfo.Wlff wlff = new WlffInfo.Wlff();
                    wlff = ylxms.get(i);
                    HgInfo.Hg hg = (HgInfo.Hg) sp_hg.getSelectedItem();
                    wlff.setBinnum(hg.getBinnum());
                    wlff.setFfsl(et_ffsl.getText().toString());
                    wlff.setIssueto(llr.getUserid());
                    wlff.setEnterby((String) SPUtils.get(MaterialIssue.this, Contans.USERNAME, ""));
                    list.add(wlff);
                    info.setRows(list);
                    json = GsonUtils.GsonString(info);
                }
            }
        }
        return json;
    }


    //请求参数
    private List properties() {
//        String json = "";

        List<String> properties = new ArrayList<String>();

        if (lv.getVisibility() == View.VISIBLE) {
            for (int i = 0; i < lists.size(); i++) {
                if (lists.get(i).isPrint()) {
                    WlffInfo info = new WlffInfo();
                    List<WlffInfo.Wlff> list = new ArrayList<>();
//                    info.setTotal(1);
                    WlffInfo.Wlff wlff = new WlffInfo.Wlff();
                    wlff = lists.get(i);
                    HgInfo.Hg hg = (HgInfo.Hg) sp_hg.getSelectedItem();

                    properties.add(wlff.getWonum());//工单编号
                    properties.add(wlff.getItemnum());//物资编码
                    properties.add(UiUtlis.getText(et_ffsl));//发放数量
                    properties.add((String) SPUtils.get(context, Contans.USERNAME, ""));//发放人
                    properties.add(hg.getBinnum().isEmpty() ? "" : hg.getBinnum());//货柜号
//                    properties.add("项目");
                    properties.add(llr.getUserid());//领料人
                    properties.add(wlff.getLocation());//仓库
//                    properties.add("发放");
                    properties.add(wlff.getRequestnum());//请求号
                    properties.add(hg.getLotnum());//批次号

                }
            }
        } else {
            for (int i = 0; i < ylxms.size(); i++) {
                if (ylxms.get(i).isPrint()) {
                    WlffInfo info = new WlffInfo();
                    List<WlffInfo.Wlff> list = new ArrayList<>();
                    info.setTotal(1);
                    WlffInfo.Wlff wlff = new WlffInfo.Wlff();
                    wlff = ylxms.get(i);
                    HgInfo.Hg hg = (HgInfo.Hg) sp_hg.getSelectedItem();

                    properties.add(wlff.getWonum());//工单编号
                    properties.add(wlff.getItemnum());//物资编码
                    properties.add(UiUtlis.getText(et_ffsl));//发放数量
                    properties.add((String) SPUtils.get(context, Contans.USERNAME, ""));//发放人
                    properties.add(hg.getBinnum());//货柜号
                    properties.add(llr.getUserid());
//                    properties.add("项目");
                    properties.add(wlff.getLocation());//仓库
//                    properties.add("发放");
                    properties.add(wlff.getRequestnum());//请求号
                    properties.add(hg.getLotnum());//批次号
                }
            }
        }
        return properties;
    }
}