<template>
  <div class="content">
    <div>
      <byTable
        :source="sourceList.data"
        :pagination="sourceList.pagination"
        :config="config"
        :loading="loading"
        highlight-current-row
        :selectConfig="[]"
        :table-events="{}"
        :action-list="[]"
        @get-list="getData"
        :hideSearch="true"
      >
        <template #code="{ item }">
          <div>
            <span
              style="cursor: pointer; color: #409eff"
              @click="clickPrint(item)"
              >{{ item.code }}</span
            >
          </div>
        </template>
        <template #money="{ item }">
          <div>
            <span>{{ moneyFormat(item.amount, 2) }}</span>
          </div>
        </template>
        <template #advanceCharge="{ item }">
          <div>
            {{ item.currency
            }}{{ moneyFormat(item.advanceCharge, 2) }}（预付款比列：{{
              item.advanceRatio
            }}%）
          </div>
        </template>
        <template #buyContactName="{ item }">
          <div>
            客户联系人：<span style="cursor: pointer; color: #409eff">{{
              item.buyContactName
            }}</span>
          </div>
        </template>
      </byTable>
    </div>

    <el-dialog title="打印" v-if="openPrint" v-model="openPrint" width="920">
      <ContractPDFOne :rowData="rowData"></ContractPDFOne>
      <template #footer>
        <el-button @click="openPrint = false" size="large">取消</el-button>
        <el-button type="primary" v-print="printObj" size="large"
          >打印</el-button
        >
        <el-button type="primary" @click="clickDownload()" size="large"
          >下载PDF</el-button
        >
      </template>
    </el-dialog>
  </div>
</template>
  
<script setup>
import byTable from "@/components/byTable/index";
import ContractPDFOne from "@/components/PDF/contractPDFOne.vue";

const props = defineProps({
  customerId: {
    type: String,
  },
});
const loading = ref(false);
const sourceList = ref({
  data: [],
  pagination: {
    total: 3,
    pageNum: 1,
    pageSize: 10,
  },
});
const { proxy } = getCurrentInstance();
const selectConfig = reactive([]);
const config = computed(() => {
  return [
    {
      attrs: {
        label: "时间",
        prop: "createTime",
      },
    },
    {
      attrs: {
        label: "合同编码",
        slot: "code",
      },
    },
    {
      attrs: {
        label: "合同金额",
        slot: "money",
      },
    },
    {
      attrs: {
        label: "业务员",
        prop: "userName",
      },
    },
    {
      attrs: {
        label: "预付款",
        prop: "advanceCharge",
        slot: "advanceCharge",
      },
    },
    {
      attrs: {
        label: "客户",
        prop: "buyContactName",
        slot: "buyContactName",
      },
    },
  ];
});
const getData = (req = {}) => {
  loading.value = true;
  sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  proxy
    .post("/saleQuotation/saleDetail", {
      id: props.customerId,
      ...sourceList.value.pagination,
      ...req,
    })
    .then((res) => {
      sourceList.value.data = res.rows;
      sourceList.value.pagination.total = res.total;
      setTimeout(() => {
        loading.value = false;
      }, 200);
    });
};
onMounted(() => {
  if (props.customerId) {
    getData();
  }
});

const openPrint = ref(false);
const rowData = ref({});
const clickPrint = (row) => {
  rowData.value = {
    id: row.id,
  };
  openPrint.value = true;
};
const printObj = ref({
  id: "pdfDom",
  popTitle: "",
  extraCss:
    "https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css, https://cdn.bootcdn.net/ajax/libs/hover.css/2.3.1/css/hover-min.css",
  extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',
});
const clickDownload = () => {
  proxy.getPdf("外销合同PDF文件");
};
</script>
  
<style lang="scss" scoped>
.content {
  padding: 10px;
}
</style>