<template>
  <div class="back-line-main">
    <div class="back-line-header">
      <div class="back-line-header-title">
        <h2>费用校验</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>
      <div>选择投保险种：</div>

      <a-radio-group
        default-value="0"
        button-style="solid"
        v-model="formState.riskCode"
      >
        <a-radio-button value="all"> 全部 </a-radio-button>
        <a-radio-button value="单交"> 单交 </a-radio-button>
        <a-radio-button value="单商"> 单商 </a-radio-button>
        <a-radio-button value="单三"> 单三 </a-radio-button>
        <a-radio-button value="交三"> 交三 </a-radio-button>
        <a-radio-button value="交商"> 交商 </a-radio-button>
      </a-radio-group>
      <a-form layout="inline" :model="formState" class="users">
        <a-form-item label="保险公司" :labelCol="{ span: 8 }" :colon="false">
          <a-select
            placeholder="请选择"
            v-model="formState.companyId"
            allowClear
            show-search
            :filter-option="filterOption"
          >
            <a-select-option
              v-for="item in companyList"
              :key="item.id"
              :value="item.id"
            >
              {{ item.name }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="审核人员" :labelCol="{ span: 8 }" :colon="false">
          <a-input
            placeholder="请输入审核人员"
            v-model="formState.reviewer"
            allowClear
          ></a-input>
        </a-form-item>
        <a-form-item
          style="
            display: flex;
            justify-content: flex-end;
            padding-right: 15px;
            box-sizing: border-box;
            align-items: flex-end;
          "
        >
          <a-button @click="getList" type="primary">查询</a-button>
        </a-form-item>
      </a-form>
    </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>
      <div slot="operation" slot-scope="{ record }">
        <a-button type="link" @click="routerMessage(record)">详情</a-button>
      </div>
      <template slot="footer">
        <div>合计</div>
        <div>已审（条）:{{ totalObj.allAuditstatusOrders }}</div>
        <div>自动：{{ totalObj.allAutomaticAudit }}</div>
        <div>人工：{{ totalObj.allPersionAudit }}</div>
        <div>未审（条）：{{ totalObj.allAuditOrder }}</div>
      </template>
    </standard-table>
  </div>
</template>
    
    <script>
import StandardTable from "@/components/table/StandardTable";

// import mixin from "../../minins/mixin";
const columns = [
  {
    title: "保险公司",
    dataIndex: "insuranceCompanyName",
    // scopedSlots: { customRender: "qutationCount" },
  },

  {
    title: "已审（条）",
    dataIndex: "auditstatusOrders",
    scopedSlots: { customRender: "qutationCount" },
  },
  {
    title: "自动",
    dataIndex: "automaticAudit",
    scopedSlots: { customRender: "qutationCount" },
  },
  {
    title: "人工",
    dataIndex: "persionAudit",
    scopedSlots: { customRender: "qutationCount" },

    // sorter: true,
    needTotal: true,
  },
  {
    title: "未审（条）",
    dataIndex: "auditOrder",
    needTotal: true,
    scopedSlots: { customRender: "qutationCount" },
  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" },
  },
];
import moment from "moment";

export default {
  components: {
    StandardTable,
  },
  //   mixins: [mixin],
  data() {
    return {
      formState: {
        days: undefined,
        time: [moment().format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")],
        riskCode: "",
        endDate: moment().format("YYYY-MM-DD"),
        beginDate: moment().format("YYYY-MM-DD"),
        reviewer: undefined,
        companyId: undefined,
      },
      backLinePersonnel: {},
      columns: columns,

      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: [],
      totalObj: {},
      companyList: [],
    };
  },
  watch: {
    "formState.riskCode"() {
      this.getVerification();
    },
    "formState.days"() {
      this.getVerification();
    },
  },
  mounted() {
    this.getList();
    this.$API.financial.getCompany().then((res) => {
      console.log(res);
      if (res.data.code === 200) {
        this.companyList = [...res.data.data];
      }
    });
    // setTimeout(() => {
    // }, 1000);
  },
  methods: {
    routerMessage(text) {
      // console.log(text);
      this.$router.push({
        path: "/verification/message",
        query: {
          companyId: text.companyId,
          riskCode: this.formState.riskCode,
          beginDate: this.formState.beginDate,
          endDate: this.formState.endDate,
          reviewer: this.formState.reviewer,
        },
      });
      // /verification/message
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    getList() {
      //
      this.pagination.current = 1;
      this.pagination.defaultPageSize = 10;
      this.getVerification();
    },

    async getVerification() {
      this.loading = true;
      await this.$API.financial
        .getVerificationList({
          pageNum: this.pagination.current,
          pageSize: this.pagination.defaultPageSize,
          ...this.formState,
        })
        .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,
            };
          } else {
            this.loading = false;
            this.tableList = [];
          }
        });
      await this.$API.financial
        .getCostCenterTotal({
          pageNum: this.pagination.current,
          pageSize: this.pagination.defaultPageSize,
          ...this.formState,
        })
        .then((res) => {
          if (res.data.code === 200) {
            this.totalObj = { ...res.data.data };
          } else {
            this.totalObj = {};
          }
        });
    },
    onClear() {
      this.$message.info("您清空了勾选的所有行");
    },
    onChangeTime(val) {
      // console.log(val);
      this.formState.beginDate = val[0];
      this.formState.endDate = val[1];
      this.formState.days = undefined;
      this.getVerification();
    },
    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.getVerification();
    },
  },
};
</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: none;
        width: 300px;
        /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;
      }
    }
  }
}
/deep/.ant-table.ant-table-bordered .ant-table-footer {
  display: flex;
  > div {
    flex: 1;
  }
}
</style>