package cn.muchinfo.rma.view.base.home.reportquery

import android.view.Gravity
import androidx.appcompat.app.AppCompatActivity
import cn.muchinfo.rma.R
import cn.muchinfo.rma.global.data.FinancialReportData
import cn.muchinfo.rma.lifecycle.bindOptional
import cn.muchinfo.rma.view.autoWidget.autoSize
import cn.muchinfo.rma.view.autoWidget.textColorInt
import cn.muchinfo.rma.view.autoWidget.textSizeAuto
import mtp.polymer.com.autowidget.adapter.BaseViewHolder
import org.jetbrains.anko.*

/**
 * 财务报表的日报表-viewholder
 * @property activity AppCompatActivity
 * @property viewModel ReportQueryViewModel
 * @property itemSize IntArray
 * type 1 款项 2 发票
 * @constructor
 */
class FinancialDayViewHolder(private val activity: AppCompatActivity,private val viewModel: ReportQueryViewModel,private val type : String) : BaseViewHolder<FinancialReportData>(activity){
    override val itemSize: IntArray = intArrayOf(matchParent, wrapContent)

    override fun _FrameLayout.createContentView() {
        linearLayout {
            verticalLayout {
                gravity = Gravity.START
                textView {
                    data.bindOptional(context){
                        text = it?.logdatetime
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginStart = autoSize(36)
                }
            }.lparams(autoSize(225), autoSize(97))

            verticalLayout {
                gravity = Gravity.CENTER_HORIZONTAL
                textView {
                    data.bindOptional(context){
                        text = it?.logtypename
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
                textView {
                    data.bindOptional(context){
                        text = it?.relatedno
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(97))

            verticalLayout {
                gravity = Gravity.CENTER_HORIZONTAL
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = if (it?.contracttype == "1"){ "收款" }else{ "退款" }
                        }else{
                            text = if (it?.contracttype == "1"){ "收票" }else{ "开票" }
                        }
                        text = it?.relatedno
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
                textView {
                    data.bindOptional(context){
                        text = it?.logvalue
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(97))

            verticalLayout {
                gravity = Gravity.END
                textView {
                    data.bindOptional(context){
                        text = it?.applyname
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginStart = autoSize(36)
                }
            }.lparams(autoSize(225), autoSize(97))
        }.lparams(matchParent, autoSize(100))
    }

}