package com.zj365.health.act

import android.text.TextUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.util.CommonToastUtils
import com.zj365.health.adapter.PictureAdapter
import com.zj365.health.databinding.ActCollectBloodBinding
import com.zj365.health.vm.PayCancerVm

/**
 */
@Route(path = ARouterUrl.COLLECT_BLOOD)
class CollectBloodAct : BaseVmAct<PayCancerVm>() {
    var signPath = ""
    val IMAGE_PICKER = 1001
    val mAdapter by lazy { PictureAdapter() }
    val binding by lazy { ActCollectBloodBinding.inflate(layoutInflater) }

    override fun setLayout() = binding.root
    var isList: Boolean = false
    override fun initData() {
        super.initData()
        isList = intent.getBooleanExtra("isList",false)
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = "预约采血"
        binding.title.mIvBack.setOnClickListener { finish() }
//        binding.ivUpload.setOnClickListener {
//            PictureUtils.openCamera(this, PictureMimeType.ofImage(),5)
//        }
        binding.mSubmit.setOnClickListener {
            val toString = binding.mName.text.toString()
            if (TextUtils.isEmpty(toString)) {
                CommonToastUtils.showToast("请输入姓名")
                return@setOnClickListener
            }

            val phone = binding.mPhone.text.toString()
            if (TextUtils.isEmpty(phone)) {
                CommonToastUtils.showToast("请输入手机号码")
                return@setOnClickListener
            }
            if (phone.length!=11) {
                CommonToastUtils.showToast("请输入正确手机号码")
                return@setOnClickListener
            }
            val sexValue = if (binding.checkSex.isChecked) 2 else 1
            mViewModel.saveInfo(toString, sexValue, phone)
        }

    }


    override fun liveObserver() {
        mViewModel.saveObservable.observe(this) {
            //采血列表
            if (isList){
                finish()
            } else {
                bundle.clear()
                RouteManager.goAct(ARouterUrl.COLLECT_BLOOD_list, bundle)
            }
        }
    }
}