<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="120px">
            <el-form-item label="供应商名称" prop="name1">
              <el-input v-model="queryParams.name1" clearable placeholder="请输入企业名称" />
            </el-form-item>
            <el-form-item label="统一社会信用代码" prop="ztyxydm">
              <el-input v-model="queryParams.ztyxydm" clearable placeholder="请输入统一社会信用代码" />
            </el-form-item>

          </el-form>
          <el-row>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              <el-button v-hasPermi="['bfs:supplierInfo:export']" icon="Download" type="success" @click="handleExport">导出</el-button>
              <el-button v-hasPermi="['bfs:supplierInfo:increase']" icon="RefreshRight" type="success" @click="handleSapIncrease"
                >从SAP获取增量</el-button
              >
            </el-form-item>
          </el-row>
        </el-card>
      </div>
    </transition>
    <el-card shadow="never">
      <el-table v-loading="loading" :data="supplierInfoList">
        <el-table-column label="客户端" align="center" prop="mandt" />
        <el-table-column label="供应商" align="center" prop="lifnr" width="150px" />
        <el-table-column label="国家代码" align="center" prop="land1" />
        <el-table-column label="供应商名称" align="center" prop="name1" width="300px" />
<!--        <el-table-column label="名称4" align="center" prop="name4" width="150px" />-->
        <el-table-column label="记录创建日期" align="center" prop="erdat" width="150px">
          <template #default="scope">
            <span>{{ parseTime(scope.row.erdat, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="地区" align="center" prop="regio" />
        <el-table-column label="供应商帐户组" align="center" prop="ktokk" />
        <el-table-column label="地址" align="center" prop="adrnr" width="150px" />
        <el-table-column label="中心记帐冻结" align="center" prop="sperr" />
        <el-table-column label="集中删除标志" align="center" prop="loevm" />
        <el-table-column label="内外部" align="center" prop="kraus" />
<!--        <el-table-column label="工商登记号" align="center" prop="zgsdjh" width="200px" />-->
<!--        <el-table-column label="组织机构代码" align="center" prop="zzzjgdm" width="200px" />-->
        <el-table-column label="身份证" align="center" prop="zcard" width="200px" />
        <el-table-column label="统一社会信用代码" align="center" prop="ztyxydm" width="200px" />
      </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 {getSapAllData, getSapIncrease, getSupplierInfoList} from '@/api/bfs/busnessQury/costBalance';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const total = ref(0);
const showSearch = ref(true);
const loading = ref(false);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name1: undefined,
    zgsdjh: undefined,
    zzzjgdm: undefined,
    ztyxydm: undefined
  },
  rules: {
    policyOrgCode: [{ required: true, message: '保单管理机构不能为空', trigger: 'blur' }],
    dateRange: [{ required: true, message: '交易日期不能为空', trigger: 'blur' }]
  }
});
const { queryParams, rules } = toRefs(data);
const queryFormRef = ref<ElFormInstance>();
const supplierInfoList = ref([]);

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

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

const getList = async () => {
  loading.value = true;
  const res = await getSupplierInfoList(queryParams.value);
  supplierInfoList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'bfs/bussnessQury/exportSupplierInfo',
    {
      ...queryParams.value
    },
    `供应商明细_${new Date().getTime()}.xlsx`
  );
};

/** 获取全量 */
const handleSapAll = async () => {
  loading.value = true;
  try {
    const res = await getSapAllData();
    proxy.$modal.msgSuccess('查询成功');
    loading.value = false;
  } catch (e) {
    loading.value = false;
  }
};

/** 获取增量 */
const handleSapIncrease = async () => {
  loading.value = true;
  try {
    const res = await getSapIncrease();
    proxy.$modal.msgSuccess('查询成功');
    loading.value = false;
  } catch (e) {
    loading.value = false;
  }
};
</script>

<style scoped lang="scss"></style>
