<template>
    <el-dialog title="确认报价" class="get-price-dialog" v-model="checkDialog" width="1400px" append-to-body>
        <template #header>
            <div class="dialog-header" style="display: flex;justify-content: center;align-items: center;">
                <el-select v-model="form.quotationType" style="width: 150px">
                    <el-option :value="1" label="国内贸易"></el-option>
                    <el-option :value="2" label="国外贸易"></el-option>
                </el-select>
            </div>
        </template>
        <el-row>
            <el-col :span="24" style="border-right: 1px solid #e5e6e7; padding-left: 5px">
                <el-row style="margin-bottom: 15px">
                    <el-col :span="24">
                        <el-button type="primary" icon="plus" @click="addProduct">添加产品</el-button>
                        <el-button type="primary" icon="plus" @click="addOtherProduct">添加外部产品</el-button>
                        <el-button type="primary" icon="plus" @click="addOtherFee">添加其他费用</el-button>
                    </el-col>
                </el-row>
                <el-table :data="form.ssdSkuDetailVOList">

                    <el-table-column prop="ssdSkuCode" label="内部编号" width="110"> </el-table-column>
                    <el-table-column prop="ssdSkuCode" label="规格">
                        <template #default="scope">
                            <template v-if="scope.row.ssdSkuCode != '外部产品' && scope.row.ssdSkuCode != '其他费用'">
                                <span class="ss">{{ scope.row.connectorType }}<small>|<br></small>{{
                                    scope.row.productSize
                                    }}<small>|<br></small>{{ scope.row.connectorProtocol }}<small>|<br></small>{{
                                    scope.row.coreChipType }}<small>|<br></small>{{ scope.row.productLevel
                                    }}<small>|<br></small>{{ scope.row.flashChipType }}<small>|<br></small>{{
                                    scope.row.capacity }}</span>
                            </template>
                            <template v-else>
                                <SelectDict v-if="scope.row.ssdSkuCode == '其他费用'" :clearable='false'
                                    v-model="scope.row.specificationRemarks" placeholder="请选择其他费用"
                                    dictCode="additional_costs"></SelectDict>
                                <el-input v-else v-model="scope.row.specificationRemarks"
                                    placeholder="请输入规格备注"></el-input>
                            </template>

                        </template>
                    </el-table-column>
                    <el-table-column prop="interface" label="功能配置">
                        <template #default="scope">
                            <template v-if="scope.row.ssdSkuCode != '外部产品' && scope.row.ssdSkuCode != '其他费用'">
                                <el-checkbox :disabled="scope.row.forceOpenPhysicalDestroyTemp"
                                    v-if="scope.row.openPhysicalDestroy === 1" @change="computeData(scope.row)"
                                    v-model="scope.row.forceOpenPhysicalDestroy">物理销毁
                                </el-checkbox>
                                <el-checkbox :disabled="scope.row.forceOpenLogicDestroyTemp"
                                    v-if="scope.row.openLogicDestroy === 1" @change="computeData(scope.row)"
                                    v-model="scope.row.forceOpenLogicDestroy">逻辑销毁
                                </el-checkbox>
                                <el-checkbox :disabled="scope.row.forceOpenAesEncryptTemp"
                                    v-if="scope.row.openAesEncrypt === 1" @change="computeData(scope.row)"
                                    v-model="scope.row.forceOpenAesEncrypt">AES加密
                                </el-checkbox>
                                <el-checkbox :disabled="scope.row.forceOpenRapidBackupTemp"
                                    v-if="scope.row.openRapidBackup === 1" @change="computeData(scope.row)"
                                    v-model="scope.row.forceOpenRapidBackup">r-Backup
                                </el-checkbox>
                            </template>
                            <template v-else>
                                <el-input v-model="scope.row.functionRemarks" placeholder="请输入功能备注"></el-input>
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column prop="interface" label="数量" width="160">
                        <template #default="scope">
                            <el-input-number v-model="scope.row.productCount" style="width: 130px;" step="2"
                                @change="computeData(scope.row)" :precision="0" :min="1" :max="99999"
                                label="请输入数量"></el-input-number>
                        </template>
                    </el-table-column>
                    <el-table-column prop="interface" label="国内不含税总价(￥)">
                        <template #default="scope">
                            <template v-if="scope.row.ssdSkuCode != '外部产品' && scope.row.ssdSkuCode != '其他费用'">
                                <p style="font-weight: 600">标准价格:</p>
                                <p>总价:{{ $formatNumber(scope.row.skuPriceCNYWithNoRate) }}</p>
                                <p>单价:{{ $formatNumber(scope.row.unitPriceCNYWithNoRate) }}</p>
                                <p style="font-weight: 600"> 报价金额:</p>
                                <block v-if="form.quotationType == 1">
                                    <p style="padding: 6px 0">总价:{{ $formatNumber(scope.row.skuPriceCNYWithNoRateActual
                                        ) }}</p>
                                    <p style="padding: 6px 0">单价:{{
                                        $formatNumber(scope.row.unitPriceCNYWithNoRateActual) }}</p>
                                </block>
                                <blcok v-else>
                                    <el-input title='' @change="computedDataUnit(scope.row, 3)" type="number"
                                        style="margin-bottom: 5px" v-model="scope.row.skuPriceCNYWithNoRateActual"
                                        placeholder="请输入总价">
                                        <template #prepend>总价</template>
                                    </el-input>
                                    <el-input title='' @change="computedDataUnit(scope.row, 1)" type="number"
                                        v-model="scope.row.unitPriceCNYWithNoRateActual" placeholder="请输入单价">
                                        <template #prepend>单价</template>
                                    </el-input>
                                </blcok>

                            </template>
                            <template v-else>
                                <p style="font-weight: 600"> 报价金额:</p>
                                <block v-if="form.quotationType == 1">
                                    <p style="padding: 6px 0">总价:{{ $formatNumber(scope.row.skuPriceCNYWithNoRateActual
                                        ) }}</p>
                                    <p style="padding: 6px 0">单价:{{
                                        $formatNumber(scope.row.unitPriceCNYWithNoRateActual) }}</p>
                                </block>
                                <blcok v-else>
                                    <el-input type="number" style="margin-bottom: 5px"
                                        @change="computedDataUnit(scope.row, 3)"
                                        v-model="scope.row.skuPriceCNYWithNoRateActual" placeholder="请输入总价">
                                        <template #prepend>总价</template>
                                    </el-input>
                                    <el-input type="number" @change="computedDataUnit(scope.row, 1)"
                                        v-model="scope.row.unitPriceCNYWithNoRateActual" placeholder="请输入单价">
                                        <template #prepend>单价</template>
                                    </el-input>
                                </blcok>
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column prop="interface" label="国内价格(￥)（含13%增值税）">
                        <template #default="scope">
                            <template v-if="scope.row.ssdSkuCode != '外部产品'  && scope.row.ssdSkuCode != '其他费用'">
                                <p style="font-weight: 600">标准价格:</p>
                                <p>总价:{{ $formatNumber(scope.row.skuPriceCNY) }}</p>
                                <p>单价:{{ $formatNumber(scope.row.unitPriceCNY) }}</p>
                                <p style="font-weight: 600">报价金额:</p>
                                <block v-if="form.quotationType == 2">
                                    <p style="padding: 6px 0">总价:{{ $formatNumber(scope.row.skuPriceCNYActual ) }}</p>
                                    <p style="padding: 6px 0">单价:{{ $formatNumber(scope.row.unitPriceCNYActual) }}</p>
                                </block>

                                <block v-else>
                                    <el-input type="number" @change="computedDataUnit(scope.row, 6)"
                                        style="margin-bottom: 5px" v-model="scope.row.skuPriceCNYActual"
                                        placeholder="请输入总价"> <template #prepend>总价</template></el-input>
                                    <el-input type="number" @change="computedDataUnit(scope.row, 5)"
                                        v-model="scope.row.unitPriceCNYActual" placeholder="请输入单价"> <template
                                            #prepend>单价</template></el-input>
                                </block>

                            </template>
                            <template v-else>
                                <p style="font-weight: 600"> 报价金额:</p>
                                <block v-if="form.quotationType == 2">
                                    <p style="padding: 6px 0">总价:{{ $formatNumber(scope.row.skuPriceCNYActual ) }}</p>
                                    <p style="padding: 6px 0">单价:{{ $formatNumber(scope.row.unitPriceCNYActual) }}</p>
                                </block>
                                <block v-else>
                                    <el-input type="number" @change="computedDataUnit(scope.row, 6)"
                                        style="margin-bottom: 5px" v-model="scope.row.skuPriceCNYActual"
                                        placeholder="请输入总价"> <template #prepend>总价</template></el-input>
                                    <el-input type="number" @change="computedDataUnit(scope.row, 5)"
                                        v-model="scope.row.unitPriceCNYActual" placeholder="请输入单价"> <template
                                            #prepend>单价</template></el-input>
                                </block>
                                <!--                                <el-input type="number" title='' style="margin-bottom: 5px" v-model="scope.row.skuPriceCNYActual" placeholder="请输入总价">  <template #prepend>总价</template></el-input>-->
                                <!--                                <el-input type="number" title='' v-model="scope.row.unitPriceCNYActual" placeholder="请输入单价"> <template #prepend>单价</template></el-input>-->
                            </template>
                        </template>
                    </el-table-column>

                    <el-table-column prop="interface" :label="`国外价格($)（不含税，美元汇率${USDToCNYRate}）`">
                        <template #default="scope">
                            <template v-if="scope.row.ssdSkuCode != '外部产品' && scope.row.ssdSkuCode != '其他费用'">
                                <p style="font-weight: 600">标准价格:</p>
                                <p>总价:{{ $formatNumber(scope.row.skuPriceUSD) }}</p>
                                <p>单价:{{ $formatNumber(scope.row.unitPriceUSD) }}</p>
                                <p style="font-weight: 600">报价金额:</p>
                                <el-input title='' @blur="computedDataUnit(scope.row, 4)" style="margin-bottom: 5px"
                                    type="number" v-model="scope.row.skuPriceUSDActual" placeholder="请输入总价"> <template
                                        #prepend>总价</template></el-input>
                                <el-input title='' @blur="computedDataUnit(scope.row, 2)" type="number"
                                    v-model="scope.row.unitPriceUSDActual" placeholder="请输入单价"> <template
                                        #prepend>单价</template></el-input>
                            </template>
                            <template v-else>
                                <p style="font-weight: 600"> 报价金额:</p>
                                <el-input title='' style="margin-bottom: 5px" type="number"
                                    @change="computedDataUnit(scope.row, 4)" v-model="scope.row.skuPriceUSDActual"
                                    placeholder="请输入总价"> <template #prepend>总价</template></el-input>
                                <el-input title='' type="number" @change="computedDataUnit(scope.row, 2)"
                                    v-model="scope.row.unitPriceUSDActual" placeholder="请输入单价"> <template
                                        #prepend>单价</template></el-input>
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column prop="deliveryDays" label="预计生产天数">
                        <template #default="scope">
                            <template v-if="scope.row.ssdSkuCode != '外部产品' && scope.row.ssdSkuCode != '其他费用'">
                                <p>{{ scope.row.deliveryDays }}</p>
                            </template>
                            <template v-else>
                                <el-input type="number" v-model="scope.row.deliveryDays" placeholder="请输入预计生产天数">
                                    <template #prepend>天数</template></el-input>
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column prop="interface" label="操作">
                        <template #default="scope">
                            <!--                            <el-button size="small"  @click="detail(scope.row.datasheetUrl)">产品详情</el-button>-->
                            <!--                            <el-link @click="openSkuDetail(scope.row)" style="margin-right: 5px" type="primary">产品详情</el-link>-->
                            <el-link style="margin-right: 5px" @click="delPriceSkuData(scope.row)" type="danger"><i
                                    class="el-icon-delete"></i>删除</el-link>

                            <el-link v-if="scope.row.ssdSkuCode != '外部产品' && scope.row.ssdSkuCode != '其他费用'"
                                :href="scope.row.datasheetUrl" style="color: #1874ff" tag="a" :download="getName(scope.row.datasheetUrl)"
                                target="_blank">下载规格书</el-link>
                            <!--                            <el-button type="danger" size="small" @click="delPriceSkuData(scope.row)">删除</el-button>-->
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
        </el-row>
        <el-form :model="form" ref="queryFormRef" style="margin-top: 20px" :inline="true">
            <el-row>
                <el-col :span="24">
                    <div style="display: flex;justify-content: end; width: 100%">
                        <el-form-item label="产品数量:">
                            {{ countNum }}
                        </el-form-item>
                        <el-form-item label="产品总金额:">
                            {{ $formatNumber(totalMoney) }}
                        </el-form-item>
                        <el-form-item label="其他费用:">
                            {{ $formatNumber(otherTotalMoney) }}
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="downPdf(1)">下载中文报价</el-button>
                            <el-button type="primary" @click="downPdf(2)">下载英文报价</el-button>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="reset">取消</el-button>
                <el-button type="primary" :loading="submitLoading" @click="submit">提交报价</el-button>

            </div>
        </template>
    </el-dialog>

    <ProductPrice ref="productPriceRef" @callBack="okPrice"></ProductPrice>
</template>

<script setup lang="ts">
import skuDetail from './skuDetail.vue'
import {
    downLodaQuotation, getDetail,
    listProductType,
    querySkuVoList,
    quotationAdd,
    ssdStep1GetSku,
    ssdStep1GetSkuList,
    getUSDtoCnyRate,
    quotationEdite,
    getPriceCNY,
    getPriceUSD
} from '@/api/product/index'
import downloadPlugins from '@/plugins/download'
import {
    ProductTypeVo,
    SkuVo,
    SkuQueryVo,
    ProductTypeQuery,
    MakeOrderSkuDetailVO,
    SsdSkuDetailVOList
} from '@/api/product/types'
import {AllBusinessForm, AllBusinessQuery} from "@/api/business/allBusiness/types";
import {useDictCache} from "@/hooks/web/useDict";
const { queryDictDetailByCodes } = useDictCache(['additional_costs' ])
queryDictDetailByCodes()

const emits = defineEmits(['ok'])
const skuData = ref<Array<SkuVo>>([])

const isEdite = ref(false)
const submitLoading = ref(false)

const productTypeListVo = ref<Array<ProductTypeVo>>()
const skuVoList = ref<Array<SkuVo>>()

//确认报价
const checkDialog = ref(false)
//确认报价数据
// const priceData = ref<Array<MakeOrderSkuDetailVO>>([])

const initFormData:SsdSkuDetailVOList={
    totalEarnestAmt: undefined,
    totalNumber: undefined,
    totalOrderAmt: undefined,
    abutmentUserId: undefined,
    businessId: undefined,
    customerId: undefined,
    describe: undefined,
    id: undefined,
    totalMoney: undefined,
    orderFormId: undefined,
    rate: undefined,
    quotationType: 2,
    ssdSkuDetailVOList:[]
}
//添加外部产品
const addOtherProduct = ()=>{
    let param = {
        ssdSkuCode: '外部产品',
        status: 2,
        pageIndex: 1,
        pageSize: 1,
    }

    getSkuList(param)
}//添加外部产品
const addOtherFee = ()=>{
    let param = {
        ssdSkuCode: '其他费用',
        status: 2,
        pageIndex: 1,
        pageSize: 1,
    }

    getSkuList(param)
}
// const queryFormsSku =reactive( )

const getSkuList = async (queryFormsSku)=>{
    let data  = await querySkuVoList(queryFormsSku)
    console.log(data.result.records)
    okPrice(data.result.records)
    // skuData.value = data.result.records
}

const computedDataUnit = async (data, type)=>{
    let temp = form.value.ssdSkuDetailVOList.find(i=>i.randomId == data.randomId)
    //国内
    temp.quotationPricetype = type
    let res = await getPriceCNY(temp)
    Object.assign(data, temp)
    if( res.result.skuPriceCNYActual) {
        data.skuPriceCNYActual = res.result.skuPriceCNYActual
    }
    if( res.result.unitPriceCNYActual) {
        data.unitPriceCNYActual = res.result.unitPriceCNYActual
    }
    if( res.result.unitPriceCNYWithNoRateActual) {
        data.unitPriceCNYWithNoRateActual = res.result.unitPriceCNYWithNoRateActual
    }
    if( res.result.skuPriceUSDActual) {
        data.skuPriceUSDActual = res.result.skuPriceUSDActual
    }
    if( res.result.unitPriceUSDActual) {
        data.unitPriceUSDActual = res.result.unitPriceUSDActual
    }
    if( res.result.skuPriceCNYWithNoRateActual) {
        data.skuPriceCNYWithNoRateActual = res.result.skuPriceCNYWithNoRateActual
    }
    // //总价 CNY含税（实际）
    // data.skuPriceCNYActual = res.result.skuPriceCNYActual ? res.result.skuPriceCNYActual : 0
    // //总价 CNY不含税（实际）
    // data.skuPriceCNYWithNoRateActual = res.result.skuPriceCNYWithNoRateActual ? res.result.skuPriceCNYWithNoRateActual : 0
    // //单价CNY含税（实际）
    // data.unitPriceCNYActual = res.result.unitPriceCNYActual ? res.result.unitPriceCNYActual : 0
    //
    // //单价CNY不含税（实际）
    // data.unitPriceCNYWithNoRateActual = res.result.unitPriceCNYWithNoRateActual ? res.result.unitPriceCNYWithNoRateActual : 0
    // //美元总价
    // data.skuPriceUSDActual = res.result.skuPriceUSDActual ? res.result.skuPriceUSDActual : 0
    // //美元单价
    // data.unitPriceUSDActual = res.result.unitPriceUSDActual ? res.result.unitPriceUSDActual : 0
}

const data = reactive({
    form: {...initFormData},
    rules: {
        id: [
            {required: true, message: "商机主键不能为空", trigger: "blur"}
        ],
    }
})

const {form, rules} = toRefs(data);


const downPdf = async (type)=>{
    if(form.value.ssdSkuDetailVOList.length <= 0) {
        ElMessage.error('请添加产品')
        return
    }

    form.value.ssdSkuDetailVOList.forEach(item=>{
        item.languageType = type
    })
    let param = {
        quotationType: form.value.quotationType,
        ssdSkuDetailVOList: form.value.ssdSkuDetailVOList
    }
    let time = new Date().getTime()
    let name = type === 1 ? `报价单-${time}.docx` : `Quotation-${time}.docx`
    await downLodaQuotation(param, name)
}

//提交报价
const submit=async ()=>{
    submitLoading.value = true
    if (form.value.ssdSkuDetailVOList.length <= 0) {
        ElMessage.error('请添加产品')
        submitLoading.value = false
        return
    }
    if (form.value.businessId) {
        let res = null
        if (isEdite.value) {
            res = await quotationEdite(form.value)
        } else {
            res = await quotationAdd(form.value)
        }

        if(res.success) {
            ElMessage.success((isEdite.value ? '编辑' : '添加') + '成功')
            reset()
            emits('ok')
            checkDialog.value = false
        }else{
            ElMessage.error((isEdite.value ? '编辑' : '添加') + '添加失败')
        }
        emits('ok')
        submitLoading.value = false
        return
    }
    submitLoading.value = false
    checkDialog.value = false
    form.value.totalMoney = totalMoney.value
    emits('ok', form.value)
}
const computeData = async (data) => {
    // if(data.ssdSkuCode == '外部产品') return

    let temp = form.value.ssdSkuDetailVOList.find(i=>i.randomId == data.randomId)
    computedDataUnit(temp,2)
    let res = await ssdStep1GetSku(temp)
    Object.assign(temp, res.result)
}

const skuDetailRef = ref()
const openSkuDetail = (data)=>{
    skuDetailRef.value.open(data)
}
const USDToCNYRate = ref(0)
const getRate =  ()=>{
    getUSDtoCnyRate().then(res=>{
        USDToCNYRate.value = res.result
        form.value.rate = res.result
    })

}

//确认报价
const okPrice = async (data) => {
    data.forEach(item=>{
        let param: MakeOrderSkuDetailVO = {
            randomId:  generateRandomId(22),
            ssdSkuId: 0,
            ssdSkuCode: '',
            connectorType: '',
            coreChipType: '',
            productLevel: '',
            productSize: '',
            flashChipType: '',
            connectorProtocol: '',
            capacity: '',
            flashChipCount: 0,
            flashChipPrice: 0,
            additionalSurcharges: 0,
            coreChipPrice: 0,
            openPhysicalDestroy: 0,
            physicalDestroyPrice: 0,
            openLogicDestroy: 0,
            logicDestroyPrice: 0,
            openAesEncrypt: 0,
            aesEncryptPrice: 0,
            openRapidBackup: 0,
            rapidBackupPrice: 0,
            productCount: 1,
            materialPricing: 0,
            processingPricing: 0,
            rate: 0,
            ssdCoreShipId: 0,
            ssdFlashShipId: 0,
            estimateDay: 0,
            datasheetName: '',
            datasheetUrl: '',
            skuPrice: 0,
            skuunitPrice: 0,
            forceOpenPhysicalDestroy: false,
            forceOpenLogicDestroy: false,
            forceOpenAesEncrypt: false,
            forceOpenRapidBackup: false,
            forceOpenPhysicalDestroyTemp: false,
            forceOpenLogicDestroyTemp: false,
            forceOpenAesEncryptTemp: false,
            forceOpenRapidBackupTemp: false,
            repeatData: false,
            unitPriceCNY: 0,
            unitPriceUSD: 0,
            skuPriceUSD: 0,
            USDToCNYRate: 0,
            languageType: 1,
            skuPriceCNYWithNoRate: 0,
            unitPriceCNYWithNoRate: 0,
            skuPriceCNY: 0,
            skuPriceCNYActual: 0,
            skuPriceCNYWithNoRateActual: 0,
            skuPriceUSDActual: 0,
            unitPriceCNYActual: 0,
            unitPriceCNYWithNoRateActual: 0,
            unitPriceUSDActual: 0,
        };

        Object.assign(param, item)

        param.productCount = 1
        form.value.ssdSkuDetailVOList.push(param)
    })
    let param: SsdSkuDetailVOList = {
        ssdSkuDetailVOList:  form.value.ssdSkuDetailVOList
    }
    let res = await ssdStep1GetSkuList(param)
    res.result.forEach(item=>{
        form.value.ssdSkuDetailVOList.forEach(jtem=>{
            if (item.randomId == jtem.randomId && jtem.ssdSkuCode != '外部产品') {
                Object.assign(jtem, item)
            }
        })
    })
}

const getName = (url) =>{
    return url ? url.substring(url.lastIndexOf('/')) : '' ;
}
const reset=()=>{
    form.value = {...initFormData}
    form.value.ssdSkuDetailVOList = []
    submitLoading.value = false
    checkDialog.value = false
}

const delPriceSkuData = (item) =>{
    form.value.ssdSkuDetailVOList = form.value.ssdSkuDetailVOList.filter(i=>i.randomId != item.randomId)
}
const generateRandomId = (length)=> {
    var result = '';
    var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var charactersLength = characters.length;
    for (var i = 0; i < length; i++) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return result;
}

const getSureSku=(data)=>{
    console.log(data)
    data.forEach(item=>{
        item.randomId = generateRandomId(22)
    })
    skuData.value.push(...data)
}
const productPriceRef = ref()
const addProduct = ()=>{

    productPriceRef.value.open()
}

const download = (url)=>{
    downloadPlugins.oss(url)
}
const getCheckedNodes = ()=>{

}
//产品数量
const countNum = computed(()=>{
    let count:number = 0
    form.value.ssdSkuDetailVOList.forEach((item)=>{
        if(item.ssdSkuCode != '其他费用') {
            count += item.productCount
        }
    })
    return count
})//产品数量


//产品总金额不含税
const totalMoney = computed(()=>{
    let count: number = 0

    form.value.ssdSkuDetailVOList.forEach((item) => {
        if(item.ssdSkuCode != '其他费用') {
            if(form.value.quotationType == 2) {
                count += item.skuPriceCNYWithNoRateActual ? Number(item.skuPriceCNYWithNoRateActual) : 0
            } else {
                count += item.skuPriceCNYActual ? Number(item.skuPriceCNYActual) : 0
            }

        }
    })
    return count.toFixed(2)
})
//产品总金额不含税
const otherTotalMoney = computed(()=>{
    let count: number = 0
    form.value.ssdSkuDetailVOList.forEach((item) => {
        if(item.ssdSkuCode == '其他费用') {
            if(form.value.quotationType == 2) {
                count += item.skuPriceCNYWithNoRateActual ? Number(item.skuPriceCNYWithNoRateActual) : 0
            } else {
                count += item.skuPriceCNYActual ? Number(item.skuPriceCNYActual) : 0
            }
            // count += item.skuPriceCNYWithNoRateActual ? Number(item.skuPriceCNYWithNoRateActual) : 0
        }
    })
    return count.toFixed(2)
})

//产品总金额含税
const totalMoneyNoRate = computed(()=>{
    let count: number = 0
    form.value.ssdSkuDetailVOList.forEach((item) => {
        if(item.ssdSkuCode != '其他费用') {
            count += item.skuPriceCNYWithNoRateActual ? Number(item.skuPriceCNYWithNoRate) : 0
        }
    })
    return count.toFixed(2)
})


const open = async (businessId, customerId) => {
    reset()
    isEdite.value = false
    form.value.businessId = businessId
    form.value.customerId = customerId
    checkDialog.value = true
}
const getQuotationList = async () =>{

}

const edite = async (param, callBack)=>{
    reset()
    isEdite.value = true
    let data = await getDetail(param);
    form.value = data.result
    form.value.ssdSkuDetailVOList.forEach(item=>{
        item.randomId = generateRandomId(22)
        // item.forceOpenPhysicalDestroyTemp = item.forceOpenPhysicalDestroy
        // item.forceOpenLogicDestroyTemp = item.forceOpenLogicDestroy
        // item.forceOpenAesEncryptTemp = item.forceOpenAesEncrypt
        // item.forceOpenRapidBackupTemp = item.forceOpenRapidBackup
    })

    checkDialog.value = true
    if(callBack && typeof callBack === 'function') {
        callBack(true)
    }

}


defineExpose({
    open,
    edite
})
const selectedSkuVo = ref<SkuVo>()
const handleSelectionChange=(selection)=>{
    selectedSkuVo.value = selection
}

onMounted(()=>{
    getRate()
})
</script>

<style lang="scss" scoped>
    .dialog-header{
        display: flex;
        justify-content: center;
        align-items: center;

    }
</style>
