<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
            v-model="formState.time"
            @change="timeChange"
            valueFormat="YYYY-MM-DD"
          >
            <a-icon slot="suffixIcon" type="calendar" />
          </a-range-picker>
          <a-radio-group
            default-value="1"
            button-style="solid"
            v-model="formState.days"
          >
            <a-radio-button
              :value="1"
              @click="
                (formState.time = []),
                  (formState.createtimeStart = ''),
                  (formState.createtimeEnd = '')
              "
            >
              当天
            </a-radio-button>
            <a-radio-button
              :value="7"
              @click="
                (formState.time = []),
                  (formState.createtimeStart = ''),
                  (formState.createtimeEnd = '')
              "
            >
              近7天
            </a-radio-button>
            <a-radio-button
              :value="30"
              @click="
                (formState.time = []),
                  (formState.createtimeStart = ''),
                  (formState.createtimeEnd = '')
              "
            >
              近30天
            </a-radio-button>
          </a-radio-group>
        </div>
      </div>
      <fromRow
        :formState="formState"
        :className="''"
        :search="false"
        @getList="getList"
      ></fromRow>
      <a-form layout="inline" :model="formState">
        <a-form-item label="姓名" :labelCol="{ span: 5 }" :colon="false">
          <a-input placeholder="请输入姓名" v-model="formState.name"></a-input>
        </a-form-item>
        <a-form-item label="工号" :labelCol="{ span: 5 }" :colon="false">
          <a-input
            placeholder="请输入工号"
            v-model="formState.userCode"
          ></a-input>
        </a-form-item>
        <a-form-item label="手机号" :labelCol="{ span: 5 }" :colon="false">
          <a-input
            placeholder="请输入手机号"
            v-model="formState.phoneNumber"
          ></a-input>
        </a-form-item>
        <a-form-item label="" :labelCol="{ span: 5 }" :colon="false">
        </a-form-item>
        <a-form-item
          label="             "
          :labelCol="{ span: 5 }"
          :colon="false"
          class="form-item-search"
        >
          <a-button type="primary" @click="getList">查询</a-button>
        </a-form-item>
      </a-form>
    </div>
    <div class="list">
      <a-spin :spinning="loading">
        <a-row class="personnel-message">
          <a-col v-for="(item, index) in list" :key="item.userId" :span="5">
            <div :class="Math.floor((index / 5) % 2) ? 'list-2' : 'list-1'">
              <p>姓名：{{ item.name }}</p>

              <p>
                <span>总人力：{{ item.totalManpower || 0 }}</span>
              </p>
              <p>
                <span>总保费：{{ item.totalPremium || 0 }}</span>
              </p>
              <div class="user-icon">
                <img
                  v-show="item.filePath"
                  :src="process + item.filePath"
                  alt=""
                />
                <img
                  v-if="!item.filePath && item.sex == 'M'"
                  src="../../../assets/img/man.png"
                  alt=""
                />
                <img
                  v-if="!item.filePath && item.sex == 'F'"
                  src="../../../assets/img/woman.png"
                  alt=""
                />
                <img
                  v-if="!item.filePath && !item.sex"
                  src="../../../assets/img/man.png"
                  alt=""
                />
              </div>

              <p>
                <a-button type="primary" @click="teamMessage(item)"
                  >详情</a-button
                >
              </p>
            </div>
          </a-col>
        </a-row>
        <div class="page">
          <a-pagination
            v-model="pageInfo.pageNum"
            :total="pageInfo.total"
            show-less-items
            show-size-changer
            show-quick-jumper
            :show-total="(total) => `共 ${total} 条数据`"
            @change="pageChange"
            @showSizeChange="pageChange"
            :page-size.sync="pageInfo.pageSize"
            :pageSizeOptions="['15', '30', '45', '60']"
          />
        </div>
      </a-spin>
    </div>
  </div>
</template>
      
<script>
import fromRow from "@/components/form/FormRow";
import moment from "moment";
export default {
  components: {
    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")],
        name: undefined,
        userCode: undefined,
        phoneNumber: undefined,
        createtimeEnd: moment().format("YYYY-MM-DD"),
        createtimeStart: moment().format("YYYY-MM-DD"),
      },
      backLinePersonnel: {},
      process: process.env.VUE_APP_API_BASE_URL,
      companyList: [],
      tableList: [],
      pageInfo: {
        pageNum: 1,
        pageSize: 15,
        total: 0,
      },
      list: [],
      loading: true,
    };
  },
  watch: {
    "formState.days"() {
      this.getList();
      // this.formState.time = [];
    },
  },
  mounted() {
    this.getList();
    // setTimeout(() => {
    // }, 1000);
  },
  methods: {
    handleFinish() {
      //
    },
    timeChange(val) {
      this.formState.createtimeStart = val[0];
      this.formState.createtimeEnd = val[1];
      this.formState.days = undefined;
      this.getList();
    },

    //获取成员列表
    getList() {
      this.loading = true;
      this.$API.personnel
        .getyQxFrontlineAgentList({
          pageNum: this.pageInfo.pageNum,
          pageSize: this.pageInfo.pageSize,
          ...this.formState,
          managementSource: 2,
        })
        .then((res) => {
          //   console.log(res);
          this.loading = false;

          if (res.data.code === 200) {
            this.list = res.data.data.records;
            this.pageInfo.total = res.data.data.total;
          }
        });
    },
    onClear() {
      this.$message.info("您清空了勾选的所有行");
    },

    //分页事件
    pageChange(page, pageSize) {
      //   console.log(page, pageSize);
      this.pageInfo.pageNum = page;
      this.pageInfo.pageSize = pageSize;
      this.getList();
    },
    teamMessage(item) {
      // item
      // console.log(this.$route)
      this.$router.push({
        path: "/personnelManage/front/resources/teammanage",
        query: {
          userId: item.userId,
          totalManpower: item.totalManpower,
          totalPremium: item.totalPremium,
          orderManpower: item.orderManpower,
          time: this.formState.time,
        },
      });
    },
  },
};
</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;
        // width: 20%;
        /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;
      }
    }
  }
}
.list {
  padding: 15px;
  box-sizing: border-box;
}
.personnel-message {
  // display: flex;
  // flex-wrap: wrap;
  // justify-content: space-between;
  > .ant-col {
    flex: none;
    width: 20%;
    margin-bottom: 15px;
    padding: 0 15px;
    box-sizing: border-box;
    > div {
      flex: 100%;

      background: #f9faff;
      border-radius: 8px;
      border: 1px solid #2a55e5;
      padding: 15px;
      box-sizing: border-box;
      // margin: 0 15px 15px 0;
      position: relative;
    }
    p {
      display: flex;
      justify-content: flex-end;
    }
    p:last-child {
      margin: 0;
      justify-content: flex-end;
      // text-align: right;
    }
    div.user-icon {
      width: 56px;
      height: 56px;
      position: absolute;
      top: 12px;
      left: 15px;
      border-radius: 50%;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .progress {
      width: 100%;
      height: 5px;
      background: #eee;
      border-radius: 8px;
      margin-bottom: 8px;
      > p {
        width: 67%;
        height: 100%;
        background: #2a55e5;
        border-radius: 8px;
      }
    }
    // margin-right: 2%;
  }
  div.list-1 {
    background: #fff8f6;
    box-shadow: 0px 2px 8px 0px rgba(255, 173, 76, 0.15);
    border-radius: 8px 8px 8px 8px;
    border: 1px solid rgba(248, 127, 44, 0.5);
    button {
      background: #f87f2c;
      color: #fff;
      border: none;
    }
  }
  div.list-2 {
    background: #f7fef4;
    box-shadow: 0px 2px 8px 0px rgba(135, 229, 42, 0.15);
    border-radius: 8px 8px 8px 8px;
    border: 1px solid rgba(128, 190, 56, 0.5);
    button {
      background: #80be38;
      color: #fff;
      border: none;
    }
  }
  div.list-3 {
    background: #f9faff;
    box-shadow: 0px 2px 8px 0px rgba(42, 85, 229, 0.15);
    border-radius: 8px 8px 8px 8px;
    border: 1px solid rgba(42, 85, 229, 0.5);
  }
}
.page {
  display: flex;
  justify-content: flex-end;
}
</style>