import type {FormInstance} from 'element-plus'
import {GlobalStore} from '@/stores/index'
import {reactive} from "vue";

export interface LeaveUserInfoIn {
	T_user_name: string
	T_dept: string
	T_post: string
	CreateTime: string
	T_type_name: string
	T_start_time: string
	T_end_time: string
	T_text: string
	Id: string
	T_duration: number
}

export interface OvertimeUserInfoIn {
	T_uid: string
	T_user_name: string
	T_dept: string
	T_post: string
	T_type_name: string
	T_start_time: string
	T_end_time: string
	T_text: string
	Id: string
	T_duration: string
	T_prove_img: any
}

export interface ContractFormType {
	T_uuid: string
	T_number: string
	T_task_id: string
	T_product: any
	T_type: any
	T_money: string
	T_uuid_name: string
	T_discount?: string
	T_customer?: string
	T_start_date?: string
	T_end_date?: string
	T_stamping_date?: string
	T_payment_method?: string
	T_date: string
	T_project?: string
	T_remark: string
	T_pdf: string
	T_submit: string
	T_recoveries: string
	T_invoice: string
	T_submit_name?: string
	T_remit: any,
	T_approval_money: any
	T_approval_opinion: any
	T_State: any
}

export interface MyPercentageFormType {
	T_id: string
	T_device_type: string
	T_verify_type: string
	T_company_uuid: string
	T_verifyCompany_name: string
	T_money: any
	T_type: any
}

export interface MyPercentageFormTypeFrom {
	T_id: string
	// T_number: string
	T_type: any
	// T_item: any
	T_money: string
	T_task_id: string
	T_device_type: string
	T_uuid_name: string
	T_verify_type: string
	T_verifyCompany?: any
	T_uuid?: string
	T_submit?: string
	T_product?: any
	T_state?: any
	T_approval_money?: any
	T_approval_opinion?: any
}

export interface royaltyType {
	T_name: string
	T_num: number
	T_price: number
	T_priceNum: number
}

export interface PurchaseApproverInfoIn {
	T_date: string
	T_dept: string
	T_uuid_name: string
	T_State: number
	T_submit_name: string
	T_approver_name: string
	T_remark: string
	T_Detail: any
	T_product_name?: string
	T_product_quantity?: number
	T_total_price?: number
}

export const Project_State = [
	{id: 1, name: '待审核'},
	{id: 2, name: '进行中'},
	{id: 3, name: '已完成'}
]

export const Project_F_State = [
	{id: 3, name: '已完成'},
	{id: 4, name: '已发绩效'}
]
export const ReimburseFrom_F_State = [
	{T_State: 2, name: '待审核'},
	{T_State: 3, name: '审核通过'},
	{T_State: 4, name: '审核不通过'},
]
export const columns = [
	{type: 'index', label: '序号', width: 80, align: 'center '},
	{label: '产品图片', prop: 'T_img', align: 'center ', name: 'T_img'},
	{label: '产品名称', prop: 'T_name', align: 'center '},
	{label: '产品分类', prop: 'T_class_name', align: 'center '},
	{label: '产品型号', prop: 'T_model', align: 'center '},
	{label: '产品规格', prop: 'T_spec', align: 'center '},
	{label: '是否关联SN', prop: 'T_relation_sn', align: 'center ', width: 120, name: 'T_relation_sn'},
	{label: '*数量', prop: 'count', align: 'center ', name: 'count'},
	{label: '*已出库数量', prop: 'T_product_out', align: 'center ', name: 'T_product_out'},
	{prop: 'operation', label: '操作', width: 80, fixed: 'right'}
]
export const Mycolumns = [
	{type: 'index', label: '序号', width: 80, align: 'center '},
	{label: '项目', prop: 'T_name', align: 'center '},
	{label: '*数量', prop: 'T_num', align: 'center ', name: 'T_num', width: 120},
	{label: '单价', prop: 'T_price', align: 'center '},
	{label: '总价', prop: 'T_priceNum', align: 'center ', name: 'T_priceNum'},
	{prop: 'operation', label: '操作', width: 80, fixed: 'right'}
]
/**
 * 提成明细
 */
export const royalty = [
	{type: 'index', label: '序号', width: 80, align: 'center '},
	{label: '项目', prop: 'T_name', align: 'center ', name: 'T_name'},
	{label: '*数量', prop: 'T_num', align: 'center '},
	{label: '单价', prop: 'T_price', align: 'center '},
	{label: '总价', prop: 'T_priceNum', align: 'center ', name: 'T_priceNum'},
]

export const columnsRecoveries = [
	{type: 'index', label: '序号', width: 80, align: 'center '},
	{label: '回款时间', prop: 'T_date', align: 'center '},
	{label: '回款金额', prop: 'T_money', align: 'center '},
	{prop: 'operation', label: '操作', width: 150, fixed: 'right'}
]
export const labelsRecoveries = {
	date: '回款时间',
	money: '回款金额'
}
export const columnsInvoice = [
	{type: 'index', label: '序号', width: 80, align: 'center '},
	{label: '开票时间', prop: 'T_date', align: 'center '},
	{label: '开票金额', prop: 'T_money', align: 'center '},
	{prop: 'operation', label: '操作', width: 150, fixed: 'right'}
]
//打款明细
export const columnsRemit = [
	{type: 'index', label: '序号', width: 80, align: 'center '},
	{label: '打款时间', prop: 'T_date', align: 'center '},
	{label: '打款金额', prop: 'T_money', align: 'center '},
	{prop: 'operation', label: '操作', width: 150, fixed: 'right'}
]
export const labelsInvoice = {
	date: '开票时间',
	money: '开票金额'
}
export const verifyFormColumns = [
	{type: 'index', label: '序号', width: 80, align: 'center '},
	{label: '产品图片', prop: 'T_img', align: 'center ', name: 'T_img'},
	{label: '产品名称', prop: 'T_name', align: 'center '},
	{label: '产品分类', prop: 'T_class_name', align: 'center '},
	{label: '产品型号', prop: 'T_model', align: 'center '},
	{label: '产品规格', prop: 'T_spec', align: 'center '},
	{label: '*数量', prop: 'count', align: 'center ', name: 'count', sortable: true},
	{label: '单价', prop: 'T_price', name: 'T_price', align: 'center ', sortable: true},
	{label: '总价', prop: 'T_total', align: 'center ', sortable: true},
	{prop: 'operation', label: '操作', width: 80, fixed: 'right'}
]

export const options = [
	{name: '已通过', id: 1},
	{name: '未通过', id: 2},
	{name: '待审核', id: 3}
]
export const options1 = [
	{name: '待审核', id: 1},
	{name: '审核通过', id: 2},
	{name: '审核不通过', id: 3},
	{name: '已部分打款', id: 4},
	{name: '已全部打款', id: 5}
]
export const options2 = [
	{name: '待审核', id: 1},
	{name: '审核通过', id: 2},
	{name: '审核不通过', id: 3},
	// { name: '已部分打款', id: 4 },
	{name: '已打款', id: 5},
	{name: '未提交审核', id: 6}
]
export const options3 = [
	{name: '验证实施', id: 1},
	{name: '报告编写', id: 2},
]
export const options4 = [
	{name: '未回款', id: 1},
	{name: '已回款', id: 2},
]
export const deptOptions = [
	{name: '研发部', id: '研发部'},
	{name: '生产部', id: '生产部'},
	{name: '报告部', id: '报告部'},
	{name: '实施部', id: '实施部'},
	{name: '财务人事部', id: '财务人事部'},
	{name: '销售部', id: '销售部'},
]


export const paymentMethodOptions = [
	{name: '先款后货', id: 'A'},
	{name: '收部分定金50%', id: 'B'},
	{name: '先货后款', id: 'C'},
	{name: '项目支持', id: 'D'},
]

export function useStapublicFun(data: any) {
	const a = options2.find((item: any) => item.id == data)
	return a?.name

}

export function useTablePublic() {
	const globalStore = GlobalStore()
	const validate_T_product = (rule: any, value: any, callback: any) => {
		if (value === '') {
			callback(new Error('请选择产品明细'))
		} else if (value.includes(undefined)) {
			callback(new Error('请填写产品数量'))
		} else {
			callback()
		}
	}

	//判断是否相等，相同时改变背景颜色
	const tableRowClassName = (T_uuid: string, T_uuid2: string): any => {
		let user: any = undefined
		if (T_uuid === T_uuid2) {
			user = T_uuid2
		}
		if (user !== undefined) {
			let rowBackground = {
				background: '#e3eefd',
				color: '#0d7bff'
			}
			return rowBackground
		} else {
			return ''
		}
	}
	const resetForm = (formEl: FormInstance | undefined) => {
		if (!formEl) return
		formEl.resetFields()
	}

	const searchOnTableList = (TableRef: any) => TableRef?.searchTable()
	const updateOnTableList = (TableRef: any) => TableRef?.getTableList()

	return {
		validate_T_product,
		resetForm,
		globalStore,
		tableRowClassName,
		searchOnTableList,
		updateOnTableList
	}
}
