<template>
    <view>
        <uni-section
            :sub-title="queryParams.contractcode"
            :title="queryParams.user_name"
            padding="0 0 5px 10px"
            style="margin-bottom: 20px"
        />

        <MBCard style="margin: 15px">
            <view class="context">
                <view class="label">
                    <text>制单日期:</text>
                    <text>{{ queryParams.adddate }}</text>
                </view>
                <view class="label">
                    <text>支付方式:</text>
                    <text>{{ queryParams.ispaynow }}</text>
                </view>
                <view class="label">
                    <text>订单金额:</text>
                    <text>{{ formatPrice(queryParams.contractmoney) }}</text>
                </view>
                <view class="label">
                    <text>补差金额:</text>
                    <text>{{ formatPrice(queryParams.piaokou) }}</text>
                </view>
            </view>
        </MBCard>

        <uni-section class="mb-10" padding="0 0 5px 10px" title="商品信息"/>


        <uni-card
            v-for="item in queryParams.goods"
            :key="item.goodsname"
            :title="item.goodsname"
        >
            <view class="context">
                <view class="label">
                    <text>单价:</text>
                    <text>{{ formatPrice(item.invoiceprice) }}</text>
                </view>
                <view class="label">
                    <text>小计:</text>
                    <text>{{ formatPrice(item.allmoney) }}</text>
                </view>
                <view class="label">
                    <text>采购数量:</text>
                    <text>{{ item.goodsnum }}</text>
                </view>
                <view class="label">
                    <text>补差:</text>
                    <text>{{ formatPrice(item.piaokou) }}</text>
                </view>
                <view class="label">
                    <text>税率:</text>
                    <text>{{ item.piaokou }}</text>
                </view>
            </view>
        </uni-card>


        <view style="display: flex;margin: 0 15px;justify-content: space-between;">
            <uni-tag
                style="font-size: 20px;line-height: 28px;font-weight: bold;padding: 5px 25px;"
                text="回退"
                type="success"
                @click="handleCallBack"
            />
            <uni-tag
                style="font-size: 20px;line-height: 28px;font-weight: bold;padding: 5px 25px;"
                text="审核"
                type="primary"
                @click="handleSubmit"
            />
        </view>

    </view>
</template>

<script setup>
import {getCurrentInstance, onMounted, ref} from 'vue'
import {onLoad} from '@dcloudio/uni-app'
import {businessManagerReviewGoodsList, salemainDetailSWJL} from "../../../api/BusinessApproval";
import MBCard from "../../../components/MB/MBCard.vue";
import {formatPrice} from "../../../utils/utils";
import UniCard from "../../../uni_modules/uni-card/components/uni-card/uni-card.vue";
import UniTag from "../../../uni_modules/uni-tag/components/uni-tag/uni-tag.vue";
import {financeConfirm, financeConfirmRefuse} from "../../../api/Salemain";


const id = ref('')
const queryParams = ref({})

const {proxy} = getCurrentInstance()

onLoad((options) => {
    id.value = options.id
})


onMounted(async () => {
    const {data} = await salemainDetailSWJL({
        id: id.value,
        isThisMonth: 1
    })
    queryParams.value = data[0]

    const {data: goods} = await businessManagerReviewGoodsList(id.value)
    queryParams.value = {
        ...queryParams.value,
        goods: goods
    }
})

const handleCallBack = () => {
    financeConfirmRefuse(queryParams.value.saleIds)
        .then(() => {
            proxy.$modal.msgSuccess('回退成功！');
            proxy.$tab.navigateTo('/pages/work/FinancialApproval/index')
        })
}

const handleSubmit = () => {
    financeConfirm(queryParams.value.saleIds)
        .then(() => {
            proxy.$modal.msgSuccess('审批成功！');
            proxy.$tab.navigateTo('/pages/work/FinancialApproval/index')
        })
}
</script>