package com.pan_american.android.ui.group_common.insurance_payment_insert

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.pan_american.android.OASystem
import com.pan_american.android.R
import com.pan_american.android.base.BaseActivity
import com.pan_american.android.base.BaseResponse
import com.pan_american.android.base.CardAdapter
import com.pan_american.android.base.ListAdapter
import com.pan_american.android.data.model.common.entity.Selector
import com.pan_american.android.data.model.common.network.GroupClientListRequest
import com.pan_american.android.data.model.common.network.GroupClientListResponse
import com.pan_american.android.data.model.group_common_modle.insurance_payment_insert.network.InsurancePaymentDetailRequest
import com.pan_american.android.data.model.group_common_modle.insurance_payment_insert.network.InsurancePaymentDetailResponse
import com.pan_american.android.data.model.group_common_modle.insurance_payment_insert.network.InsurancePaymentResourceRequest
import com.pan_american.android.data.model.group_common_modle.insurance_payment_insert.network.InsurancePaymentResourceResponse
import com.pan_american.android.data.model.group_common_modle.insurance_payment_insert.network.UpdateInsurancePaymentRequest
import com.pan_american.android.data.network.APIService
import com.pan_american.android.data.network.ServiceCreator
import com.pan_american.android.databinding.ActivityAddInsurancePaymentBinding
import com.pan_american.android.databinding.LayoutTitleBinding
import com.pan_american.android.util.MoneyInputFilter
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class AddInsurancePaymentActivity : BaseActivity<ActivityAddInsurancePaymentBinding>() {

    private lateinit var titleBinding: LayoutTitleBinding

    private var fromList = false

    private var groupId = 0

    private var paymentId = 0

    private val apiService = ServiceCreator.create<APIService>()

    private var insuranceType = ArrayList<Selector>()

    private var insuranceTypeId = 0

    private var customerList = ArrayList<Selector>()

    private var customerSelectList = ArrayList<Selector>()

    private var paymentWayList = ArrayList<Selector>()

    private var paymentWayId = 0

    private var paymentWaySelect = false

    private var currencyList = ArrayList<Selector>()

    private var currencyId = 0

    private var currencySelect = false

    private var cardList = ArrayList<Selector>()

    private var cardId = 0

    private var cardSelect = false

    private var bankNumber = ""

    private var paymentMarkId = 0

    private var paymentMarkSelect = false

    private var updateInsurancePaymentRequest = UpdateInsurancePaymentRequest()

    private var isAuditGM = -1

    override fun getViewBinding() = ActivityAddInsurancePaymentBinding.inflate(layoutInflater)

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

        intent.apply {
            fromList = getBooleanExtra("fromList", false)
            groupId = getIntExtra("groupId", 0)
            paymentId = getIntExtra("paymentId", 0)
            binding.groupName.text = getStringExtra("teamName")
            binding.groupNumber.text = getStringExtra("tourCode")
            binding.groupCustomer.text = getStringExtra("clientName")
            binding.visitCountry.text = getStringExtra("visitCountry")

            isAuditGM = if (fromList) {
                getIntExtra("isAuditGM", -1)
            } else {
                0
            }
        }

        initTitle()

        getSelectorResource()
    }

    override fun initTitle() {

        titleBinding = LayoutTitleBinding.bind(binding.root).apply {
            if (fromList) {
                titleText.text = resources.getString(R.string.insurance_payment_detail)
            } else {
                titleText.text = resources.getString(R.string.add_insurance_payment)
            }

            backButton.setOnClickListener {
                back()
            }
        }
    }

    override fun initViews() {

        binding.paymentSum.filters = arrayOf(MoneyInputFilter())

        if (fromList) {
            getInsurancePaymentDetail()

            binding.commit.setText(resources.getString(R.string.update))

            if (!canBeEdit()) {
                binding.apply {
                    addCustomer.visibility = View.GONE
                    insuranceNotes.isEnabled(false)
                    paymentWay.isEnabled = false
                    consumeWay.isEnabled = false
                    consumeDate.isEnabled = false
                    cardType.isEnabled = false
                    companyBankNo.isEnabled = false
                    transferOtherBankName.isEnabled = false
                    transferOtherSideName.isEnabled = false
                    transferOtherSideName.isEnabled = false
                    otherBankName.isEnabled = false
                    otherSideNo.isEnabled = false
                    otherSideName.isEnabled = false
                    payee.isEnabled = false
                    paymentMark.isEnabled = false

                    commit.setText(resources.getString(R.string.back))
                }
            }

        } else {
            binding.commit.setText(resources.getString(R.string.add))

            for (item in paymentWayList) {
                if (item.id == OASystem.PAYMENT_WAY_INSURANCE_ID) {
                    binding.paymentWay.text = item.name

                    paymentWayId = item.id
                }
            }

            for (item in insuranceType) {
                if (item.id == 2) {
                    binding.insuranceType.text = item.gName

                    insuranceTypeId = item.id
                }
            }
        }
    }

    override fun initEvents() {

        binding.insuranceType.setOnClickListener {
            showSelector {
                val adapter = ListAdapter.Builder<Selector>().apply {
                    setData(insuranceType)
                    setLayoutId(R.layout.item_selector)
                    addBindView { itemView, data ->
                        itemView.findViewById<TextView>(R.id.selector_item_name).text = data.gName
                    }
                }.create()

                selector.adapter = adapter

                adapter.onRecyclerViewItemClick =
                    object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                        override fun onItemClick(position: Int) {
                            insuranceType[position].apply {
                                insuranceTypeId = id
                                binding.insuranceType.text = gName
                            }

                            popupWindow.dismiss()
                        }
                    }
            }
        }

        binding.addCustomer.setOnClickListener {
            showSelector {
                val adapter = ListAdapter.Builder<Selector>().apply {
                    setData(customerList)
                    setLayoutId(R.layout.item_selector)
                    addBindView { itemView, data ->
                        itemView.findViewById<TextView>(R.id.selector_item_name).apply {
                            text = String.format(
                                resources.getString(R.string.currency_name_code_format),
                                String.format(
                                    resources.getString(R.string.with_space_format),
                                    data.lastName,
                                    data.firstName
                                ),
                                data.pinyin
                            )

                            for (item in customerSelectList) {
                                if (data.id == item.id) {
                                    setTextColor(
                                        ResourcesCompat.getColor(
                                            resources, R.color.title_background_color, null
                                        )
                                    )
                                }
                            }
                        }
                    }
                }.create()

                selector.adapter = adapter

                adapter.onRecyclerViewItemClick =
                    object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                        override fun onItemClick(position: Int) {

                            for (item in customerSelectList) {
                                if (customerList[position].id == item.id) {
                                    showMessage(resources.getString(R.string.customer_selected))
                                    popupWindow.dismiss()
                                    return
                                }
                            }

                            customerSelectList.add(customerList[position])
                            initCustomerList()

                            popupWindow.dismiss()
                        }
                    }
            }
        }

        binding.insurancePayment.filters = arrayOf(MoneyInputFilter())

        binding.insurancePayment.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

            }

            override fun afterTextChanged(p0: Editable?) {
                binding.paymentSum.text = p0
            }
        })

        binding.insuranceCurrency.setOnClickListener {
            showSelector {
                val adapter = ListAdapter.Builder<Selector>().apply {
                    setData(currencyList)
                    setLayoutId(R.layout.item_selector)
                    addBindView { itemView, data ->
                        itemView.findViewById<TextView>(R.id.selector_item_name).text =
                            String.format(
                                resources.getString(R.string.currency_name_code_format),
                                data.currencyName,
                                data.currencyCode
                            )
                    }
                }.create()

                selector.adapter = adapter

                adapter.onRecyclerViewItemClick =
                    object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                        override fun onItemClick(position: Int) {
                            binding.insuranceCurrency.text = currencyList[position].currencyCode
                            binding.sumUnit.text = currencyList[position].currencyCode

                            currencyId = currencyList[position].currencyId
                            currencySelect = true

                            popupWindow.dismiss()
                        }
                    }
            }
        }

        binding.paymentWay.setOnClickListener {
            showSelector {
                val adapter = ListAdapter.Builder<Selector>().apply {
                    setData(paymentWayList)
                    setLayoutId(R.layout.item_selector)
                    addBindView { itemView, data ->
                        itemView.findViewById<TextView>(R.id.selector_item_name).text = data.name
                    }
                }.create()

                selector.adapter = adapter

                adapter.onRecyclerViewItemClick =
                    object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                        override fun onItemClick(position: Int) {

                            paymentWayList[position].apply {
                                paymentWayId = id
                                binding.paymentWay.text = name
                                paymentWaySelect = true
                            }

                            when (paymentWayId) {
                                //刷卡
                                72 -> {
                                    binding.swipe.visibility = View.VISIBLE
                                    binding.transfer.visibility = View.GONE
                                    binding.remit.visibility = View.GONE

                                    binding.cardType.text = ""
                                    binding.bankCardNumber.text = ""

                                    cardId = 0
                                    cardSelect = false
                                }
                                //转账
                                73 -> {
                                    binding.swipe.visibility = View.GONE
                                    binding.transfer.visibility = View.VISIBLE
                                    binding.remit.visibility = View.GONE

                                    binding.sumUnit.hint =
                                        resources.getString(R.string.please_select)
                                }
                                //汇款
                                83 -> {
                                    binding.swipe.visibility = View.GONE
                                    binding.transfer.visibility = View.GONE
                                    binding.remit.visibility = View.VISIBLE

                                    binding.sumUnit.hint =
                                        resources.getString(R.string.please_select)
                                }
                                //其它
                                else -> {
                                    binding.swipe.visibility = View.GONE
                                    binding.transfer.visibility = View.GONE
                                    binding.remit.visibility = View.GONE

                                    binding.sumUnit.hint =
                                        resources.getString(R.string.please_select)
                                }
                            }

                            popupWindow.dismiss()
                        }
                    }
            }
        }

        binding.consumeDate.setOnClickListener {
            showDatePicker(
                resources.getString(R.string.consume_date_select_hint), binding.consumeDate
            ) {}
        }

        binding.cardType.setOnClickListener {
            showSelector {
                val adapter = ListAdapter.Builder<Selector>().apply {
                    setData(cardList)
                    setLayoutId(R.layout.item_selector)
                    addBindView { itemView, data ->
                        itemView.findViewById<TextView>(R.id.selector_item_name).text = data.name
                    }
                }.create()

                selector.adapter = adapter

                adapter.onRecyclerViewItemClick =
                    object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                        override fun onItemClick(position: Int) {
                            binding.cardType.text = cardList[position].name
                            binding.bankCardNumber.text = cardList[position].remark

                            cardId = cardList[position].id
                            bankNumber = cardList[position].remark
                            cardSelect = true

                            popupWindow.dismiss()
                        }
                    }
            }
        }

        binding.paymentMark.setOnClickListener {
            showSelector {
                val adapter = ListAdapter.Builder<Selector>().apply {
                    setData(OASystem.paymentMark)
                    setLayoutId(R.layout.item_selector)
                    addBindView { itemView, data ->
                        itemView.findViewById<TextView>(R.id.selector_item_name).text = data.name
                    }
                }.create()

                selector.adapter = adapter

                adapter.onRecyclerViewItemClick =
                    object : ListAdapter.OnRecyclerViewItemClick<Selector> {
                        override fun onItemClick(position: Int) {
                            paymentMarkId = OASystem.paymentMark[position].id
                            binding.paymentMark.text = OASystem.paymentMark[position].name
                            paymentMarkSelect = true

                            popupWindow.dismiss()
                        }
                    }
            }
        }

        binding.commit.setOnClickListener {

            if (!canBeEdit()) {
                back()
                return@setOnClickListener
            }

            updateInsurancePaymentRequest.id = paymentId
            updateInsurancePaymentRequest.diId = groupId

            if (customerSelectList.size == 0) {
                showMessage(resources.getString(R.string.customer_select_hint))
                return@setOnClickListener
            } else {
                var i = 0

                var customerId = ""

                while (i < customerSelectList.size) {

                    customerId += customerSelectList[i].id.toString()

                    i += 1

                    if (i < customerSelectList.size) {
                        customerId += ","
                    }
                }

                updateInsurancePaymentRequest.clientName = customerId
            }

            if (binding.insurancePayment.text.isNullOrBlank()) {
                showMessage(resources.getString(R.string.insurance_payment_input_hint))
                return@setOnClickListener
            } else {
                updateInsurancePaymentRequest.insuranceCosts =
                    binding.insurancePayment.text.toString().toDouble()
            }

            if (currencySelect) {
                updateInsurancePaymentRequest.currency = currencyId
            } else {
                showMessage(resources.getString(R.string.payment_currency_hint))
                return@setOnClickListener
            }

            binding.insuranceNotes.getText().apply {
                if (isNotBlank()) {
                    updateInsurancePaymentRequest.remark = this
                }
            }

            if (!paymentWaySelect) {
                showMessage(resources.getString(R.string.payment_way_hint))
                return@setOnClickListener
            } else {
                updateInsurancePaymentRequest.payDId = paymentWayId
            }

            if (binding.consumeWay.text.isBlank()) {
                showMessage(resources.getString(R.string.consume_way_hint))
                return@setOnClickListener
            } else {
                updateInsurancePaymentRequest.consumptionPatterns =
                    binding.consumeWay.text.toString()
            }

            if (binding.consumeDate.text.isNotBlank()) {
                updateInsurancePaymentRequest.consumptionDate = binding.consumeDate.text.toString()
            } else {
                showMessage(resources.getString(R.string.consume_date_select_hint))
                return@setOnClickListener
            }

            when (paymentWayId) {
                72 -> {
                    if (!cardSelect) {
                        showMessage(resources.getString(R.string.card_type_select_hint))
                        return@setOnClickListener
                    } else {
                        updateInsurancePaymentRequest.ctdId = cardId
                        updateInsurancePaymentRequest.bankNo = bankNumber
                        updateInsurancePaymentRequest.cardholderName =
                            binding.bankCardOwner.text.toString()
                    }
                }

                73 -> {
                    if (binding.companyBankNo.text.isBlank()) {
                        showMessage(resources.getString(R.string.company_blank_number_input_hint))
                        return@setOnClickListener
                    } else {
                        updateInsurancePaymentRequest.companyBankNo =
                            binding.companyBankNo.text.toString()
                    }

                    if (binding.transferOtherBankName.text.isBlank()) {
                        showMessage(resources.getString(R.string.other_blank_name_input_hint))
                        return@setOnClickListener
                    } else {
                        updateInsurancePaymentRequest.otherBankName =
                            binding.transferOtherBankName.text.toString()
                    }

                    if (binding.transferOtherSideNo.text.isBlank()) {
                        showMessage(resources.getString(R.string.other_side_no))
                        return@setOnClickListener
                    } else {
                        updateInsurancePaymentRequest.otherSideNo =
                            binding.transferOtherSideNo.text.toString()
                    }

                    if (binding.transferOtherSideName.text.isBlank()) {
                        showMessage(resources.getString(R.string.other_side_name))
                        return@setOnClickListener
                    } else {
                        updateInsurancePaymentRequest.otherSideName =
                            binding.transferOtherSideName.text.toString()
                    }

                }

                83 -> {
                    if (binding.otherBankName.text.isBlank()) {
                        showMessage(resources.getString(R.string.transfer_other_bank_name_input_hint))
                        return@setOnClickListener
                    } else {
                        updateInsurancePaymentRequest.otherBankName =
                            binding.otherBankName.text.toString()
                    }

                    if (binding.otherSideNo.text.isBlank()) {
                        showMessage(resources.getString(R.string.other_side_number_input_hint))
                        return@setOnClickListener
                    } else {
                        updateInsurancePaymentRequest.otherSideNo =
                            binding.otherSideNo.text.toString()
                    }

                    if (binding.otherSideName.text.isBlank()) {
                        showMessage(resources.getString(R.string.other_side_name_input_hint))
                        return@setOnClickListener
                    } else {
                        updateInsurancePaymentRequest.otherSideName =
                            binding.otherSideName.text.toString()
                    }
                }
            }

            updateInsurancePaymentRequest.payMoney = binding.paymentSum.text.toString().toDouble()

            updateInsurancePaymentRequest.paymentCurrency = currencyId

            if (binding.payee.text.isNotBlank()) {
                updateInsurancePaymentRequest.payee = binding.payee.text.trim().toString()
            }

            if (!paymentMarkSelect) {
                showMessage(resources.getString(R.string.payment_mark_hint))
                return@setOnClickListener
            } else {
                updateInsurancePaymentRequest.orbitalPrivateTransfer = paymentMarkId
            }

            if (binding.paymentApplyNotes.getText().trim().isNotBlank()) {
                updateInsurancePaymentRequest.cRemark = binding.paymentApplyNotes.getText()
            }

            if (fromList) {
                updateInsurancePaymentRequest.status = 2
                updateInsurancePayment()
            } else {
                updateInsurancePaymentRequest.status = 1
                updateInsurancePayment()
            }
        }
    }

    private fun getSelectorResource() {
        apiService.getInsurancePaymentResource(InsurancePaymentResourceRequest(groupId))
            .enqueue(object : Callback<InsurancePaymentResourceResponse> {
                override fun onResponse(
                    call: Call<InsurancePaymentResourceResponse>,
                    response: Response<InsurancePaymentResourceResponse>
                ) {
                    val resourceResponse = response.body()

                    if (resourceResponse != null) {
                        if (resourceResponse.code == 200) {

                            for (item in resourceResponse.data.payment) {
                                paymentWayList.add(item)
                            }

                            for (item in resourceResponse.data.bankCard) {
                                cardList.add(item)
                            }

                            for (item in resourceResponse.data.currencyList) {
                                currencyList.add(item)
                            }

                            for (item in resourceResponse.data.insuranceCost) {
                                insuranceType.add(item)
                            }

                            getCustomerList()

                        } else {
                            showMessage(resourceResponse.msg)
                        }
                    }
                }

                override fun onFailure(call: Call<InsurancePaymentResourceResponse>, t: Throwable) {
                    showErrorInfo(R.string.base_resource_data_get_failed)
                }
            })
    }

    private fun getCustomerList() {
        apiService.getClientListByDiId(GroupClientListRequest(groupId))
            .enqueue(object : Callback<GroupClientListResponse> {
                override fun onResponse(
                    call: Call<GroupClientListResponse>, response: Response<GroupClientListResponse>
                ) {

                    val customerListResponse = response.body()

                    if (customerListResponse != null) {
                        if (customerListResponse.code == 200) {

                            for (item in customerListResponse.data) {
                                customerList.add(item)
                            }

                            initViews()
                            initEvents()

                        } else {
                            showMessage(customerListResponse.msg)
                        }
                    }
                }

                override fun onFailure(call: Call<GroupClientListResponse>, t: Throwable) {
                    showErrorInfo(R.string.get_customer_list_failed)
                }
            })
    }

    private fun initCustomerList() {
        val layoutManager = LinearLayoutManager(OASystem.context)
        binding.customerList.layoutManager = layoutManager

        val adapter = CardAdapter.Builder<Selector>().apply {
            setData(customerSelectList)
            setLayoutId(R.layout.item_delete_button_selector)
            setCanDelete(canBeEdit())
            addBindView { itemView, data ->
                itemView.findViewById<TextView>(R.id.left_text).text = data.pinyin
                itemView.findViewById<TextView>(R.id.right_text).text = String.format(
                    resources.getString(R.string.with_space_format), data.lastName, data.firstName
                )
            }
        }.create()

        binding.customerList.adapter = adapter

        adapter.onRecyclerViewItemClick = object : CardAdapter.OnRecyclerViewItemClick<Selector> {
            override fun onItemClick(position: Int) {

            }

            override fun onItemDelete(position: Int) {
                customerSelectList.removeAt(position)
                binding.customerList.adapter!!.notifyItemRemoved(position)
                binding.customerList.adapter!!.notifyItemRangeChanged(
                    position, customerSelectList.size
                )
            }
        }
    }

    private fun updateInsurancePayment() {

        binding.commit.setButtonStatus(1)

        apiService.updateInsurancePayment(updateInsurancePaymentRequest)
            .enqueue(object : Callback<BaseResponse> {
                override fun onResponse(
                    call: Call<BaseResponse>, response: Response<BaseResponse>
                ) {

                    val baseResponse = response.body()

                    if (baseResponse != null) {
                        if (baseResponse.code == 200) {
                            if (fromList) {
                                showMessage(resources.getString(R.string.update_success))
                            } else {
                                showMessage(resources.getString(R.string.insert_success))
                            }

                            OASystem.needRefresh = true

                            back()

                        } else {

                            binding.commit.setButtonStatus(0)

                            showMessage(baseResponse.msg)
                        }
                    }
                }

                override fun onFailure(call: Call<BaseResponse>, t: Throwable) {

                    binding.commit.setButtonStatus(0)

                    showErrorInfo(R.string.update_error)
                }
            })
    }

    private fun getInsurancePaymentDetail() {
        apiService.getInsurancePaymentDetail(InsurancePaymentDetailRequest(paymentId))
            .enqueue(object : Callback<InsurancePaymentDetailResponse> {
                override fun onResponse(
                    call: Call<InsurancePaymentDetailResponse>,
                    response: Response<InsurancePaymentDetailResponse>
                ) {
                    val detailResponse = response.body()

                    if (detailResponse != null) {
                        if (detailResponse.code == 200) {

                            detailResponse.data.customers.apply {

                                run {
                                    for (item in insuranceType) {
                                        if (item.id == iid) {
                                            insuranceTypeId = iid

                                            binding.insuranceType.text = item.gName

                                            return@run
                                        }
                                    }
                                }

                                val clientId = clientName.split(",")

                                for (customer in customerList) {
                                    for (selectedCustomer in clientId) {
                                        if (selectedCustomer.matches(Regex("[0-9]*\$"))) {
                                            if (customer.id == selectedCustomer.toInt()) {
                                                customerSelectList.add(customer)
                                            }
                                        }
                                    }
                                }

                                initCustomerList()

                                binding.insurancePayment.setText(insuranceCosts.toString())

                                run {
                                    for (item in currencyList) {
                                        if (item.currencyId == this.currency) {

                                            currencyId = this.currency

                                            binding.insuranceCurrency.text = item.currencyCode

                                            currencySelect = true

                                            return@run
                                        }
                                    }
                                }

                                if (remark.isNotBlank()) {
                                    binding.insuranceNotes.setText(remark)
                                }

                            }

                            detailResponse.data.creditCard.apply {

                                for (item in paymentWayList) {
                                    if (item.id == payDId) {
                                        binding.paymentWay.text = item.name
                                        paymentWayId = payDId
                                        paymentWaySelect = true
                                    }
                                }

                                binding.consumeWay.setText(consumptionPatterns)

                                if (consumptionDate.isNotBlank()) {
                                    binding.consumeDate.text = consumptionDate
                                }

                                binding.paymentSum.text = payMoney.toString()

                                run {
                                    for (item in currencyList) {
                                        if (paymentCurrency == item.currencyId) {
                                            binding.sumUnit.text = item.currencyCode

                                            currencyId = item.currencyId
                                            currencySelect = true

                                            return@run
                                        }
                                    }
                                }

                                when (paymentWayId) {
                                    72 -> {
                                        binding.swipe.visibility = View.VISIBLE
                                        binding.transfer.visibility = View.GONE
                                        binding.remit.visibility = View.GONE

                                        for (item in cardList) {
                                            if (item.id == ctdId) {
                                                binding.cardType.text = item.name
                                                binding.bankCardNumber.text = item.remark
                                                cardId = ctdId
                                                bankNumber = bankNo
                                                cardSelect = true
                                            }
                                        }
                                    }

                                    //转账
                                    73 -> {
                                        binding.swipe.visibility = View.GONE
                                        binding.transfer.visibility = View.VISIBLE
                                        binding.remit.visibility = View.GONE

                                        binding.companyBankNo.setText(companyBankNo)

                                        binding.transferOtherBankName.setText(otherBankName)

                                        binding.transferOtherSideNo.setText(otherSideNo)

                                        binding.transferOtherSideName.setText(otherSideName)
                                    }

                                    //汇款
                                    83 -> {
                                        binding.swipe.visibility = View.GONE
                                        binding.transfer.visibility = View.GONE
                                        binding.remit.visibility = View.VISIBLE

                                        binding.otherBankName.setText(otherBankName)

                                        binding.otherSideNo.setText(otherSideNo)

                                        binding.otherSideName.setText(otherSideName)
                                    }

                                    else -> {
                                        binding.swipe.visibility = View.GONE
                                        binding.transfer.visibility = View.GONE
                                        binding.remit.visibility = View.GONE
                                    }
                                }

                                binding.payee.setText(payee)

                                binding.paymentMark.text =
                                    OASystem.paymentMark[orbitalPrivateTransfer].name
                                paymentMarkId = orbitalPrivateTransfer
                                paymentMarkSelect = true

                                if (remark.isNotBlank()) {
                                    binding.paymentApplyNotes.setText(remark)
                                }
                            }

                        } else {
                            showMessage(detailResponse.msg)
                        }
                    }
                }

                override fun onFailure(call: Call<InsurancePaymentDetailResponse>, t: Throwable) {
                    showErrorInfo(R.string.insurance_info_get_failed)
                }
            })
    }

    private fun canBeEdit(): Boolean {
        return OASystem.authorization(OASystem.INSURANCE_PAYMENT_INSERT, OASystem.EDIT) and (isAuditGM == 0)
    }
}