<style>
  .Sysuser_Date .el-input__inner {
    background-color: transparent;
    width: 100%;
    border: none;
  }
  .Sysuser_Date .el-range-input{
    background-color: transparent;
  }
</style>
<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @input="resetSearch" dense clearable filled v-model="msg.StuName" label="昵称" maxlength="20" />
        </div>
        <div class="col-3">
          <q-input @input="resetSearch" dense clearable filled v-model="msg.StuTel" label="电话" maxlength="20" />
        </div>
        <div class="col-3">
          <q-input @input="resetSearch" dense clearable filled v-model="msg.QQ" label="QQ" maxlength="20" />
        </div>
        <div class="col-3">
          <q-input @input="resetSearch" dense clearable filled v-model="msg.WechatNo" label="微信号" maxlength="20" />
        </div>
        <div class="col-3">
          <q-select @input="resetSearch" dense filled v-model="msg.StuType" :options="customTypeList" option-label="Name"
            option-value="Id" emit-value map-options label="客户类型" clearable />
        </div>
        <div class="col-3">
          <q-select @input="resetSearch" dense filled v-model="msg.CreateBy" @filter="filterEmployee" use-input
            :options="myEmployeeList" option-label="EmployeeName" option-value="Id" emit-value map-options label="负责人"
            clearable />
        </div>
        <div class="col-3">
          <q-select @input="resetSearch" dense filled v-model="msg.StuStage" :options="customState" option-label="Name"
            option-value="Id" emit-value map-options label="客户状态" clearable />
        </div>
        <div class="col-3 Sysuser_Date">
          <q-field filled dense>
             <template v-slot:control>
              <el-date-picker v-model="dateArray" size="mini" @change="resetSearch" value-format="yyyy-MM-dd" type="daterange" style="border:none;"
                 range-separator="至"  start-placeholder="开始时间"  end-placeholder="结束时间" />    
            </template>
          </q-field>
        </div>
      </div>
    </div>
    <div class="page-content">
      <stulist :dataList="data" @success="refreshPage" :loading="loading" ref="stuList" :authObj="AuthObj" :queryMsg="msg">
      </stulist>
      <div class="row" style="justify-content: flex-end;padding: 5px 20px">
        <q-pagination v-model="msg.pageIndex" :max="pageCount" @input="changePage" class="full-width justify-end"
          color="primary" :input="true">
        </q-pagination>
      </div>
    </div>
  </div>
</template>
<script>
  import {
    getStudentPage,
    getSchoolDropdown,
    deleteStudent,
    createStudentAccount,
    queryStuStageList,
    GetStudentTypeList
  } from '../../api/school/index'

  import {
    queryEmployee
  } from '../../api/users/user'
  import {
    resetPassword
  } from '../../api/users/user.js'
  import stulist from '../../components/school/student/stulist'
  import { mapGetters } from "vuex";

  export default {
    meta: {
      title: "客户管理"
    },
    components: {
      stulist
    },
    data() {
      return {
        currentUrl: "",
        data: [],
        loading: true,
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          StuName: "", //昵称
          StuTel: "", //电话
          CreateBy: "", //负责人
          StuStage: "", //客户阶段
          StartTime: "", //开始时间
          EndTime: "", //结束时间
          QQ:'',
          WechatNo:'',
          StuType:''
        },
        dateArray: [], //日期数组
        pageCount: 0,
        employeeList: [],
        myEmployeeList: [],
        //客户阶段状态列表
        customState: [],
        customTypeList: [], //客户类型
        AuthObj:{
          isShowDownload:true,
        }
      }
    },
    computed: {
      ...mapGetters(["userInfo"])
    },
    created() {
      this.getEmployeeList();
      this.getStuStageList();
      this.getCustomTypeList();
    },
    mounted() {
      this.currentUrl = this.$route.path
      this.getStudent()
    },
    methods: {
      //获取客户阶段列表
      getStuStageList() {
        queryStuStageList().then(res => {
          this.customState = res.Data;
        })
      },
      //获取客户类型
      getCustomTypeList(){
        GetStudentTypeList().then(res => {
          if (res.Code == 1) {
            this.customTypeList = res.Data;
          }
        })
      },
      //获取员工列表
      getEmployeeList() {
        queryEmployee({
          IsLeave: 1
        }).then(res => {
          this.employeeList = res.Data;
          this.myEmployeeList = res.Data;
        })
      },
      //筛选员工
      filterEmployee(val, update, abort) {
        update(() => {
          this.myEmployeeList = this.employeeList.filter(
            v => v.EmployeeName.indexOf(val) > -1
          );
        });
      },
      resetSearch() {
        this.msg.pageIndex = 1;
        if (this.schoolTemp) {
          this.msg.School_Id = this.schoolTemp.SId
        } else {
          this.msg.School_Id = 0
        }
        this.getStudent()
      },
      changePage(val) {
        this.msg.pageIndex = val;
        this.getStudent();
      },
      getStudent() {
        if (this.dateArray && this.dateArray.length > 0) {
          this.msg.StartTime = this.dateArray[0];
          this.msg.EndTime = this.dateArray[1];
        } else {
          this.msg.StartTime = '';
          this.msg.EndTime = '';
        }
        this.loading = true;
        getStudentPage(this.msg).then(res => {
          this.loading = false;
          this.data = res.Data.PageData
          this.pageCount = res.Data.PageCount
          this.data.forEach(x => {
            if (x.CreateBy != this.userInfo.Id) {
              x.BelongType = 3;
            } else {
              x.BelongType = 1;
            }
          });
        }).catch(() => {
          this.loading = false
        })
      },
      refreshPage() {
        this.getStudent()
      },
    },
  }
</script>
<style lang="sass">
  @import url('~assets/css/table.sass')
</style>