<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" v-loading="loading" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="80px">
            <el-form-item label="申请日期" prop="dateRange">
              <el-date-picker
                v-model="queryParams.dateRange"
                value-format="YYYY-MM-DD"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                clearable
              >
              </el-date-picker>
            </el-form-item>
            <el-row>
              <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-row>
          </el-form>
        </el-card>
      </div>
    </transition>
    <el-card shadow="hover">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <right-toolbar v-model:showSearch="showSearch" @query-table="getList"></right-toolbar>
        </el-row>
      </template>
      <el-table v-loading="loading" :data="invoicingList">
        <el-table-column label="红冲申请流水号" align="center" prop="invoicingId" width="200px" />
        <el-table-column label="红冲原因" align="center" prop="invoicingReason" width="120px">
          <template #default="scope">
            <dict-tag :options="bfs_invoicing_reason" :value="scope.row.invoicingReason" />
          </template>
        </el-table-column>
        <el-table-column label="红冲原因描述" align="center" prop="invoicingDetail" width="300px" />
        <el-table-column label="状态" align="center" prop="status" >
          <template #default="scope">
            <dict-tag :options="bfs_invoicing_status" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="红冲处理" placement="top">
              <el-button
                v-hasPermi="['bls:invoicing:deal']"
                link
                type="primary"
                icon="Edit"
                @click="handleDeal(scope.row)"
              >红冲处理</el-button
              >
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
    </el-card>

  </div>
</template>
<script setup lang="ts">

import { getInvoicingList } from '@/api/bfs/busnessQury/redInvoicing';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { bfs_invoicing_type } = toRefs<any>(proxy?.useDict('bfs_invoicing_type'));
const { bfs_invoicing_reason } = toRefs<any>(proxy?.useDict('bfs_invoicing_reason'));
const { bfs_invoicing_status } = toRefs<any>(proxy?.useDict('bfs_invoicing_status'));
const showSearch = ref(true);
const loading = ref(false);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    invoicingType: undefined,
    status: '2',
    dateRange: undefined
  },
  rules: {}
});

const { queryParams, rules } = toRefs(data);
const queryFormRef = ref<ElFormInstance>();
const invoicingList = ref([]);
const total = ref(0);

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  queryParams.value.pageNum = 1;
};

const getList = async () => {
  loading.value = true;
  const res = await getInvoicingList(proxy?.addDateRange(queryParams.value, queryParams.value.dateRange));
  invoicingList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

const handleDeal = (row: any) => {
  proxy.$router.push({
    path: '/bfs/Operation/invoicing/invoiceDeal',
    query: { invoicingId: row.invoicingId }
  });
};

onMounted(() => {
  getList();
});

</script>

<style scoped lang="scss">

</style>
