package com.wd.workoffice.ui.fg;

import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkBaseFg;
import com.wd.workoffice.bean.workEnum.PagePermissionType;
import com.wd.workoffice.ui.activity.user.UserInfoActivity;
import com.wd.workoffice.ui.activity.user.UserMoneyActivity;
import com.wd.workoffice.ui.activity.user.UserPermissionActivity;
import com.wd.workoffice.ui.activity.user.UserSettingActivity;
import com.wd.workoffice.util.UserKeeper;
import com.wd.workoffice.util.WorkUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class MyFragment extends WorkBaseFg {

    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_no)
    TextView tvNo;
    @BindView(R.id.ll_role)
    LinearLayout llRole;
    @BindView(R.id.ll_info)
    LinearLayout llInfo;
    @BindView(R.id.ll_setting)
    LinearLayout llSetting;
    @BindView(R.id.tv_dep)
    TextView tvDep;
    @BindView(R.id.ll_money)
    LinearLayout llMoney;
    @BindView(R.id.ll_mes_setting)
    LinearLayout llMesSetting;

    @Override
    protected void initView() {
        ButterKnife.bind(this, getContentView());
        if (!TextUtils.isEmpty(UserKeeper.getInstance().getLoginInfo())) {
            tvNo.setText("员工编号:" + UserKeeper.getInstance().getUserErpId());
            tvName.setText(UserKeeper.getInstance().getUserNickName());
            tvDep.setText(UserKeeper.getInstance().getUserDepName());
            if (!UserKeeper.getInstance().getMesLogin()) {
                llMesSetting.setVisibility(View.GONE);
            }
        } else {
            tvNo.setText("员工编号:" + UserKeeper.getInstance().getMesUserCode());
            tvName.setText(UserKeeper.getInstance().getMesNickName());
            tvDep.setText(UserKeeper.getInstance().getMesDep());
            llSetting.setVisibility(View.GONE);
            llRole.setVisibility(View.GONE);
            llMoney.setVisibility(View.GONE);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!WorkUtils.hasPermission(PagePermissionType.DEPT_ACCOUNT_BALANCE_TAX.getPermission()) &&
                !WorkUtils.hasPermission(PagePermissionType.DEPT_ACCOUNT_BALANCE_EXCHANGE.getPermission()) &&
                !WorkUtils.hasPermission(PagePermissionType.DEPT_ACCOUNT_BALANCE_CO.getPermission()) &&
                !TextUtils.equals(UserKeeper.getInstance().getUserDepRuler(), "1")) {
            llMoney.setVisibility(View.GONE);
        }
    }

    @Override
    protected void initData() {
    }


    @Override
    protected void initEvent() {
    }

    @Override
    protected int layoutId() {
        return R.layout.fg_my;
    }


    @OnClick({R.id.ll_mes_setting, R.id.ll_role, R.id.ll_money, R.id.ll_info, R.id.ll_setting})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_role:
                startActivity(UserPermissionActivity.class);
                break;
            case R.id.ll_info:
                startActivity(UserInfoActivity.class);
                break;
            case R.id.ll_setting:
                startActivity(UserSettingActivity.class);
                break;
            case R.id.ll_mes_setting:
                startActivity(UserSettingActivity.class);
                break;
            case R.id.ll_money:
                startActivity(UserMoneyActivity.class);
                break;
        }
    }

}
