package com.zswc.creativity.activity

import android.os.Bundle
import android.text.TextUtils
import com.qmuiteam.qmui.kotlin.onClick
import com.zswc.creativity.R
import com.zswc.creativity.base.MBActivity
import com.zswc.creativity.databinding.ActivityRegisterBinding
import com.zswc.creativity.inte.ChoiceData
import com.zswc.creativity.utils.PopuTipsUtils
import com.zswc.creativity.vmodel.RegisterVModel

class RegisterActivity : MBActivity<RegisterVModel, ActivityRegisterBinding>() {

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)


    }

    override fun listeners() {
        super.listeners()

        binding.imgSure.onClick {
            if (vm.isRead.value == 0) {//去勾选
                binding.imgSure.setImageResource(R.drawable.ct_select_on)
                vm.isRead.value = 1
            } else {
                binding.imgSure.setImageResource(R.drawable.ct_select_off)
                vm.isRead.value = 0

            }
        }
        binding.tvRegist.onClick {
            if (TextUtils.isEmpty(vm.phone)) {
                toast("请输入手机号")
               return@onClick
            }

            if (TextUtils.isEmpty(vm.code)) {
                toast("请输入验证码")
                return@onClick
            }
            if (TextUtils.isEmpty(vm.passWord)) {
                toast("请设置登录密码")
                return@onClick
            }

            if (TextUtils.isEmpty(vm.passWordTo)) {
                toast("请再次输入登录密码")
                return@onClick
            }

            if (!vm.passWord.equals(vm.passWordTo)) {
                toast("两次密码不一致")
                return@onClick
            }
            if (TextUtils.isEmpty(vm.passWordSeconnd)) {
                toast("请输入（支付/寄售）密码为6位纯数字")
                return@onClick
            }

            if (TextUtils.isEmpty(vm.passWordSeconndTo)) {
                toast("请再次输入上述密码")
                return@onClick
            }
            if (!vm.passWordSeconnd.equals(vm.passWordSeconndTo)) {
                toast("两次支付密码不一致")
                return@onClick
            }

            if(vm.isRead.value==0){
                toast(R.string.please_red_policy)
                return@onClick
            }
            PopuTipsUtils.showRegistOrder(context(),vm.phone!!, binding.tvRegist,vm.passWord!!,vm.passWordSeconnd!!, object : ChoiceData {
                override fun onRestuse(id: String?) {
                    vm.toSubmit()

                }

            })
        }
    }


    override fun title(): String? {
        return null
    }

    override fun binding(): ActivityRegisterBinding {
        return ActivityRegisterBinding.inflate(layoutInflater)
    }

    override fun vmClass(): Class<RegisterVModel> {
        return RegisterVModel::class.java
    }

    override val isRxbus: Boolean
        get() = true

}
