package com.rehome.bhdxj.activity

import android.os.Bundle
import android.text.TextUtils
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.rehome.bhdxj.R
import com.rehome.bhdxj.base.BaseActivityOaToolbarViewBinding
import com.rehome.bhdxj.contans.Contans
import com.rehome.bhdxj.databinding.ActivityQxgdNewBinding
import com.rehome.bhdxj.utils.GsonUtils
import com.rehome.bhdxj.utils.OAToolbar
import com.rehome.bhdxj.utils.RSAUtils
import com.rehome.bhdxj.utils.SPUtils
import com.yolanda.nohttp.NoHttp
import com.yolanda.nohttp.RequestMethod
import com.yolanda.nohttp.rest.OnResponseListener
import com.yolanda.nohttp.rest.RequestQueue
import com.yolanda.nohttp.rest.Response
import org.litepal.crud.DataSupport

class QxgdNewActivity : BaseActivityOaToolbarViewBinding<ActivityQxgdNewBinding>() {

    private lateinit var queueNoHttp: RequestQueue
    private lateinit var username: String
    private lateinit var usernames: String

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

    override fun getToolbar()= binding.toolbarView.toolbar

    override fun initView() {
        initToolbar("缺陷工单提交", "提交") {

        }

        queueNoHttp = NoHttp.newRequestQueue(1)
        val userIdTemp = SPUtils.get(this, Contans.USERID, "") as String
        if (!TextUtils.isEmpty(userIdTemp)) {
            username = RSAUtils.decryptBASE64StrLocal(userIdTemp);
        }else{
            username = ""
        }
        usernames = SPUtils.get(this, Contans.USERNAME, "") as String


    }

    override fun initData() {
        //缺陷工单下拉数据
        getZyDropDown();

    }

    private fun getZyDropDown() {
        var param = HashMap<String,String>()
        param["action"] = "QXGD_ZY_GET";
        val json = GsonUtils.GsonString(param)


        val url = Contans.MAXIMOIP + Contans.QX_GET_ZY_DROP
        showLog(url)
        val request = NoHttp.createStringRequest(url, RequestMethod.POST)
        request.setDefineRequestBodyForJson(json)

        queueNoHttp.add(12, request, object : OnResponseListener<String> {
            override fun onStart(what: Int) {

            }

            override fun onSucceed(what: Int, response: Response<String>?) {
                val result = response?.get()
                showLog(result)
                /**
                 * {"state": 1,"msg":"查询成功","data":[
                 * {"description":"保卫","value":"保卫"},
                 * {"description":"电气","value":"电气"},
                 * {"description":"辅助","value":"辅助"},
                 * {"description":"辅助维护","value":"辅助维护"},
                 * {"description":"锅炉","value":"锅炉"},
                 * {"description":"化验","value":"化验"},
                 * {"description":"环化","value":"环化"},
                 * {"description":"机组启停","value":"机组启停"},
                 * {"description":"金属","value":"金属"},
                 * {"description":"其他","value":"其他"},
                 * {"description":"汽机","value":"汽机"},
                 * {"description":"燃料","value":"燃料"},
                 * {"description":"燃料电仪","value":"燃料电仪"},
                 * {"description":"燃料机械","value":"燃料机械"},
                 * {"description":"热控","value":"热控"},
                 * {"description":"生产公用","value":"生产公用"},
                 * {"description":"生技","value":"生技"},
                 * {"description":"土建","value":"土建"},
                 * {"description":"消防","value":"消防"},
                 * {"description":"信息","value":"信息"},
                 * {"description":"运行","value":"运行"},
                 * {"description":"运行A值","value":"运行A值"},
                 * {"description":"运行B值","value":"运行B值"},
                 * {"description":"运行C值","value":"运行C值"},
                 * {"description":"运行D值","value":"运行D值"},
                 * {"description":"运行E值","value":"运行E值"},
                 * {"description":"综合服务","value":"综合服务"}]}
                 */

                //专业
//                if(type=="zy"){
//                    val zyQxData = GsonUtils.GsonToBean(result, ZyQxData::class.java)
//                    if (zyQxData != null&&zyQxData.state == 1) {
//                        if (zyQxData.data != null&&zyQxData.data.size > 0) {
//                            showLog(zyQxData.data.size.toString())
//                            val zyList = DataSupport.findAll(Zy::class.java)
//                            if(zyList!=null&&zyList.size>0){
//                                showLog("zyList size > 0")
//                                showLog(GsonUtils.GsonString(zyList))
//                                showLog(zyList.size.toString())
//                                DataSupport.deleteAll(Zy::class.java)
//                                DataSupport.saveAll(zyQxData.data)
//                            }else{
//                                showLog("zyList size == 0")
//                                DataSupport.saveAll(zyQxData.data)
//                            }
//                        }
//                    }
//                }
            }

            override fun onFailed(what: Int, response: Response<String>?) {

            }

            override fun onFinish(what: Int) {

            }
        })

    }
}