package com.zxhl.main.page.activity

import android.text.TextUtils
import android.view.View
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.Utils
import com.zxhl.cms.widget.LoadingDialog
import com.zxhl.main.R
import com.zxhl.main.page.contract.LogisticsContract
import com.zxhl.main.page.presenter.LogisticsPresenter
import kotlinx.android.synthetic.main.activity_layout_logistics.*

class LogisticsActivity : BaseActivity(), LogisticsContract.View {
    private var mPresenter: LogisticsPresenter? = null
    private var mLoading: LoadingDialog? = null
    override fun onClick(v: View?) {

    }

    override fun before() {
        super.before()
        setStatusBarBackground(AppContext.get().resources.getColor(R.color.transparent))
    }

    override fun layoutID(): Int {
        return R.layout.activity_layout_logistics
    }

    override fun init() {
        mPresenter = LogisticsPresenter(this)
        mLoading = LoadingDialog.getLoadingDialog(
            this,
            getString(com.zxhl.cms.R.string.wait_ing),
            false,
            false
        )
        id_img_back?.setOnClickListener {
            finish()
        }
        id_tv_tijiao?.setOnClickListener {
            if (TextUtils.isEmpty(id_tv_content?.text.toString())
            ) {
                Utils.showToast(this, "请输入遇到的问题")
                return@setOnClickListener
            }
            if (TextUtils.isEmpty(id_edit_mobile?.text.toString())) {
                Utils.showToast(this, "请输入手机号")
                return@setOnClickListener
            }
            if (id_edit_mobile?.text?.toString()?.length != 11) {
                Utils.showToast(this, "手机号格式不正确")
                return@setOnClickListener
            }
            mPresenter?.feedback(
                id_tv_content?.text.toString(),
                id_edit_mobile?.text.toString()
            )
            mLoading?.setLoading("请稍后")
            mLoading?.show()

        }
    }

    override fun postSuc(msg: String) {
        if (mLoading != null) {
            mLoading?.dismiss()
        }

        JumpUtils.SubmitJump()
        finish()
    }

    override fun PostFail() {
        if (mLoading != null) {
            mLoading?.dismiss()
        }
        Utils.showToast(this, "提交失败,请稍候再试")
    }
}