package com.lukouguoji.mit.activity

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SimpleItemAnimator
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.fastjson.JSONObject
import com.luck.picture.lib.basic.IBridgeViewLifecycle
import com.luck.picture.lib.basic.PictureSelector
//import com.luck.picture.lib.config.PictureSelectionConfig.selectorStyle
import com.luck.picture.lib.config.SelectMimeType.ofImage
import com.luck.picture.lib.decoration.GridSpacingItemDecoration
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.interfaces.OnResultCallbackListener
import com.luck.picture.lib.style.PictureSelectorStyle
import com.luck.picture.lib.utils.DensityUtil
import com.lukouguoji.gnj.common.MitCommon
import com.lukouguoji.mit.R
import com.lukouguoji.mit.adapt.AccidentVisaInfoAdapter
import com.lukouguoji.mit.adapt.PictureAdapter
import com.lukouguoji.mit.model.AccidentVisaInfoItemModel
import com.lukouguoji.mit.uitl.FullyGridLayoutManager
import com.lukouguoji.mit.uitl.GlideEngine
import com.lukouguoji.mit.viewModel.AccidentVisaInfoViewModel
import com.lukouguoji.module_base.ActivityCollector
import com.lukouguoji.module_base.BaseActivity
import com.lukouguoji.module_base.MyApplication
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.String.emptyToNull
import com.lukouguoji.module_base.ktx.getActivity
import com.lukouguoji.module_base.router.ARouterConstants
import com.lukouguoji.module_base.util.Common
import kotlinx.coroutines.launch
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File


@Route(path = ARouterConstants.ACTIVITY_URL_MONITOR_ACCIDENT_VISA_INFO)
class AccidentVisaInfoActivity : BaseActivity(), View.OnClickListener {
    private lateinit var viewModel: AccidentVisaInfoViewModel
    private lateinit var adapter: AccidentVisaInfoAdapter

    private val collectList = ArrayList<AccidentVisaInfoItemModel>()

    private lateinit var pictureAdapter: PictureAdapter
    private lateinit var mRecyclerView: RecyclerView
    private val mData = ArrayList<LocalMedia>()

    //    private lateinit var uploadImg: ImageView
    private lateinit var cancel: TextView
    private lateinit var submit: TextView


    @JvmField
    @Autowired
    var id: Int = -9999

    private fun initView() {
        viewModel = ViewModelProvider(this).get(AccidentVisaInfoViewModel::class.java)

        val layoutManager = GridLayoutManager(this, 2)
        adapter = AccidentVisaInfoAdapter(this, viewModel, collectList)
        var recyclerView: RecyclerView = findViewById(R.id.collectList)
        recyclerView.layoutManager = layoutManager
        recyclerView.adapter = adapter

        //初始化 加载的资源
        /*val list = ArrayList<LocalMedia>()
        list.add(LocalMedia.generateHttpAsLocalMedia("https://fdfs.test-kepu.weiyilewen.com/group1/M00/00/01/wKhkY2Iv936EMKWzAAAAAHuLNY8762.mp4"));
        list.add(LocalMedia.generateHttpAsLocalMedia("https://wx1.sinaimg.cn/mw2000/0073ozWdly1h0afogn4vij30u05keb29.jpg"));
        list.add(LocalMedia.generateHttpAsLocalMedia("https://wx3.sinaimg.cn/mw2000/0073ozWdly1h0afohdkygj30u05791kx.jpg"));
        list.add(LocalMedia.generateHttpAsLocalMedia("https://wx2.sinaimg.cn/mw2000/0073ozWdly1h0afoi70m2j30u05fq1kx.jpg"));
        list.add(LocalMedia.generateHttpAsLocalMedia("https://wx2.sinaimg.cn/mw2000/0073ozWdly1h0afoipj8xj30kw3kmwru.jpg"));
        list.add(LocalMedia.generateHttpAsLocalMedia("https://wx4.sinaimg.cn/mw2000/0073ozWdly1h0afoj5q8ij30u04gqkb1.jpg"));
        list.add(LocalMedia.generateHttpAsLocalMedia("https://ww1.sinaimg.cn/bmiddle/bcd10523ly1g96mg4sfhag20c806wu0x.gif"));
        mData.addAll(list);*/
        mRecyclerView = findViewById(R.id.recycler)
        val manager = FullyGridLayoutManager(
            this,
            6, GridLayoutManager.VERTICAL, false
        )
        mRecyclerView.layoutManager = manager
        val itemAnimator: RecyclerView.ItemAnimator? = mRecyclerView.itemAnimator
        if (itemAnimator != null) {
            (itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
        }
        mRecyclerView.addItemDecoration(
            GridSpacingItemDecoration(
                6,
                DensityUtil.dip2px(this, 4f), false
            )
        )
        pictureAdapter = PictureAdapter(this, viewModel, mData)
        pictureAdapter.setSelectMax(9)
        mRecyclerView.adapter = pictureAdapter


//        uploadImg = findViewById(R.id.uploadImg)
        cancel = findViewById(R.id.cancel)
        submit = findViewById(R.id.submit)

//        uploadImg.setOnClickListener(this)
        cancel.setOnClickListener(this)
        submit.setOnClickListener(this)

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_accident_visa_info)
        initView()

        /**
         * 上传图片返回结果
         */
        /*viewModel.uploadImgObserver.observe(this) {
            loadingCancel()
            val status = it.getString("status")
            val msg = it.getString("msg")
            if (Constant.Result.succ == status) {
                val data = it.getJSONObject("data")
                var oldName = data.getString("oldName")
                var newName = data.getString("newName")

                viewModel.imageKeyValue[oldName] = newName

            } else {
                Common.showToast(this, "上传失败！")
            }
        }*/

        viewModel.viewModelScope.launch {
            viewModel.uploadImgObserver.collect {
                loadingCancel()
                val status = it.getString("status")
                val msg = it.getString("msg")
                if (Constant.Result.succ == status) {
                    val data = it.getJSONObject("data")
                    var oldName = data.getString("oldName")
                    var newName = data.getString("newName")

                    viewModel.imageKeyValue[oldName] = newName

                } else {
                    Common.showToast(MyApplication.context, "上传失败！")
                }

            }

        }

        //航班返回结果
        viewModel.queryFlightObserver.observe(this) {
            loadingCancel()
            val status = it.getString("status")
            if (Constant.Result.succ == status) {
                var jsonObject = it.getJSONObject("data")
                val countryName = jsonObject.getString("countryName")
                val countryType = jsonObject.getString("countryType")
                val dep = jsonObject.getString("fdep")
                val dest = jsonObject.getString("fdest")

                viewModel.waybillFormNetWork["countryName"] = countryName
                viewModel.waybillFormNetWork["areaFlag"] = countryName
                viewModel.waybillFormNetWork["countryType"] = countryType
                viewModel.waybillFormNetWork["dep"] = dep
                viewModel.waybillFormNetWork["dest"] = dest

                //运单号
                collectList.forEach { c ->
                    when (c.titleCode) {
                        "areaFlag" -> {
                            c.inputContent = countryName
                        }
                        "dep" -> {
                            c.inputContent = dep
                        }
                        "dest" -> {
                            c.inputContent = dest
                        }
                    }
                }
                adapter.notifyDataSetChanged()

            } else {
                val countryName = ""
                val countryType = ""
                val dep = ""
                val dest = ""

                viewModel.waybillFormNetWork["areaFlag"] = countryName
                viewModel.waybillFormNetWork["countryName"] = countryName
                viewModel.waybillFormNetWork["countryType"] = countryType
                viewModel.waybillFormNetWork["dep"] = dep
                viewModel.waybillFormNetWork["dest"] = dest

                //运单号
                collectList.forEach { c ->
                    when (c.titleCode) {
                        "areaFlag" -> {
                            c.inputContent = countryName
                        }
                        "dep" -> {
                            c.inputContent = dep
                        }
                        "dest" -> {
                            c.inputContent = dest
                        }
                    }
                }
                adapter.notifyDataSetChanged()
            }
        }


        /**
         * 删除图片返回结果
         */
        viewModel.deleteImgObserver.observe(this) {
            loadingCancel()
            val status = it.getString("status")
            val msg = it.getString("msg")
        }
        //监听照片事件
        pictureAdapter.setOnItemClickListener(object : PictureAdapter.OnItemClickListener {
            override fun onItemClick(v: View?, position: Int) {
                // 预览图片、视频、音频
                PictureSelector.create(ActivityCollector.getLastActivity())
                    .openPreview()
                    .setImageEngine(GlideEngine.createGlideEngine())
                    .setAttachViewLifecycle(object : IBridgeViewLifecycle {
                        override fun onViewCreated(fragment: Fragment, view: View, savedInstanceState: Bundle?) {

                        }

                        override fun onDestroy(fragment: Fragment) {
                        }
                    })
                    .startActivityPreview(position, false, pictureAdapter.getData())
            }

            override fun openPicture() {
                // 进入相册
                PictureSelector.create(ActivityCollector.getLastActivity())
                    .openGallery(ofImage())
                    .setImageEngine(GlideEngine.createGlideEngine())
                    .isPageSyncAlbumCount(true)
                    .forResult(object : OnResultCallbackListener<LocalMedia?> {
                        override fun onCancel() {
                            // 取消
                        }

                        override fun onResult(result: java.util.ArrayList<LocalMedia?>?) {
                            if (result != null) {
                                val resultList = arrayListOf<LocalMedia>()
                                result.forEach {
                                    //上传图片至服务器
                                    val filePath = File(it!!.realPath)
                                    var fileName = it.fileName
                                    val imgBody = RequestBody.create("multipart/form-data".toMediaTypeOrNull(), filePath)
                                    val filePart = MultipartBody.Part.createFormData("file", filePath.name, imgBody)
                                    viewModel.imageKeyValue[fileName] = ""
                                    loading()
                                    viewModel.uploadImg(filePart)

                                    resultList.add(it)
                                }
                                mData.addAll(resultList)
                                pictureAdapter.notifyDataSetChanged()

                            }

                        }
                    })
            }
        })


        //1.新增
        if (id == -9999) {
//        if (true) {
            setBackArrow("新增事故签证")

            selObserve()
            initData(MitCommon.AccidentVisa.Info.add)

            viewModel.saveFestGnjCangDanObserver.observe(this) {
                loadingCancel()
                val status = it.getString("status")
                val msg = it.getString("msg")
                if (Constant.Result.succ == status) {
                    val dataStatus = it.getString("data")
                    if (Constant.Result.succ == dataStatus) {
                        Common.showToast(this, "新增成功！")
                        reset()
                    } else if (Constant.Result.code2 == dataStatus) {
                        Common.showToast(this, "没有选择航班，请选择航班！")
                    } else {
                        Common.showToast(this, "新增失败！")
                    }
                } else {
                    Common.showToast(this, "新增失败！")
                }
            }
            return
        }
        //2.编辑
        if (id != -9999) {
            setBackArrow("事故签证详情")

            initNetWork(id, null, MitCommon.AccidentVisa.Info.update)

            viewModel.updateFestGnjCangDanObserver.observe(this) {
                loadingCancel()
                val status = it.getString("status")
                val msg = it.getString("msg")
                if (Constant.Result.succ == status) {
                    var dataStatus = it.getString("data")
                    if (Constant.Result.succ == dataStatus) {
                        Common.showToast(this, "修改成功！")
                    } else if (Constant.Result.code2 == dataStatus) {
                        Common.showToast(this, "没有选择航班，请选择航班！")
                    } else {
                        Common.showToast(this, "修改失败！")
                    }
                } else {
                    Common.showToast(this, "修改失败！")
                }
            }
            return
        }
    }

    override fun onClick(v: View?) {
        v?.let {
            when (it.id) {
                /*R.id.uploadImg -> {

                    PictureSelector.create(this)
                        .openGallery(ofImage())
                        .setImageEngine(GlideEngine.createGlideEngine()) // 请参考Demo GlideEngine.java
                        .forResult(object : OnResultCallbackListener<LocalMedia?> {
                            override fun onCancel() {
                                // 取消
                            }

                            override fun onResult(result: java.util.ArrayList<LocalMedia?>?) {
                                if(result != null){
                                    val files = arrayListOf<MultipartBody.Part>()
                                    result.forEach {
                                        var file = File(it?.realPath)
                                        var imgBody = RequestBody.create(MediaType.parse("multipart/form-data"), file)
                                        var filePart = MultipartBody.Part.createFormData("file", file.name, imgBody)

//                                        viewModel.uploadImg(filePart)

                                        files.add(filePart)

                                    }

//                                    viewModel.uploadImgList(files)
                                }

                            }
                        })
                }*/
                R.id.cancel -> {
                    finish()
                }
                R.id.submit -> {
                    submit()
                }
                else -> {
                    Toast.makeText(this, "未找到对应操作", Toast.LENGTH_SHORT).show()
                }
            }
        }
    }

    /**
     * 扫码返回的结果
     */
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        // 扫描二维码/条码回传
        if (resultCode == RESULT_OK && data != null) {
            val content = data.getStringExtra(com.yzq.zxinglibrary.common.Constant.CODED_CONTENT)
            if (content == null) {
                Common.showToast(this, "条码错误！")
                return
            }
            when (requestCode) {
                Constant.RequestCode.accident_visa_info_wbno_scan -> {
                    //运单号
                    viewModel.waybillFormNetWork["wbNo"] = content
                    collectList.forEach { c ->
                        if (c.titleCode == "wbNo") {
                            c.inputContent = content
                        }
                    }
                    adapter.notifyDataSetChanged()
                }
            }
        }
    }

    /**
     * 监听运单详情返回数据
     *
     * write = false 只读 true 可写
     */
    private fun waybillObserve(status: String) {
        viewModel.waybillLiveData.observe(this) {
            val resStatus = it.getString("status")
            if (Constant.Result.succ == resStatus) {
                viewModel.waybillFormNetWork = it.getJSONObject("data")

                initData(status)

            } else {
                //无数据
            }
        }
    }

    /**
     * 下拉框赋值
     */
    private fun selObserve() {
        ///////////////    下拉框   start
        viewModel.outerPackageType(System.currentTimeMillis().toString())
        viewModel.outerPackageTypeObserver.observe(this) { vd ->
            val noneObj = JSONObject()
            noneObj["name"] = "请选择外包装"
            noneObj["code"] = ""
            viewModel.outerPackageTypeList.add(noneObj)
            viewModel.outerPackageTypeList.addAll(vd.getJSONArray("data"))

            totalRequestNotifyAdapter()
        }

        viewModel.damageType(Constant.businessType.CO)
        viewModel.damageTypeObserver.observe(this) { vd ->
            val noneObj = JSONObject()
            noneObj["name"] = "请选择包装破损情况"
            noneObj["code"] = ""
            viewModel.damageTypeList.add(noneObj)
            viewModel.damageTypeList.addAll(vd.getJSONArray("data"))

            totalRequestNotifyAdapter()
        }

        viewModel.contentType(System.currentTimeMillis().toString())
        viewModel.contentTypeObserver.observe(this) { vd ->
            val noneObj = JSONObject()
            noneObj["name"] = "请选择内容物情况"
            noneObj["code"] = ""
            viewModel.contentTypeList.add(noneObj)
            viewModel.contentTypeList.addAll(vd.getJSONArray("data"))

            totalRequestNotifyAdapter()
        }

        viewModel.unusualType(System.currentTimeMillis().toString())
        viewModel.unusualTypeObserver.observe(this) { vd ->
            val noneObj = JSONObject()
            noneObj["name"] = "请选择不正常类型"
            noneObj["code"] = ""
            viewModel.unusualTypeList.add(noneObj)
            viewModel.unusualTypeList.addAll(vd.getJSONArray("data"))

            totalRequestNotifyAdapter()
        }

        viewModel.searchDateType(System.currentTimeMillis().toString())
        viewModel.searchDateTypeObserver.observe(this) { vd ->
            val noneObj = JSONObject()
            noneObj["name"] = "请选择发现时间类型"
            noneObj["code"] = ""
            viewModel.searchDateTypeList.add(noneObj)
            viewModel.searchDateTypeList.addAll(vd.getJSONArray("data"))

            totalRequestNotifyAdapter()
        }

        ///////////////    下拉框   end
    }

    /**
     * 所有请求结束，更细adpter 只适用于刚开始加载
     */
    private fun totalRequestNotifyAdapter() {
        adapter.notifyDataSetChanged()
    }

    /**
     * 初始化网络请求
     */
    private fun initNetWork(id: Int, wbNo: String?, status: String) {
        selObserve()
        viewModel.queryWaybillById(id, wbNo)
        waybillObserve(status)
    }

    /**
     * 提交
     */
    private fun submit() {
        for ((index, c) in collectList.withIndex()) {
            val titleName = c.titleName//标题
            val inputContent = c.inputContent//输入内容
            val selContentCode = c.selContentCode//选择内容
            val must = c.isMust//是否必填
            val sel = c.isSel//是否下拉框
            val titleCodePre = c.titleCodePre//前缀
            val inputContentPre = c.inputContentPre//前缀
            //下拉框
            if (sel) {
                if (must && selContentCode == "") {
                    Common.showToast(this, "请选择$titleName")
                    return
                }
                viewModel.waybillFormNetWork[c.titleCode] = selContentCode.emptyToNull()
            }
            //输入框
            else {
                if (must && inputContent == "") {
                    Common.showToast(this, "请输入$titleName")
                    return
                }
                viewModel.waybillFormNetWork[c.titleCode] = inputContent.emptyToNull()
                //前缀不为空时，赋值
                if (titleCodePre != null && titleCodePre != "" && inputContentPre != null && inputContentPre != "") {
                    viewModel.waybillFormNetWork[titleCodePre] = inputContentPre.emptyToNull()
                }
            }
        }

        //图片循环获取名称。映射表里存在，说明是新上传的，取映射的字段。否则直接去名字
        val imageUrls = mData.map { m ->
            val fileName = viewModel.imageKeyValue[m.fileName]
            if (fileName != null && fileName != "") {
                fileName
            } else {
                m.fileName
            }
        }.joinToString { i -> i }

        viewModel.waybillFormNetWork["imageUrl"] = imageUrls.emptyToNull()

        //1.新增
        if (id == -9999) {
            //输入运单号，需要校验规则，判断前7位除以7得到的余数是否等于第8位，是即符合规则，否则提示
            /*val prefixStr = viewModel.waybillFormNetWork.getString("prefix")
            if (prefixStr.length != 3 || !prefixStr.isValidInt()) {
                Common.showToast(this, "请输入正确的运单号前缀格式！")
                return
            }
            val checkWaybill = viewModel.waybillFormNetWork.getString("no")
            if (checkWaybill.length != 8 || !checkWaybill.isValidInt()) {
                Common.showToast(this, "请输入正确的运单号格式！")
                return
            }
            var subSequence = checkWaybill.subSequence(0, 7).toString().toInt()
            var subSequence2 = checkWaybill[7].toString().toInt()
            if (subSequence % 7 != subSequence2) {
                Common.showToast(this, "请输入正确的运单号格式！")
                return
            }*/

            loading()
            viewModel.saveFestGnjCangDan(viewModel.waybillFormNetWork)
            return
        }
        //2.编辑
        if (id != -9999) {
            loading()
            viewModel.updateFestGnjCangDan(viewModel.waybillFormNetWork)
            return
        }
    }

    /**
     * 初始化列表数据
     */
    private fun initData(status: String) {
        var write = false
        var waybillOperator = false
        when (status) {
            MitCommon.AccidentVisa.Info.read -> {
                write = false
                waybillOperator = false
            }
            MitCommon.AccidentVisa.Info.add -> {
                write = true
                waybillOperator = true
            }
            MitCommon.AccidentVisa.Info.update -> {
                write = true
                waybillOperator = false
            }
        }

        collectList.clear()
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                waybillOperator,
                "运单号",
                "wbNo",
                viewModel.waybillFormNetWork.getString("wbNo") ?: "", id == -9999, Constant.RequestCode.accident_visa_info_wbno_scan
            )
        )//  id == -9999 是新增，显示扫描
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                write,
                "不正常件数",
                "dpc",
                viewModel.waybillFormNetWork.getString("dpc") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                write,
                "外包装",
                "opacking",
                viewModel.outerPackageTypeList,
                viewModel.waybillFormNetWork.getString("opacking") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                write,
                "包装破损情况",
                "damage",
                viewModel.damageTypeList,
                viewModel.waybillFormNetWork.getString("damage") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                write,
                "内容物情况",
                "condition",
                viewModel.contentTypeList,
                viewModel.waybillFormNetWork.getString("condition") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                write,
                "发现时间类型",
                "searchDate",
                viewModel.searchDateTypeList,
                viewModel.waybillFormNetWork.getString("searchDate") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                write,
                "不正常类型",
                "kdamage",
                viewModel.unusualTypeList,
                viewModel.waybillFormNetWork.getString("kdamage") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                write,
                "航班日期",
                "fdate",
                false,
                viewModel.waybillFormNetWork.getString("fdate") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                true,
                write,
                "航班号",
                "fno",
                viewModel.waybillFormNetWork.getString("fno") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                false,
                false,
                "地区类型",
                "areaFlag",
                viewModel.waybillFormNetWork.getString("areaFlag") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                false,
                false,
                "始发港",
                "dep",
                viewModel.waybillFormNetWork.getString("dep") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                false,
                false,
                "目的港",
                "dest",
                viewModel.waybillFormNetWork.getString("dest") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                false,
                write,
                "运单总件数",
                "pc",
                viewModel.waybillFormNetWork.getString("pc") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                false,
                write,
                "运单总重量",
                "weight",
                viewModel.waybillFormNetWork.getString("weight") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                false,
                write,
                "复称重量",
                "checkWeight",
                viewModel.waybillFormNetWork.getString("checkWeight") ?: ""
            )
        )
        collectList.add(
            AccidentVisaInfoItemModel(
                false,
                write,
                "品名",
                "goods",
                viewModel.waybillFormNetWork.getString("goods") ?: ""
            )
        )

        collectList.add(AccidentVisaInfoItemModel(false, write, "备注", "remarks", viewModel.waybillFormNetWork.getString("remarks") ?: ""))

        //加载图片
        var imageUrl = viewModel.waybillFormNetWork.getString("imageUrl") ?: ""
        if (imageUrl != "") {
            val list = ArrayList<LocalMedia>()
            imageUrl.split(",").forEach { i ->
                val tempUrl = i.trim()
                var generateHttpAsLocalMedia = LocalMedia.generateHttpAsLocalMedia(loadImgUrl(tempUrl))
                generateHttpAsLocalMedia.fileName = tempUrl
                list.add(generateHttpAsLocalMedia)
            }
            mData.addAll(list)
        }

        totalRequestNotifyAdapter()
    }

    /**
     * 封装图片路径
     */
    private fun loadImgUrl(suffixUrl: String) =
        "${MyApplication.context.getString(com.lukouguoji.module_base.R.string.system_url)}/file/getImg/${suffixUrl.trim()}"

    /**
     * 清空数据
     */
    private fun reset() {
        //1.清空数据
        viewModel.waybillFormNetWork.clear()
        mData.clear()
        pictureAdapter.notifyDataSetChanged()
        initData(MitCommon.AccidentVisa.Info.add)
    }
}