<template>
  <div class="quote">
    <div class="quote-tree" style="border-radius: 8px">
      <div><h2>组织树</h2></div>
      <div>
        <!-- <a-tree  :tree-data="treeData" /> -->
        <tree @getList="chooseUser"></tree>
      </div>
    </div>
    <div class="back-line-main">
      <div class="back-line-header">
        <div class="back-line-header-title">
          <h2>合计</h2>
          <div>
            <dl>
              <dt><span>签单保费</span></dt>
              <dd>
                <span>{{ amount.sumPremium || 0 }}</span>
              </dd>
            </dl>
            <dl>
              <dt><span>签单保费总占比</span></dt>
              <dd>
                <span>{{
                  amount.sumPremiumProportion
                    ? (amount.sumPremiumProportion * 100).toFixed(2) + "%"
                    : 0
                }}</span>
              </dd>
            </dl>
            <dl>
              <dt><span>交强险保费</span></dt>
              <dd>
                <span>
                  {{ amount.jqpremium }}
                </span>
              </dd>
            </dl>
            <dl>
              <dt><span>车船税</span></dt>
              <dd>
                <span>
                  {{ amount.taxamount }}
                </span>
              </dd>
            </dl>
            <dl>
              <dt><span>商业险保费</span></dt>
              <dd>
                <span>
                  {{ amount.sypremium || 0 }}
                </span>
              </dd>
            </dl>
            <dl>
              <dt><span>非车险保费</span></dt>
              <dd>
                <span>
                  {{ amount.jypremium || 0 }}
                </span>
              </dd>
            </dl>
          </div>
        </div>
      </div>
      <div style="background-color: #fff; margin-top: 15px">
        <div class="table-title">
          <h2>电销</h2>
          <div>
            <span>时间筛选</span>
            <a-range-picker
              @change="onChangeTime"
              v-model="formState.time"
              value-format="YYYY-MM-DD"
              style="margin-left: 10px"
            >
              <a-icon slot="suffixIcon" type="calendar" />
            </a-range-picker>
            <a-radio-group
              default-value="0"
              button-style="solid"
              v-model="formState.dateType"
              @change="getVerification()"
              style="margin-left: 10px"
            >
              <a-radio-button
                value="1"
                @click="
                  (formState.time = []),
                    (formState.createtimeStart = ''),
                    (formState.createtimeEnd = '')
                "
              >
                当天
              </a-radio-button>
              <a-radio-button
                value="2"
                @click="
                  (formState.time = []),
                    (formState.createtimeStart = ''),
                    (formState.createtimeEnd = '')
                "
              >
                近7天
              </a-radio-button>
              <a-radio-button
                value="3"
                @click="
                  (formState.time = []),
                    (formState.createtimeStart = ''),
                    (formState.createtimeEnd = '')
                "
              >
                近30天
              </a-radio-button>
            </a-radio-group>
          </div>
        </div>
        <a-form
          layout="inline"
          :model="formState"
          style="padding: 15px; box-sizing: border-box"
        >
          <a-form-item label="姓名" :colon="false">
            <a-input
              placeholder="请输入姓名"
              v-model="formState.userName"
              allowClear
              style="width: 200px"
            ></a-input>
          </a-form-item>
          <a-form-item label="工号" :colon="false">
            <a-input
              placeholder="请输入工号"
              v-model="formState.userId"
              style="width: 200px"
              allowClear
            ></a-input>
          </a-form-item>
          <a-form-item
            style="
              flex: 1;
              display: flex;
              justify-content: flex-end;
              padding-right: 15px;
              box-sizing: border-box;
              align-items: flex-end;
            "
          >
            <a-button type="primary" @click="getList">查询</a-button>
          </a-form-item>
        </a-form>

        <standard-table
          bordered
          :columns="columns"
          :dataSource="tableList"
          :pagination="pagination"
          @clear="onClear"
          @change="onChange"
          :loading="loading"
        >
          <div slot="operation" slot-scope="{ text, record }">
            <a-button type="link" @click="watchMessage({ text, record })"
              >详情</a-button
            >
          </div>
        </standard-table>
      </div>
    </div>
  </div>
</template>
          
  <script>
import StandardTable from "@/components/table/StandardTable";
// import mixin from "../../minins/mixin";
import tree from "@/components/tree/userTree";
import moment from "moment";

const columns = [
  {
    title: "姓名",
    dataIndex: "userName",
  },

  {
    title: "工号",
    dataIndex: "userId",
    // scopedSlots: { customRender: "parterCompanyName" },
  },

  {
    title: "签单保费",
    dataIndex: "sumPremium",
  },
  {
    title: "交强险保费",
    dataIndex: "jqpremium",
  },
  {
    title: "车船税",
    dataIndex: "taxamount",
  },
  {
    title: "商业险保费",
    dataIndex: "sypremium",
  },
  {
    title: "非车险保费",
    dataIndex: "jypremium",
  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" },
  },
];

export default {
  components: {
    StandardTable,
    tree,
  },
  //   mixins: [mixin],
  data() {
    return {
      formState: {
        dateType: undefined,
        time: [moment().format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")],
        createtimeStart: moment().format("YYYY-MM-DD"),
        createtimeEnd: moment().format("YYYY-MM-DD"),
        userName: "",
        userId: "",
        treeUserId: "",
      },
      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: [],
      treeData: [
        { title: "Expand to load", key: "0" },
        { title: "Expand to load", key: "1" },
        { title: "Tree Node", key: "2", isLeaf: true },
      ],
      amount: {},
    };
  },
  mounted() {
    this.getVerification();
    // setTimeout(() => {
    // }, 1000);
  },
  methods: {
    chooseUser(val) {
      this.formState.treeUserId = val;
      this.getVerification();
    },
    getList() {
      this.pagination.current = 1;
      this.pagination.defaultPageSize = 10;
      this.getVerification();
    },
    onChangeTime(val) {
      this.formState.createtimeStart = val[0];
      this.formState.createtimeEnd = val[1];
      this.formState.dateType = undefined;
      this.pagination.current = 1;
      this.pagination.defaultPageSize = 10;
      this.getVerification();
    },
    watchMessage(item) {
      //
      item;
      this.$router.push({
        path: "/business/sales/message",
        query: {
          user: { ...item },
          time: {
            createtimeStart: this.formState.createtimeStart,
            createtimeEnd: this.formState.createtimeEnd,
          },
        },
      });
    },

    async getVerification() {
      this.loading = true;

      this.$API.business
        .getBusinessAgentList({
          pageNum: this.pagination.current,
          pageSize: this.pagination.defaultPageSize,
          ...this.formState,
          managementSource: 3,
        })
        .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,
            };
          }
        });
      this.$API.business
        .getBusinessAgentTotalList({
          ...this.formState,
          managementSource: 3,
        })
        .then((res) => {
          if (res.data.code === 200) {
            this.amount = { ...res.data.data };
          }
        });
    },
    onClear() {
      this.$message.info("您清空了勾选的所有行");
    },

    onChange(pagination) {
      // this.$message.info('表格状态改变了')

      this.pagination = {
        current: pagination.current,
        defaultPageSize: pagination.pageSize,
        total: pagination.total,
      };
      this.getVerification();
    },
  },
};
</script>
  <style lang='less' scoped>
.quote {
  display: flex;
  > div:first-child {
    width: 20%;
    background: #fff;
    margin-right: 15px;
  }
  .quote-tree {
    padding: 15px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    //
    > div:first-child {
      border-bottom: 1px solid #f0f0f0;
    }
    > div:last-child {
      flex: 1;
      overflow: auto;
      // padding-bottom: 100px;
      // box-sizing: border-box;
    }
  }
}
.back-line-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  .back-line-header {
    // padding: 15px;
    box-sizing: border-box;
    .back-line-header-title {
      padding: 15px;
      box-sizing: border-box;
      background: #ffffff;
      box-shadow: 0px 2px 8px 0px rgba(141, 149, 176, 0.15);
      border-radius: 8px 8px 8px 8px;
      border: 2px solid rgba(255, 255, 255, 0.2);
      h2 {
        margin: 0;
      }
      > div {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        > dl {
          flex: none;
          width: 180px;
          height: 80px;
          display: flex;
          //   align-items: center;
          justify-content: space-between;
          flex-direction: column;
          padding: 10px;
          box-sizing: border-box;

          border-radius: 4px 4px 4px 4px;

          > dd {
            display: flex;
            // align-items: center;
            justify-content: flex-end;
            margin: 0;
            font-family: PingFang SC, PingFang SC;
            font-weight: 500;
            font-size: 24px;
            // color: rgba(0, 0, 0, 0.85);
            // padding-left: 15px;
            box-sizing: border-box;
          }
        }
        > dl:first-child {
          background: url("../../assets/img/business1.png");
          color: #11a6d3;
        }
        > dl:nth-child(2) {
          background: url("../../assets/img/business2.png");
          color: #f87f2c;
        }
        > dl:nth-child(3) {
          background: url("../../assets/img/business3.png");
          color: #fab600;
        }
        > dl:nth-child(4) {
          background: url("../../assets/img/business4.png");
          color: #80be38;
        }
        > dl:nth-child(5) {
          background: url("../../assets/img/business5.png");
          color: #906cef;
        }
        > dl:nth-child(6) {
          background: url("../../assets/img/business6.png");
          color: #47a2eb;
        }
      }
      span {
        display: block;
        margin-right: 15px;
      }
      /deep/.ant-calendar-picker {
        width: 300px;
      }
    }
  }
  > div {
    // height: 152px;
    // background: #fff;
    .ant-form {
      display: flex;
      padding-top: 10px;
      box-sizing: border-box;
      > .ant-form-item {
        flex: none;
        /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;
      }
    }
  }
  .table-title {
    padding: 15px;
    border-bottom: 1px solid #eee;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    h2 {
      margin: 0;
    }
    > div {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.ant-form {
  display: flex;
  padding-top: 10px;
  box-sizing: border-box;
}
.ant-form-item {
  display: flex;
}
</style>