package com.android.chmo.ui.activity.order;

import android.widget.ImageView;
import android.widget.TextView;

import com.android.chmo.R;
import com.android.chmo.base.BaseActivity;
import com.android.chmo.http.HttpApi;
import com.android.chmo.http.RequestCallback;
import com.android.chmo.http.response.OrderRes;
import com.android.chmo.http.service.OrderService;
import com.android.chmo.model.OrderInfo;
import com.android.chmo.utils.XUtilsImage;
import com.google.gson.Gson;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/8/6.
 */

public class OrderDetailActivity extends BaseActivity {

    @BindView(R.id.state)
    TextView stateView;
    @BindView(R.id.workName)
    TextView workNameView;
    @BindView(R.id.workAddress)
    TextView addressView;
    @BindView(R.id.head)
    ImageView headView;
    @BindView(R.id.modelName)
    TextView nameView;
    @BindView(R.id.price)
    TextView priceView;
    @BindView(R.id.time)
    TextView timeView;
    @BindView(R.id.totalPrice)
    TextView totalPriceView;
    @BindView(R.id.orderNum)
    TextView orderNumView;
    @BindView(R.id.createTime)
    TextView createTimeView;

    private OrderInfo order;

    @Override
    protected int getContentResId() {
        return R.layout.activity_order_detail;
    }

    @Override
    public void initView() {
        String orderPk = getIntent().getStringExtra("orderPk");
        getOrderInfo(orderPk);
    }

    private void fillView() {
        XUtilsImage.display(headView, HttpApi.getImgUrl(order.hphoto),R.mipmap.def_head);
        workNameView.setText("活动名称：" + order.sname);
        addressView.setText("地址：" + order.addr);
        nameView.setText(order.name);
        priceView.setText(order.skillname + "  单价：￥" + order.sprice + "元/h");
        totalPriceView.setText("￥" + order.coin + "元");
        timeView.setText("时长：" + Math.round(Float.parseFloat(order.scount)) + "h");

        orderNumView.setText("订单号：" + order.ordernumber);
        createTimeView.setText("创建时间：" + order.odate);

        stateView.setText(getStateStr(order.orderstate));
    }

    private  String getStateStr(String state) {
        if (state.equals("0")) {
            return "待付款";
        }else if(state.equals("1")) {
            return "已付款";
        }else if(state.equals("2")) {
            return "取消订单";
        }else if(state.equals("3")) {
            return "已接单";
        }else if(state.equals("4")) {
            return "模特取消";
        }else if(state.equals("5")) {
            return "已完成";
        }else if(state.equals("6")) {
            return "订单超时";
        }
        return "";
    }

    public void getOrderInfo(String orkerPk) {
        showLoading();
        OrderService.getOrder(orkerPk, new RequestCallback() {
            @Override
            public void onSuccess(String result) {
                hideLoading();
                OrderRes res = new Gson().fromJson(result,OrderRes.class);
                if(res.data != null) {
                    order = res.data;
                    fillView();
                }else {
                    showToast("获取订单失败");
                }
            }

            @Override
            public void onFailure(String error) {
                hideLoading();
                showToast("获取订单失败");
            }
        });
    }
}
