<template>
    <div class="w-full p-2 flex overflow-auto justify-center">
        <el-table
            size="small"
            fit
            :data="inquiry_result"
            class="text-xs w-auto"
            style="border: 1px solid black;"
            :header-cell-style="{background: '#e0f2fe', color: 'black',borderColor: 'black'}"
            :cell-style="{borderColor: 'black'}"
            :max-height="subTableHeight - 40"
            border
        >
            <el-table-column type="index" label="#" width="50" align="center" header-align="center"/>
            <el-table-column prop="b_name" label="品牌" show-overflow-tooltip width="100" align="left" header-align="center"/>
            <el-table-column prop="code" label="件号" show-overflow-tooltip width="120" align="left" header-align="center"/>
            <el-table-column prop="new_code" label="更新件号" show-overflow-tooltip width="100" align="left" header-align="center"/>
            <el-table-column prop="name" label="品名" show-overflow-tooltip width="120" align="left" header-align="center"/>
            <el-table-column prop="price" label="面价" show-overflow-tooltip width="100" align="right" header-align="center">
                <template #default="{row}">
                    {{ (Math.round(row.price * 100) / 100.00).toFixed(2) }}
                </template>
            </el-table-column>
            <el-table-column prop="sell_price" label="预计售价" show-overflow-tooltip width="100" align="right" header-align="center">
                <template #default="{row}">
                    {{ (Math.round(row.sell_price * 100) / 100.00).toFixed(2) }}
                </template>
            </el-table-column>
            <el-table-column prop="goods" label="商城状况" show-overflow-tooltip width="120" header-align="center" align="center">
                <template #default="{row}">
                    <el-tag v-if="row.goods?.length>0" type="danger">有货({{ row.goods?.length }})</el-tag>
                    <el-tag v-else type="primary">无货</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="客户采购" header-align="center">
                <el-table-column prop="amount" label="采购数" show-overflow-tooltip width="80" align="right" header-align="center"/>
                <el-table-column prop="note" label="客户备注" show-overflow-tooltip width="120" align="left" header-align="center"/>
            </el-table-column>
            <el-table-column label="销售报价" width="120" align="center" header-align="center" v-if="inquiry_result_status == 3">
                <el-table-column label="供应品牌" show-overflow-tooltip width="100" align="left" header-align="center">
                    <template #default="{row}">
                        {{ row.g_bname }}
                    </template>
                </el-table-column>
                <el-table-column label="商品品相" show-overflow-tooltip width="80" align="left" header-align="center">
                    <template #default="{row}">
                        {{ row.g_quality }}
                    </template>
                </el-table-column>
                <el-table-column label="销售价" width="100" align="right" header-align="center">
                    <template #default="{row}">
                        {{ (+row.g_sell_price).toFixed(2) }}
                    </template>
                </el-table-column>
                <el-table-column label="加急服务" width="100" align="right" header-align="center">
                    <template #default="{row}">
                        {{ (+row.g_sell_price2).toFixed(2) }}
                    </template>
                </el-table-column>
                <el-table-column label="销售数" width="80" align="right" header-align="center">
                    <template #default="{row}">
                        {{ row.g_nums }}
                    </template>
                </el-table-column>
                <el-table-column label="销售备注" show-overflow-tooltip width="120" align="left" header-align="center">
                    <template #default="{row}">
                        {{ row.g_note }}
                    </template>
                </el-table-column>
            </el-table-column>
        </el-table>
    </div>
</template>

<script setup>
    import { ref,reactive,computed,onMounted } from 'vue'
    import { brandList,searchSupplier,addLog,getSupplierContact } from '@/api'
    import { supplyInquiry,supplierFile,inquiryGoodsList,info,addSupplyInquiry,removeSupplyInquiry,checkSupplyInquiry,sendLink } from '@/api/inquiry'
    import { Message,Delete,InfoFilled,Check,DocumentCopy,View,RefreshRight,Download,Upload,CloseBold,Avatar,Promotion,ChatDotRound,Link,Hide,DArrowLeft } from '@element-plus/icons-vue'
    // import XLSX from 'xlsx-js-style'
    import { utils,writeFile,read } from 'xlsx-js-style'
    import { ElMessage } from 'element-plus'
    import { md5 } from '@/utils'
    import { useUserStore } from '@/store'

    const user_store = useUserStore()
    const emit = defineEmits(['next-step','add-goods','status-change'])
    const props = defineProps({
        'orderId': {
            type: Number,
            default: 0
        },
        'orderStatus':{
            type: Number,
            default: 0
        }
    })

    const brand_list = ref([])
    const inquiryTableRef = ref()
    const goodsList = ref([])
    const inquiry_item = ref({})
    const order_status = ref(0)
    const order_id = ref(0)

    const goods_list = ref([])
    const group_list = ref([])
    const span_list = ref([])
    const flatProduct = (product)  => {
        let start = 0
        goods_list.value = []
        group_list.value = []
        span_list.value = []
        product.forEach(item => {
            if(item.enquiry && Object.keys(item.enquiry).length > 0) {
                let key_array = Object.keys(item.enquiry)//.filter(k => item.enquiry[k][0] > 0 || (item.enquiry[k].length > 3 && item.enquiry[k][3] >= 0))
                let rows = key_array.length
                if(rows > 1) {
                    span_list.value.push([start,rows])
                }
                group_list.value.push([start,start+rows-1])
                start += rows
                Object.entries(item.enquiry).forEach(([k,v]) => {
                    let i = v.length
                    product_list.value.push(Object.assign({},item,{
                        g_id: k,
                        g_price: i > 0 ? v[0] : 0.0,
                        g_price2: i > 3 ? v[3] : 0.0,
                        g_store: i > 1 ? v[1] : 0,
                        g_note: i > 2 ? v[2] : '',
                        g_source: i > 4 ? v[4] : '',
                        cost_price: i > 0 ? v[0] : 0.0,
                        cost_price2: i > 3 ? v[3] : 0.0,
                    }))
                })
            } else {
                product_list.value.push(Object.assign({},item,{
                    g_id: '',
                    g_price: 0.0,
                    g_price2: 0.0,
                    g_store: 0,
                    g_note: '',
                    g_source: '',
                    cost_price: 0.0,
                    cost_price2: 0.0,
                }))
                group_list.value.push([start,start])
                start += 1
            }
        })
    }

    const spanMethod = ({row, column, rowIndex, columnIndex}) => {
        if (columnIndex >= 0 && columnIndex <= 6) {
            let sp = span_list.value.find(([s,_]) => rowIndex === s)
            if(sp) {
                return {rowspan: sp[1], colspan: 1}
            }
            sp = span_list.value.find(([s,n]) => rowIndex > s && rowIndex < s + n)
            if(sp) {
                return {rowspan: 0, colspan: 0}
            }
        }
    }
    onMounted(async () => {
        order_id.value = +props.orderId
        await loadInquiry()
    })

    const loadInquiry = async () => {
        const { data:res } = await inquiry(order_id.value)
        if(res.error == 0) {
            order_status.value = +res.data.status
            inquiry_item.value = res.data
            goods_list.value = res.data.products
            if(order_status.value == 3) {
                flatOffer(res.data.offer)
            } else if(order_status.value == 0 && res.data.inquiry_status?.checked > 0) {
                flatSupply(res.data.offer)
            }
        }
    }

    const goodsTableRef = ref()
    const centerDialogVisible = ref(false)

    const goodsSelected = ref([])
    const goods_nums = computed(() => goodsSelected.length)
    const handleGoodsSelect = (val) => goodsSelected.value = val

    const expandPanel = (row) => {
        if(row.return_data && row.return_data.length > 0) {
            inquiryTableRef.value.toggleRowExpansion(row)
        }
    }

    const expandRowKeys = ref([])
    const isExpanded = computed(() => (id) => expandRowKeys.value.findIndex(it => it == id))
    const expandChange = async (row,rows) => {
        expandRowKeys.value = rows.map(item => item.id)
    }

    const supplier_id = ref('')
    const supplierSearch = async (qs, cb) => {
        if(qs && qs.length) {
            try {
                const {data:slist} = await searchSupplier(qs)
                var list = slist.data
                if (list.length == 0) {
                    list.push({
                        id: '-1',
                        value: '无匹配结果'
                    })
                    cb(list);
                } else {
                    list = list.map(item => {
                        return {
                            value: item.sname,
                            id: `${item.sid}`,
                            name: item.sname,
                            cname: item.company_name
                        }
                    })
                    cb(list);
                }
            } catch (error) {
                console.log(error)
            }
        } else {
            cb([{id: '-1',value: '无匹配结果'}])
        }
    }

    const handleSupplierSelect = async (item) => {
        supplier_id.value = ''
        if(item.id != -1 && !new_inquiry.supplier_array.map(m => m.id).includes(item.id)) {
            new_inquiry.supplier_array.push({id: item.id,name: item.name,cname: item.cname})
        }
    }

    let new_inquiry = reactive({
        supplier_array: [],
        note: ''
    })

    const makeInquiry = () => {
        new_inquiry = reactive({
            supplier_array: [],
            note: ''
        })
        supplier_id.value = ''
        centerDialogVisible.value = true
    }

    const removeSupplier = (index) => {
        new_inquiry.supplier_array.splice(index, 1)
    }

    const create_inquiry = async () => {
        centerDialogVisible.value = false
        const {data:order} = await info(props.orderId)
        let data = {
            products: goodsSelected.value,
            suppliers: new_inquiry.supplier_array.map(item => item.id),
            order_no: order.data.order_no,
            user_id: order.data.user_id,
            note: new_inquiry.note
        }
        const {data:res} = await addSupplyInquiry(props.orderId,data)
        if(res.data.length) {
            await addLog(props.orderId,user_store.logName,'创建询价函',JSON.stringify(data))
            ElMessage.success("询价函成功创建！")
            const {data:inquiry} = await supplyInquiry(props.orderId)
            inquiryList.value = inquiry.data
        }
    }

    const copyToClipboard = (content) => {
        if (window.clipboardData) {
            window.clipboardData.setData('text', content);
        } else {
            (function (content) {
                document.oncopy = function (e) {
                    e.clipboardData.setData('text', content);
                    e.preventDefault();
                    document.oncopy = null;
                }
            })(content);
            document.execCommand('Copy');
        }
    }

    const get_product_market = (id) => {
        const product = goodsList.value.find(item => item.id == id)
        if(product) {
            return +product.price
        }
        return 0.00
    }

    const productMmarket = computed(() => (id) => {
        const product = goodsList.value.find(item => item.id == id)
        if(product) {
            return +product.price
        }
        return 0.00
    })

    const contact_list = ref([])
    const contact_id = ref(0)
    const contactDialog = ref(false)
    const inquiryIndex = ref(0)
    const inquiryUrl = ref('')
    const handleSendLink = async (index,url) => {
        contact_id.value = 0
        let {data: res} = await getSupplierContact(inquiryList.value[index].supplier_id)
        if(res.data.contact.length > 1) {
            contact_list.value = res.data.contact
            contact_id.value = null
            inquiryIndex.value = index
            inquiryUrl.value = url
            contactDialog.value = true
        } else {
            if(res.data.contact.length == 1) {
                contact_id.value = res.data.contact[0].id
            }
            copyToClipboard(url)
            await addLog(props.orderId,user_store.logName,'发送询价函','询价函id=' + inquiryList.value[index].id)
            if(inquiryList.value[index].status != 2) {
                await sendLink(inquiryList.value[index].id,contact_id.value)
                inquiryList.value[index].status = 1
            }
            ElMessage({
                message: "询价函链接已生成！",
                type: 'success',
            })
        }
    }

    const selectContact = async () => {
        contactDialog.value = false
        copyToClipboard(inquiryUrl.value)
        await addLog(props.orderId,user_store.logName,'发送询价函','询价函id=' + inquiryList.value[inquiryIndex.value].id)
        if(inquiryList.value[inquiryIndex.value].status != 2) {
            await sendLink(inquiryList.value[inquiryIndex.value].id,contact_id.value)
            inquiryList.value[inquiryIndex.value].status = 1
        }
        ElMessage({
            message: "询价函链接已生成！",
            type: 'success',
        })
    }

    const refresh = async () => {
        const {data:inquiry} = await supplyInquiry(props.orderId)
        inquiryList.value = inquiry.data
    }

    const handleDelete = async (index, row) => {
        await removeSupplyInquiry(row.id)
        await addLog(order_id.value,user_store.logName,'删除供应商询价函','询价函id=' + row.id)
        ElMessage.success("询价单已删除！")
        inquiryList.value.splice(index, 1)
        emit('status-change',order_id.value,'remove-supply-inquiry')
    }

    const handleChecked = async (index, row) => {
        await checkSupplyInquiry(row.id)
        await addLog(order_id.value,user_store.logName,'确认供应商询价函','询价函id=' + row.id)
        ElMessage.success("已确认询价函！")
        inquiryList.value[index]['status'] = 3
        emit('status-change',order_id.value,'check-supply-inquiry')
    }

    const exportReturn = (row) => {
        const worksheet = utils.aoa_to_sheet([[`${row.supplier_name}报价函`]], {origin: 'A1'})
        if(!worksheet["!rows"]) {
            worksheet["!rows"] = []
        }
        if(!worksheet["!cols"]) {
            worksheet["!cols"] = []
        }
        if(!worksheet["!rows"][0]) {
            worksheet["!rows"][0] = {hpx: 22}
        }
        worksheet["!cols"][3] = {wch: 20}
        worksheet['A1']['s'] = {font:{bold:true,sz:14},alignment:{horizontal:'center',vertical:'center',wrapText:true}}
        worksheet['!merges'] = [{s:{r:0,c:0},e:{r:0,c:9}}]
        worksheet['!merges'].push({s:{r:1,c:0},e:{r:1,c:3}})
        worksheet['!merges'].push({s:{r:1,c:5},e:{r:1,c:9}})
        worksheet['F2'] = {t:'d',v: row.return_time,z:'报价日期：YYYY年MM月DD日'}
        utils.sheet_add_aoa(worksheet, [['品牌', '产品件号', '更新件号','品名','购买数','面价单价(元)', '执行单价(元)','紧急单价(元)','库存数','备注']], {origin: "A3"})
        let data = row.return_data
        const dataRow = 4
        const align_center = {
            horizontal: 'center',
            vertical: 'center',
            wrapText: true
        }
        const align_right = {
            horizontal: 'right',
            vertical: 'center',
            wrapText: true
        }
        const title_style = {
            font: { bold: true },
            alignment: align_center
        };
        const style_center = {
            alignment: align_center
        }
        const style_right =	{
            alignment: align_right
        }
        worksheet['A3']['s'] = title_style
        worksheet['B3']['s'] = title_style
        worksheet['C3']['s'] = title_style
        worksheet['D3']['s'] = title_style
        worksheet['E3']['s'] = title_style
        worksheet['F3']['s'] = title_style
        worksheet['G3']['s'] = title_style
        worksheet['H3']['s'] = title_style
        worksheet['I3']['s'] = title_style
        worksheet['J3']['s'] = title_style
        data.forEach((v,row) => {
            // 修改只显示new_code
            // utils.sheet_add_aoa(worksheet, [[v.b_name,v.new_code ? v.new_code : v.code,v.new_code ?? '',v.name,v.amount,v.market,v.price,v.price2,v.nums,v.note]],{origin: `A${row + dataRow}`})
            utils.sheet_add_aoa(worksheet, [[v.b_name,v.code,v.new_code ?? '',v.name,v.amount,v.market,v.price,v.price2,v.nums,v.note]],{origin: `A${row + dataRow}`})
            if(worksheet[`A${row + dataRow}`]) {
                worksheet[`A${row + dataRow}`]['s'] = style_center
            }
            if(worksheet[`E${row + dataRow}`]) {
                worksheet[`E${row + dataRow}`]['s'] = style_right
                worksheet[`E${row + dataRow}`]['s'] = '0'
            }
        })
        const workbook = utils.book_new();
        if(!workbook.Custprops) {
            workbook.Custprops = {}
        }
        let token = `${row.supplier_id}ji${row.id}fu${row.user_id}jf${row.order_id}`
        workbook.Custprops["type"] = 'full';
        workbook.Custprops["inquery"] = row.id;
        workbook.Custprops["supplier"] = row.supplier_id;
        workbook.Custprops["link"] = row.link;
        workbook.Custprops["order_no"] = row.order_no;
        workbook.Custprops["token"] = md5(token);
        utils.book_append_sheet(workbook, worksheet, `${row.supplier_name}报价函`);
        var time = new Date();
        var ext = `${row.supplier_name}-${time.getFullYear()}${time.getMonth() + 1}${time.getDate()}-${Math.round(Math.random() * 10000)}`;
        let fn = `${ext}.xlsx`
        writeFile(workbook,fn,{compression: true});
        ElMessage({
            message: "询价回函已下载！",
            type: 'success',
        })
    }

    const downloadExcel = async (row_data) => {
        let seller_name = user_store.sellerName
        const worksheet = utils.aoa_to_sheet([[`${seller_name}询价单`]], {origin: 'A1'})
        if(!worksheet["!rows"]) {
            worksheet["!rows"] = []
        }
        if(!worksheet["!cols"]) {
            worksheet["!cols"] = []
        }
        if(!worksheet["!rows"][0]) {
            worksheet["!rows"][0] = {hpx: 22}
        }
        worksheet["!cols"][3] = {wch: 20}
        worksheet['A1']['s'] = {font:{bold:true,sz:14},alignment:{horizontal:'center',vertical:'center',wrapText:true}}
        worksheet['!merges'] = [{s:{r:0,c:0},e:{r:0,c:9}}]
        worksheet['!merges'].push({s:{r:1,c:0},e:{r:1,c:3}})
        worksheet['!merges'].push({s:{r:1,c:5},e:{r:1,c:9}})
        worksheet['A2'] = {t:'s',v:`报价单位：${row_data.supplier_name}`}
        worksheet['F2'] = {t:'d',v: row_data.create_time,z:'询价日期：YYYY年MM月DD日'}
        utils.sheet_add_aoa(worksheet, [['品牌', '产品件号', '更新件号','品名','购买数','面价单价(元)', '执行单价(元)','紧急单价(元)','库存数','备注']], {origin: "A3"})
        let data = row_data.products
        const dataRow = 4
        const align_center = {
            horizontal: 'center',
            vertical: 'center',
            wrapText: true
        }
        const align_right = {
            horizontal: 'right',
            vertical: 'center',
            wrapText: true
        }
        const title_style = {
            font: { bold: true },
            alignment: align_center
        };
        const style_center = {
            alignment: align_center
        }
        const style_right = {
            alignment: align_right
        }
        worksheet['A3']['s'] = title_style
        worksheet['B3']['s'] = title_style
        worksheet['C3']['s'] = title_style
        worksheet['D3']['s'] = title_style
        worksheet['E3']['s'] = title_style
        worksheet['F3']['s'] = title_style
        worksheet['G3']['s'] = title_style
        worksheet['H3']['s'] = title_style
        worksheet['I3']['s'] = title_style
        worksheet['J3']['s'] = title_style
        data.forEach((v,row) => {
            // 修改只显示new_code
            // utils.sheet_add_aoa(worksheet, [[v.b_name,v.code,'',v.name,v.amount]],{origin: `A${row + dataRow}`})
            utils.sheet_add_aoa(worksheet, [[v.b_name,v.new_code ? v.new_code : v.code,'',v.name,v.amount]],{origin: `A${row + dataRow}`})
            if(worksheet[`A${row + dataRow}`]) {
                worksheet[`A${row + dataRow}`]['s'] = style_center
            }
            if(worksheet[`E${row + dataRow}`]) {
                worksheet[`E${row + dataRow}`]['s'] = style_right
                worksheet[`E${row + dataRow}`]['s'] = '0'
            }
        })
        const workbook = utils.book_new();
        if(!workbook.Custprops) {
            workbook.Custprops = {}
        }
        let token = `${row_data.supplier_id}ji${row_data.id}fu${row_data.user_id}jf${row_data.order_id}`
        workbook.Custprops["type"] = 'full';
        workbook.Custprops["inquery"] = row_data.id;
        workbook.Custprops["supplier"] = row_data.supplier_id;
        workbook.Custprops["link"] = row_data.link;
        workbook.Custprops["order_no"] = row_data.order_no;
        workbook.Custprops["token"] = md5(token);
        utils.book_append_sheet(workbook, worksheet, `${seller_name}询价函`);
        var time = new Date();
        var ext = `${row_data.supplier_name}-${time.getFullYear()}${time.getMonth() + 1}${time.getDate()}-${Math.round(Math.random() * 10000)}`;
        let fn = `${ext}.xlsx`
        writeFile(workbook,fn,{compression: true});
        await addLog(props.orderId,user_store.logName,'下载询价函','询价函id=' + row_data.id)
        if(row_data.status != 2) {
            await sendLink(row_data.id)
            row_data.status = 1
        }
        ElMessage({
            message: "询价函已下载！",
            type: 'success',
        })
    }

    //简易询价单
    const simpleExcel = async (row_data) => {
        let seller_name = user_store.sellerName
        let data = row_data.products
        if(data.length) {
            let sheet_data = []
            data.forEach(item => sheet_data.push([item.new_code?item.new_code:item.code,item.amount]))
            const worksheet = utils.aoa_to_sheet(sheet_data, {origin: 'A1'})
            if(!worksheet["!cols"]) {
                worksheet["!cols"] = []
            }
            worksheet["!cols"][0] = {wch: 20}
            worksheet["!cols"][1] = {wch: 20}
            const workbook = utils.book_new();
            if(!workbook.Custprops) {
                workbook.Custprops = {}
            }
            let token = `${row_data.supplier_id}ji${row_data.id}fu${row_data.user_id}jf${row_data.order_id}`
            workbook.Custprops["type"] = 'simple';
            workbook.Custprops["inquery"] = row_data.id;
            workbook.Custprops["supplier"] = row_data.supplier_id;
            workbook.Custprops["link"] = row_data.link;
            workbook.Custprops["order_no"] = row_data.order_no;
            workbook.Custprops["token"] = md5(token);
            utils.book_append_sheet(workbook, worksheet, `${seller_name}询价函`);
            var time = new Date();
            var ext = `${row_data.supplier_name}-${time.getFullYear()}${time.getMonth() + 1}${time.getDate()}-${Math.round(Math.random() * 10000)}`;
            let fn = `${ext}.xlsx`
            writeFile(workbook,fn,{compression: true});
            await addLog(props.orderId,user_store.logName,'生成并下载简易询价函','询价函id=' + row_data.id)
            if(row_data.status != 2) {
                await sendLink(row_data.id)
                row_data.status = 1
            }
            ElMessage({
                message: "简易询价函已下载！",
                type: 'success',
            })
        } else {
            ElMessage({
                message: "没有需要询价的产品！",
                type: 'warning',
            })
        }
    }
    const MAP_KEYS = ['件号','品牌','数量','单价','面价','新号','备注','库存']
    const MAP_NAME = ['code','brand','amount','price','market','new_code','note','nums']
    // 简易询价回函处理，无表头，顺序件号、单价、数量、备注、品牌
    const uploadExcel = async (row_data) => {
        const [hFile] = await window.showOpenFilePicker({
            types: [{
                description: '数据表',
                accept: {
                    'application/vnd.ms-excel': ['.xlsx', '.xls', /*...*/ ]
                }
            }],
            excludeAcceptAllOption: true,
            multiple: false
        });
        const file = await (await hFile.getFile()).arrayBuffer();
        const wb = read(file);
        let token = md5(`${row_data.supplier_id}ji${row_data.id}fu${row_data.user_id}jf${row_data.order_id}`)
        if(wb.Custprops["inquery"] == row_data.id && wb.Custprops["supplier"] == row_data.supplier_id && wb.Custprops["link"] == row_data.link && wb.Custprops["order_no"] == row_data.order_no && wb.Custprops["token"] == token) {
            const sheet = wb.SheetNames[0]
            if(wb.Custprops["type"] == 'simple') {
                const price_data = utils.sheet_to_json(wb.Sheets[sheet], {header: "A"})
                let product = row_data.products
                price_data.forEach(item => {
                    let product_data = product.find(val => val.code == item['A'] || val.new_code == item['A'])
                    if(product_data) {
                        product_data.price = item['C'] ?? 0.0
                        product_data.note = item['D'] ?? ''
                        product_data.nums = item['E'] ?? 0
                    }
                })
                const { data:res } = await supplierFile(row_data.id,product,token)
                if(res.data) {
                    row_data.status = 2
                    row_data.return_data = product
                    ElMessage({
                        message: "文件询价函报价成功！",
                        type: 'success',
                    })
                } else {
                    ElMessage({
                        message: "文件询价函报价失败！请检查后重试!",
                        type: 'error',
                    })
                }
            } else if(wb.Custprops["type"] == 'full') {
                const price_data = utils.sheet_to_json(wb.Sheets[sheet], {header: "A"})
                price_data.splice(0,3)
                let product = row_data.products
                price_data.forEach(item => {
                    let product_data = product.find(val => val.code == item['B'] || val.new_code == item['B'])
                    if(product_data) {
                        product_data.new_code = item['C'] ?? ''
                        product_data.market = item['F'] ?? 0.0
                        product_data.price = item['G'] ?? 0.0
                        product_data.price2 = item['H'] ?? 0.0
                        product_data.nums = item['I'] ?? 0
                        product_data.note = item['J'] ?? ''
                    }
                })
                const { data:res } = await supplierFile(row_data.id,product,token)
                if(res.data) {
                    row_data.status = 2
                    row_data.return_data = product
                    ElMessage({
                        message: "文件询价函报价成功！",
                        type: 'success',
                    })
                } else {
                    ElMessage({
                        message: "文件询价函报价失败！请检查后重试!",
                        type: 'error',
                    })
                }
            } else {
                ElMessage({
                    message: "不支持的询价函格式！",
                    type: 'warning',
                })
            }
        } else {
            ElMessage({
                message: "无效的询价函！",
                type: 'warning',
            })
        }
    }
</script>

<style scoped>
    :deep(.no-expand-icon .el-table__expand-icon) {
        display: none;
    }
</style>