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

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import cn.muchinfo.rma.R
import cn.muchinfo.rma.global.ViewEnumUtils
import cn.muchinfo.rma.global.data.BusinessData
import cn.muchinfo.rma.global.data.FinancialManageData
import cn.muchinfo.rma.view.autoWidget.*
import cn.muchinfo.rma.view.base.BaseActivity
import cn.muchinfo.rma.view.base.home.contract.emptyView
import org.jetbrains.anko.*

/**
 * 发票登记页面
 */
class InvoiceRegisterActivity : BaseActivity<FinancialViewModel>() {


    /** 输入的审核意见 **/
    lateinit var ramsk_edittext: EditText

    val data: FinancialManageData by lazy {
        intent.getParcelableExtra<FinancialManageData>("data") as FinancialManageData
    }


    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        verticalLayout {
            val margingPadding = autoSize(47)
            background = resources.getDrawable(R.color.segtabment_bg_color)
            topBar {
                commonLeftButton()
                commonTitle {
                    text = "发票登记"
                }
            }

            frameLayout {
                scrollView {
                    verticalLayout {
                        verticalLayout {
                            background = resources.getDrawable(R.color.white)
                            textView {
                                text = "合同基本信息"
                                textColorInt = R.color.rma_blue_color
                                textSizeAuto = 34
                            }.lparams(wrapContent, wrapContent) {
                                marginStart = margingPadding
                                topMargin = autoSize(25)
                            }

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                linearLayout {
                                    textView {
                                        text = "合同编号"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = ViewEnumUtils.getContractType(
                                                data?.contracttype ?: ""
                                            ) + "/"
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                        textView {
                                            text = data.contractno
                                            textSizeAuto = 17
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                    }.lparams(matchParent, wrapContent)

                                }.lparams(autoSize(450), wrapContent)
                                linearLayout {
                                    textView {
                                        text = if (data.contracttype == "1") {
                                            "销售方"
                                        } else {
                                            "采购方"
                                        }
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = if (data.contracttype == "1") {
                                                data.sellusername
                                            } else {
                                                data.buyusername
                                            }
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent) {
                                            marginEnd = margingPadding
                                        }
                                    }.lparams(matchParent, wrapContent)
                                }.lparams(autoSize(450), wrapContent)
                            }.lparams(matchParent, autoSize(60)) {
                                topMargin = autoSize(30)
                            }

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                linearLayout {
                                    textView {
                                        text = "定价类型"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = ViewEnumUtils.getPriceType(data.pricetype ?: "")
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)

                                    }.lparams(matchParent, wrapContent)

                                }.lparams(autoSize(450), wrapContent)
                                linearLayout {
                                    textView {
                                        text = "现货品种"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = data.goodsname
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent) {
                                            marginEnd = margingPadding
                                        }
                                    }.lparams(matchParent, wrapContent)
                                }.lparams(autoSize(450), wrapContent)
                            }.lparams(matchParent, autoSize(60))

                            view {
                                background = resources.getDrawable(R.color.rma_hint_line_color_eee)
                            }.lparams(matchParent, autoSize(1)) {
                                marginStart = autoSize(36)
                                marginEnd = autoSize(36)
                                topMargin = autoSize(30)
                            }

                            textView {
                                text = "待审核登记信息"
                                textColorInt = R.color.rma_blue_color
                                textSizeAuto = 34
                            }.lparams(wrapContent, wrapContent) {
                                marginStart = margingPadding
                                topMargin = autoSize(25)
                            }

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                linearLayout {
                                    textView {
                                        text = "类型"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            if (data.contracttype == "1") {
                                                text = "收票"
                                            } else if (data?.contracttype == "2") {
                                                text = "开票"
                                            }
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                    }.lparams(matchParent, wrapContent)

                                }.lparams(autoSize(450), wrapContent)
                                linearLayout {
                                    textView {
                                        text = "登记时间"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = data.applytime
                                            textSizeAuto = 24
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent){
                                            marginEnd = autoSize(47)
                                        }
                                        textView {
                                            visibility = View.GONE
                                            text = "00:00:00"
                                            textSizeAuto = 17
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                    }.lparams(matchParent, wrapContent)

                                }.lparams(autoSize(450), wrapContent)
                            }.lparams(matchParent, autoSize(60))

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                linearLayout {
                                    textView {
                                        text = "发票金额"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = data.invoiceAmount
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                        textView {
                                            text = "元"
                                            textSizeAuto = 17
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                    }.lparams(matchParent, wrapContent)

                                }.lparams(autoSize(450), wrapContent)
                                linearLayout {
                                    textView {
                                        text = "登记人"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = data.applyname
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent) {
                                            marginEnd = autoSize(47)
                                        }

                                    }.lparams(matchParent, wrapContent)

                                }.lparams(autoSize(450), wrapContent)
                            }.lparams(matchParent, autoSize(60))

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                linearLayout {
                                    textView {
                                        text = "其他费用"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = "123124"
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                        textView {
                                            text = "元"
                                            textSizeAuto = 17
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                    }.lparams(matchParent, wrapContent)

                                }.lparams(autoSize(450), wrapContent)
                                linearLayout {
                                    textView {
                                        text = "已开票额"
                                        textColorInt = R.color.p_normal_summary_txt_color
                                        textSizeAuto = 29
                                    }.lparams(wrapContent, wrapContent) {
                                        marginStart = margingPadding
                                    }

                                    linearLayout {
                                        emptyView()
                                        textView {
                                            text = "123124"
                                            textSizeAuto = 29
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent)
                                        textView {
                                            text = "元"
                                            textSizeAuto = 17
                                            textColorInt = R.color.rma_black_33
                                        }.lparams(wrapContent, wrapContent) {
                                            marginEnd = autoSize(47)
                                        }
                                    }.lparams(matchParent, wrapContent)

                                }.lparams(autoSize(450), wrapContent)
                            }.lparams(matchParent, autoSize(60)) {
                                bottomMargin = autoSize(50)
                            }
                        }
                        verticalLayout {
                            backgroundDrawable = createRoundRectDrawable("#ffffff", 14)

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView {
                                    text = "本次发票信息"
                                    textColorInt = R.color.rma_blue_color
                                    textSizeAuto = 34
                                }.lparams(wrapContent, wrapContent) {
                                    marginStart = autoSize(36)
                                }

                                imageView {
                                    imageResource = R.mipmap.rma_zhushi
                                }.lparams(autoSize(36), autoSize(36)) {
                                    marginStart = autoSize(29)
                                }
                            }.lparams(matchParent, autoSize(60)) {
                                topMargin = autoSize(36)
                            }

                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView {
                                    text = "开票金额"
                                    textSizeAuto = 31
                                    textColorInt = R.color.rma_black_33
                                }.lparams(wrapContent, wrapContent) {
                                    marginStart = autoSize(36)
                                }


                                linearLayout {
                                    background = resources.getDrawable(R.drawable.rma_item_click_bg)

                                    editText {
                                        setPadding(0, 10, 0, 0)
                                        setSingleLine(true)
                                        gravity = Gravity.CENTER
                                        hint = "0.00"
                                        background = null
                                        inputType = EditorInfo.TYPE_CLASS_TEXT
                                        hintColorStr = "#CCCCCC"
                                        textSizeAuto = 31
                                        textColorStr = "#333333"
                                    }.lparams(matchParent, matchParent) {

                                    }
                                }.lparams(autoSize(432), autoSize(72)) {
                                    marginStart = autoSize(80)
                                }

                                textView {
                                    text = "元"
                                    textSizeAuto = 29
                                    textColorInt = R.color.rma_black_33
                                }.lparams(wrapContent, wrapContent) {
                                    marginStart = autoSize(28)
                                }
                            }.lparams(matchParent, autoSize(80)) {
                                topMargin = autoSize(50)
                            }

                            linearLayout {
                                textView {
                                    text = "待开票金额："
                                    textColorInt = R.color.text_hit_color
                                    textSizeAuto = 29
                                }.lparams(wrapContent, wrapContent) {
                                    marginStart = autoSize(240)
                                }
                                textView {
                                    text = "12984091284元"
                                    textSizeAuto = 29
                                    textColorInt = R.color.rma_blue_color
                                }.lparams(wrapContent, wrapContent) {
                                    marginStart = autoSize(10)
                                }
                            }.lparams(matchParent, wrapContent) {
                                topMargin = autoSize(14)
                            }

                            textView {
                                text = "全部登记"
                                textSizeAuto = 29
                                textColorInt = R.color.rma_green_color
                            }.lparams(wrapContent, wrapContent) {
                                marginStart = autoSize(244)
                            }


                            linearLayout {
                                gravity = Gravity.CENTER_VERTICAL
                                textView {
                                    text = "开票金额"
                                    textSizeAuto = 31
                                    textColorInt = R.color.rma_black_33
                                }.lparams(wrapContent, wrapContent) {
                                    marginStart = autoSize(36)
                                }

                                textView {
                                    gravity = Gravity.CENTER
                                    backgroundDrawable = createRoundRectDrawable("#DAEDFF", 14)
                                    text = "上传附件"
                                    textColorInt = R.color.rma_blue_color
                                    textSizeAuto = 31
                                }.lparams(autoSize(180), autoSize(53))
                            }.lparams(matchParent, autoSize(60)) {
                                topMargin = autoSize(55)
                                marginStart = autoSize(80)
                                bottomMargin = autoSize(50)
                            }
                        }.lparams(matchParent, wrapContent) {
                            marginStart = autoSize(24)
                            marginEnd = autoSize(24)
                            topMargin = autoSize(24)
                            bottomMargin = autoSize(200)
                        }
                    }
                }

                linearLayout {
                    background = resources.getDrawable(R.color.white)
                    gravity = Gravity.CENTER_VERTICAL

                    textView {
                        gravity = Gravity.CENTER
                        backgroundResource = R.mipmap.rma_submit_bg
                        text = "发票登记"
                        textColorInt = R.color.white
                        textSizeAuto = 38
                    }.lparams(autoSize(780), autoSize(119)) {
                        marginStart = autoSize(59)
                    }

                }.lparams(matchParent, autoSize(144)) {
                    gravity = Gravity.BOTTOM
                }
            }.lparams(matchParent, matchParent)
        }
    }

}