package com.qhclh.ytzh.work.carsmannage;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ListView;

import com.qhclh.ytzh.R;
import com.qhclh.ytzh.base.BaseActivity;
import com.qhclh.ytzh.bean.ScanBean;
import com.qhclh.ytzh.home.RpcUrl;
import com.qhclh.ytzh.tasks.ViewOnClickTask;
import com.qhclh.ytzh.utils.DateTimeUtil;
import com.qhclh.ytzh.work.scan.ScanAdapter;

import org.forks.jsonrpc.JsonRpcResult;
import org.forks.jsonrpc.RpcFacade;
import org.forks.jsonrpc.RpcObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by 青花瓷 on 2018/1/22.
 */

public class FumudaiCarsinfoActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.fumudai_lv_infos)
    ListView fumudai_lv_infos;

    private long id;
    private List<ScanBean> scanBeanList;
    private ScanAdapter scanAdapter;
    @Override
    protected int setLayoutId() {
        return R.layout.act_fumudaiscanresult;
    }

    @Override
    protected void initView() {
        initToolbar(mToolbar, "运输记录", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void initData() {
        id = getIntent().getLongExtra("id",0);
        scanBeanList = new ArrayList<>();
    }

    @Override
    protected void initOper() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        load();
    }

    private void load() {
        ViewOnClickTask loadTask = new ViewOnClickTask(this,"加载中...") {
            RpcObject rpcObj;
            @Override
            protected void successUI() {
                scanBeanList.clear();
                ScanBean scanBean = new ScanBean();
                scanBean.setId(rpcObj.getLong("ID"));
                scanBean.setInfos_carname(rpcObj.getString("Car_Name"));
                scanBean.setInfos_driver(rpcObj.getString("Employee_Name"));
                scanBean.setInfos_fuhuachang(rpcObj.getString("Hatchery_Name"));
                scanBean.setInfos_yangzhichang(rpcObj.getString("BreedFactory_Name"));
                if (rpcObj.getDate("LeaveHatcheryTime")!=null) {
                    scanBean.setInfos_leavetime(DateTimeUtil.getYMD4(rpcObj.getDate("LeaveHatcheryTime")));
                }else {
                    scanBean.setInfos_leavetime("");
                }
                if (rpcObj.getDate("ArriveBreedFactoryTime")!=null) {
                    scanBean.setInfos_daodashijian(DateTimeUtil.getYMD4(rpcObj.getDate("ArriveBreedFactoryTime")));
                }else {
                    scanBean.setInfos_daodashijian("");
                }

                if (rpcObj.getString("Employee_HandPhone")!=null) {
                    scanBean.setInfos_phone(rpcObj.getString("Employee_HandPhone"));
                }else {
                    scanBean.setInfos_phone("");
                }
                scanBeanList.add(scanBean);

                scanAdapter = new ScanAdapter(FumudaiCarsinfoActivity.this,scanBeanList);
                fumudai_lv_infos.setAdapter(scanAdapter);
            }

            @Override
            public Object call() throws Exception {
                JsonRpcResult result = RpcFacade.rpcCall(RpcUrl.ChickTransportLogRpc_Load,id);
                rpcObj = result.getRpcObject(RpcUrl.ChickTransportLogRpc_fanhui);
                return null;
            }
        };
        loadTask.execute();
    }
}
