<template>
  <!-- 添加或修改菜单对话框 -->
  <el-dialog
    :title="客户导出"
    v-model="visible"
    width="680px"
    append-to-body
    draggable
  >
    <el-form ref="menuRef" :model="form" size="small" label-width="100px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="选择列" prop="name">
            <el-checkbox
              v-model="allChecked"
              @change="changeAll"
              :indeterminate="isIndeterminate"
              >全选</el-checkbox
            >
            <el-checkbox-group
              v-model="columns"
              ref="columnRef"
              @change="columnChange"
            >
              <el-checkbox
                v-for="column in defaultColumns"
                :key="column.field"
                :label="column.field"
                >{{ column.label }}</el-checkbox
              >
              <!-- <el-checkbox label="code">客户编号</el-checkbox>
              <el-checkbox label="name">客户名称</el-checkbox>
              <el-checkbox label="sourceCategoryName">客户来源类型</el-checkbox>
              <el-checkbox label="sourceName">客户来源</el-checkbox>
              <el-checkbox label="oldName">曾用名</el-checkbox>
              <el-checkbox label="taxType">纳税性质</el-checkbox>
              <el-checkbox label="socialCreditCode">税号</el-checkbox> -->
            </el-checkbox-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button
          type="primary"
          icon="Finished"
          size="small"
          @click="submitForm"
          >确 定</el-button
        >
        <el-button icon="Close" size="small" @click="cancel">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
  
  
<script setup>
import { getToken, getTenant } from "@/utils/auth";
import { addCompany } from "@/api/business/crm/company";
import useUserStore from "@/store/modules/user";
import { listSource } from "@/api/settings/source";
import { deepClone } from "@/utils";
import { incomeDefault, taxTypes, confirmDefault } from "@/utils/default";
const { proxy } = getCurrentInstance();
/** 父组件传参 */
const props = defineProps({
  getList: {
    type: Function,
    default: () => {},
  },
});
const { getList } = toRefs(props);
/** 字典数组区 */
const { develop_type } = proxy.useDict("develop_type");
/** 表单抽屉 页变量 */
const title = ref("");
const loading = ref(false);
const multiple = ref(true);
const visible = ref(false);
const editStatus = ref(false);
const isFullscreen = ref(false);
const addDetailNum = ref(1);
const currentMember = {};
const column = ref([]);

const defaultColumns = ref([
  {
    field: "name",
    label: "客户名称",
  },
  {
    field: "code",
    label: "客户编码",
  },
  {
    field: "sourceCategoryName",
    label: "客户来源类型",
  },
  {
    field: "sourceName",
    label: "客户来源",
  },
  {
    field: "area",
    label: "所属区域",
  },
  {
    field: "taxNo",
    label: "税号",
  },
  {
    field: "annualIncome",
    label: "年收入",
  },
  {
    field: "taxType",
    label: "纳税类型",
  },
  {
    field: "isZero",
    label: "是否零申报",
  },
  {
    field: "collectionMethod",
    label: "征收方式",
  },
  {
    field: "quotaAmount",
    label: "定额金额",
  },
]);

const sourceCategories = ref([]);

const allChecked = ref(false);
const isIndeterminate = ref(true);

const addType = ref(1);

const webHost = import.meta.env.VITE_APP_BASE_API;

const setHeaders = {
  Authorization: getToken(),
};
const data = reactive({
  columns: [],
});

/*** 客户导入参数 */
const upload = reactive({
  // 是否禁用上传
  isUploading: false,
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken(), tenantId: getTenant() },
  // 上传的地址
  url: "/ezhizao-yzbh-crm/business/company/importData",
});

const contactorEmptyData = {
  id: null,
  name: "",
  position: "",
  gender: "男",
  phone: "",
  email: "",
  isMain: "是",
  remark: "",
};

const companyEmptyData = {};

const followQuery = ref({});
const { columns } = toRefs(data);
const conditions = ref({});

/***********************  表单页方法 ****************************/

/** 抽屉打开 */
function open(options) {
  reset();
  conditions.value = options;
  visible.value = true;
}

function init() {}

function reset() {
  columns.values = [];
  allChecked.value = false;
  isIndeterminate.value = false;
}

function cancel() {
  visible.value = false;
  reset();
}

function submitForm() {
  conditions.value.columns = columns.value;
  console.log(conditions.value);
  proxy.download(
    "business/company/export",
    conditions.value,
    `客户管理_${new Date().getTime()}.xlsx`
  );
  cancel();
}

function changeAll(arg) {
  if (arg) {
    columns.value = defaultColumns.value.map((l) => l.field);
  } else {
    columns.value = [];
  }
}

function columnChange(value) {
  const checkedCount = value.length;
  allChecked.value = checkedCount === defaultColumns.value.length;
  isIndeterminate.value =
    checkedCount > 0 && checkedCount < defaultColumns.value.length;
  console.log(columns.value);
}

// 暴露给父组件的方法
defineExpose({
  open,
  close,
});
init();
</script>
  
<style></style>