<template>
  <el-dialog :visible.sync="isNotRenewedDlg" :close-on-click-modal="false" :modal-append-to-body="false" @close="cancelHandle" center title="下载未续约率" width="35%">
    <div>
      <el-radio-group v-model="radio">
        <el-radio style="margin-bottom: 20px" :label="1">下载当前销售的合同明细数据</el-radio>
        <el-radio :label="2">下载所有销售未续约数据列表</el-radio>
      </el-radio-group>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancelHandle">取 消</el-button>
      <el-button type="primary" @click="downloadHandle">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { dataMainInterface } from "@/api/api.js";
export default {
  props: {
    isNotRenewedDlg: {
      type: Boolean,
      default: false,
    },
    start_date: {
      type: String,
      default: "",
    },
    end_date: {
      type: String,
      default: "",
    },
    adminId: {
      type: Array,
      default: [],
    },
  },
  watch: {},
  data() {
    return {
      radio: 1,
    };
  },
  methods: {
    // 关闭弹框
    cancelHandle() {
      this.$emit("update:isNotRenewedDlg", false);
    },
    // 下载
    downloadHandle() {
      let paramStr = "";

      let baseUrl = process.env.API_ROOT + "/statistic_report/merge_company/company_contract_percentage/list_export";
      let token = localStorage.getItem("auth") || "";
      let salesArr = [];
      if (this.adminId.length) {
        salesArr = this.adminId.map((item) => {
          return item[item.length - 1];
        });
      }
      let obj = {
        EndDate: this.end_date,
        StartDate: this.start_date,
        ExportType: this.radio,
        AdminId: salesArr.join(","),
      };
      for (let key in obj) {
        paramStr = `${paramStr}&${key}=${obj[key]}`;
      }
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = `${baseUrl}?${token}${paramStr}`;
      link.setAttribute("download", name);
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    },
  },
  created() {},
  mounted() {},
};
</script>
<style lang="scss"></style>
