<template>
  <div class="back-line-main">
    <div class="back-line-header">
      <div class="back-line-header-title">
        <h2>
          <a-icon type="arrow-left" @click="$router.back()" />
          电销数据
        </h2>
        <div>
          <span>时间筛选</span>
          <a-range-picker
            @change="onChangeTime"
            v-model="formState.time"
            valueFormat="YYYY-MM-DD"
          >
            <a-icon slot="suffixIcon" type="calendar" />
          </a-range-picker>
          <a-radio-group
            default-value="0"
            button-style="solid"
            v-model="formState.days"
          >
            <a-radio-button
              value="1"
              @click="
                (formState.time = []),
                  (formState.beginDate = ''),
                  (formState.endDate = '')
              "
            >
              当天
            </a-radio-button>
            <a-radio-button
              value="7"
              @click="
                (formState.time = []),
                  (formState.beginDate = ''),
                  (formState.endDate = '')
              "
            >
              近7天
            </a-radio-button>
            <a-radio-button
              value="30"
              @click="
                (formState.time = []),
                  (formState.beginDate = ''),
                  (formState.endDate = '')
              "
            >
              近30天
            </a-radio-button>
          </a-radio-group>
        </div>
      </div>
      <fromRow
        :formState="formState"
        @getList="getList"
        :exportExcel="true"
        @exportList="exportList"
      ></fromRow>
    </div>
    <standard-table
      bordered
      :columns="columns"
      :dataSource="tableList"
      :pagination="pagination"
      @clear="onClear"
      @change="onChange"
      :loading="loading"
    >
      <div slot="qutationCount" slot-scope="{ text }">
        {{ text + "条" }}
      </div>
      <div slot="quotationRate" slot-scope="{ text }">
        {{ (text * 100).toFixed(2) + "%" }}
      </div>
      <span slot="title_slot">
        报价率
        <a-tooltip
          placement="topLeft"
          title="报价中 / 报价数"
          arrow-point-at-center
        >
          <a-icon type="question-circle" />
        </a-tooltip>
      </span>
      <span slot="title_slot2">
        承保率
        <a-tooltip
          placement="topLeft"
          title="承保数 / 报价数"
          arrow-point-at-center
        >
          <a-icon type="question-circle" />
        </a-tooltip>
      </span>
      <span slot="title_slot3">
        核保通过率
        <a-tooltip
          placement="topLeft"
          title="(承保数+ 核保数) / 报价数"
          arrow-point-at-center
        >
          <a-icon type="question-circle" />
        </a-tooltip>
      </span>
    </standard-table>
  </div>
</template>
    
    <script>
import StandardTable from "@/components/table/StandardTable";
import fromRow from "@/components/form/FormRow";
import mixin from "../../../minins/mixin";
const columns = [
  {
    title: "二级机构",
    dataIndex: "provinceName",
  },
  {
    title: "三级机构",
    dataIndex: "cityName",
  },
  {
    title: "四级机构",
    dataIndex: "districtName",
  },
  {
    title: "归属机构",
    dataIndex: "deptName",
  },
  {
    title: "业务员姓名",
    dataIndex: "userName",
  },
  {
    title: "业务员工号",
    dataIndex: "userId",
  },
  {
    title: "报价中",
    dataIndex: "qutationCount",
    scopedSlots: { customRender: "qutationCount" },
  },
  {
    title: "待审核",
    dataIndex: "auditOrder",
    scopedSlots: { customRender: "qutationCount" },
  },
  {
    title: "已核保待缴费",
    dataIndex: "underwritingCount",
    scopedSlots: { customRender: "qutationCount" },

    // sorter: true,
    needTotal: true,
  },
  {
    title: "已承保",
    dataIndex: "qutationInsureCount",
    needTotal: true,
    scopedSlots: { customRender: "qutationCount" },
  },
  {
    title: "核保退回",
    dataIndex: "underwritingReturn",
    scopedSlots: { customRender: "qutationCount" },
  },
  {
    // title: "报价率",
    dataIndex: "quotationRate",
    scopedSlots: { title: "title_slot", customRender: "quotationRate" },
  },
  {
    // title: "承保率",
    dataIndex: "closeRate",
    scopedSlots: { title: "title_slot2", customRender: "quotationRate" },
  },
  {
    // title: "核保通过率",
    dataIndex: "contributionRate",
    scopedSlots: { title: "title_slot3", customRender: "quotationRate" },
  },
];
import moment from "moment";
export default {
  components: {
    StandardTable,
    fromRow,
  },
  mixins: [mixin],
  data() {
    return {
      formState: {
        whole: undefined,
        cityId: undefined,
        countyId: undefined,
        houseId: undefined,
        provinceId: undefined,
        days: undefined,
        time: [moment().format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")],
        endDate: moment().format("YYYY-MM-DD"),
        beginDate: moment().format("YYYY-MM-DD"),
      },
      backLinePersonnel: {},
      columns: columns,
      companyList: [],
      tableList: [],
      pagination: {
        current: 1,
        defaultPageSize: 10,
        total: 0,
        pagesize0ptions: ["10", "20", "30", "50", "100"],
        hideOnSinglePage: false,
        showQuickJumper: true, //
        showSizeChanger: true, //是否可以改变pagesize
        showTotal: (total) => `共 ${total} 条数据`,
      },
      loading: false,
      wholeList: [],
      provinceList: [],
      cityList: [],
      areaList: [],
      storeList: [],
      process: process.env.VUE_APP_API_BASE_URL,
    };
  },
  watch: {
    "formState.days"() {
      this.getList();
    },
  },
  mounted() {
    this.formState.time = this.$route.query.time;
    this.formState.beginDate = this.$route.query.time[0];
    this.formState.endDate = this.$route.query.time[1];

    this.getList();
    // setTimeout(() => {

    // }, 1000);
  },
  methods: {
    handleFinish() {
      //
    },
    exportList() {
      delete this.formState.time;
      this.$API.task
        .exportChannelList({
          ...this.formState,
        })
        .then((res) => {
          if (res.data.code == 200) {
            let url = this.process + res.data.data; // 3.创建一个临时的url指向blob对象
            let a = document.createElement("a");
            a.href = url;
            a.download = "导出文件.xlsx";
            a.click();
            window.URL.revokeObjectURL(url);
          } else {
            this.$message.error(res.msg);
          }
        });
    },
    getList(val) {
      this.loading = true;
      this.$API.task
        .getTaskStatistics({
          pageNum: this.pagination.current,
          pageSize: this.pagination.defaultPageSize,
          ...this.formState,
          ...val,
          userId: this.$route.query.userId,
        })
        .then((res) => {
          if (res.data.code === 200) {
            this.loading = false;
            this.tableList = res.data.data.records;
            this.pagination = {
              current: res.data.data.current,
              defaultPageSize: res.data.data.size,
              total: res.data.data.total,
            };
          }
        });
    },
    onClear() {
      this.$message.info("您清空了勾选的所有行");
    },
    onChangeTime(val) {
      // console.log(val);
      this.formState.beginDate = val[0];
      this.formState.endDate = val[1];
      this.formState.days = undefined;
      this.getList();
    },

    onChange(pagination, filters, sorter, { currentDataSource }) {
      // this.$message.info('表格状态改变了')
      console.log(pagination, filters, sorter, { currentDataSource });
      this.pagination = {
        current: pagination.current,
        defaultPageSize: pagination.pageSize,
        total: pagination.total,
      };
      this.getList();
    },
  },
};
</script>
    <style lang='less' scoped>
.back-line-main {
  display: flex;
  flex-direction: column;
  .back-line-header {
    padding: 15px;
    box-sizing: border-box;
    .back-line-header-title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-bottom: 15px;
      border-bottom: 1px solid #f0f0f0;
      box-sizing: border-box;
      h2 {
        margin: 0;
      }
      > div {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: flex-end;
      }
      span {
        display: block;
        margin-right: 15px;
      }
      /deep/.ant-calendar-picker {
        width: 300px;
      }
    }
  }
  > div {
    // height: 152px;
    background: #fff;
    .ant-form {
      display: flex;
      > .ant-form-item {
        flex: 1;
        /deep/.ant-form-item-control-wrapper {
          width: 100%;
        }
      }
    }
    .form-item-search {
      // display: flex;
      // justify-content: flex-end;
      /deep/ .ant-form-item-control {
        display: flex;
        justify-content: flex-end;
      }
    }
  }
}
</style>