import { ref,computed } from "vue";
import { auditorOrderSettlement } from "@/api/finance/settlement.js";
//功能
export default ({proxy,jlzj_area_type}) => {
    const router = useRouter();
     const dialogFormRef = ref(null);
     const userTableRef = ref(null);
     const { 
        lrr_service_status,
        settlement_application_auditor_status
     } = proxy.useDict("lrr_service_status","settlement_application_auditor_status");

     const tabList =computed(() => {
        let data = []
        data = settlement_application_auditor_status.value.map(item => {
            return {
                title: item.label,
                name: item.value
            }
        })
        return data || [];
    })
     //打开弹窗
     const openDialog = (ids) => {
        console.log('ids', ids);
        try {
            const disabledData = {
                // payeeMethod: true,
                // payeeAccount: true,
                // payeeBankName: true,
                // payeeName: true,
                // payeeRemark: true
            }
            dialogFormRef.value.initForm({mainOrderIds:ids}, disabledData)
        } catch (error) {
            console.log('error', error);
        } finally {
            console.log('dialogFormRef.value', dialogFormRef.value);
            dialogFormRef.value.handleDialog(true);
        }
    }
    //导出
    const exportFile = async(parmas) => { 
        console.log("TCL: exportFile -> parmas", parmas)
        // try {
        //     proxy.download("core/orderSettlementApplication/export",{
        //         ...queryParams.value,
        //     }, `订单费用结算_${new Date().getTime()}.xlsx`);
        // } catch (error) { 
        // }
    }

    //申请提交
    const submitForm = async (data) => {

        try {
            console.log('submit', data);
            const parmas = {
                ids: data.mainOrderIds,
                auditorStatus:  data.auditorStatus,
                auditorRemark: data.auditorRemark
            }
            const res = await auditorOrderSettlement(parmas);
               if (up_res.code === 200) {
                    proxy.$modal.msgSuccess("审核成功");
                    return;
                }
                proxy.$modal.msgSuccess(res.msg);
        } catch (error) {
            console.log('error', error);
        } finally {
            userTableRef.value.resetForm();
            dialogFormRef.value.handleDialog(false);
        }
    }


    
    return {
        dialogFormRef,
        userTableRef,
        tabList,
        openDialog,
        exportFile,
        submitForm,
        tableColumn:ref([
            {
                label: jlzj_area_type.value === '0'?'区域中心':'服务中心',
                prop: 'applicantType',
                type: 'input',
                isSearch: true
            },
            {
                label: '申请人',
                prop: 'createBy',
            },
            {
                label: '申请时间',
                prop: 'createTime',
            },
            {
                label: '订单号',
                prop: 'orderId',
            },
            {
                label: '订单开始时间',
                prop: 'createTime',
            },
            {
                label: '订单完成时间',
                prop: 'updateTime',
            },
            {
                label: '用户名称',
                prop: 'createBy',
            },
            {
                label: '志愿者名称',
                prop: 'updateBy',
        
            },
            {
                label: '服务项目',
                prop: '',
            },
            {
                label: '订单总金额（元）',
                prop: 'amount',
            },
            {
                label: '订单状态',
                prop: 'orderStatus',
                type: 'dict',
                dict: lrr_service_status
            },
            {
                label: '抽成金额',
                prop: 'amount',
            },
            {
                label: '结算状态',
                prop: 'auditorStatus',
            },
            {
                label: '审核状态',
                prop: 'auditorStatus',
            },
        ]),
        dialogData: {
            title: '结算申请',
            column: [
                {
                    label: '区域',
                    prop: 'payeeMethod',
                    type: 'select',
                    dictionary: 'settlement_application_payee_method',
                    rules: [
                        { required: true, message: '请选择收款方式', trigger: 'change' }
                    ],
                },
                {
                    label: '提交人',
                    prop: 'payeeAccount',
                    type: 'input',
                    rules: [
                        { required: true, message: '请输入收款账号', trigger: 'change' }
                    ],
        
                },
                {
                    label: '区域抽成',
                    prop: 'payeeBankName',
                    type: 'input',
                    rules: [
                        { required: true, message: '请输入收款银行名称', trigger: 'change' }
                    ],
        
                },
                {
                    label: '订单编号',
                    prop: 'payeeName',
                    type: 'input',
                    rules: [
                        { required: true, message: '请输入收款人', trigger: 'change' }
                    ],
                },
                {
                    label: '服务项目',
                    prop: 'payeeName',
                    type: 'input',
                    rules: [
                        { required: true, message: '请输入收款人', trigger: 'change' }
                    ],
                },
                {
                    label: '订单状态',
                    prop: 'payeeName',
                    type: 'input',
                    rules: [
                        { required: true, message: '请输入收款人', trigger: 'change' }
                    ],
                },
                {
                    label: '审核状态',
                    prop: 'auditorStatus',
                    type: 'radio',
                    rules: [
                        { required: true, message: '请选择审核状态', trigger: 'blur' }
                    ],
                    options: [
                        {
                            label: '通过',
                            value: '20'
                        },
                        {
                            label: '不通过',
                            value: '30'
                        }
                    ]
                },
                {
                    label: '驳回原因',
                    prop: 'auditorRemark',
                    type: 'textarea',
                    show:(form)=>{
                        console.log('驳回原因',form);
                        return form.auditorStatus === '30'
                    }
                },
            ]
        },
        searchBtns:[
            {
                label: '批量审核',
                func: () => {
                    const ids = userTableRef.value.ids;
                    console.log('批量删除', ids)
                    ids.length > 0 && openDialog(ids)
                },
                key: 'applicant',
                type: 'primary'
            },
            {
                label: '导出',
                func: (parmas) => {
                    exportFile(parmas);
                },
                key: 'export',
                type: 'primary'
            },
        ],
        scopeBtns:[
            {
                label: '审核',
                type: 'primary',
                key: 'examine',
                func: (row) => {
                    console.log(row)
                    openDialog([row.mainOrderId])
                },
                // show: (row) => {
                //     return jlzj_area_type.value === '20'
                // }
            },
            {
                label: '查看详情',
                type: 'primary',
                key: 'details',
                func: (row) => {
                    console.log(row)
                    router.push({
                        path: "/order-details",
                        query: { id: row.mainOrderId }
                    });
                }
            },
        ]
       
    }
}