<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 @keyup.enter="resetSearch" @clear="resetSearch" dense clearable filled v-model="msg.StuName"
            label="昵称" maxlength="20" />
        </div>
        <div class="col-3">
          <q-input @keyup.enter="resetSearch" @clear="resetSearch" dense clearable filled v-model="msg.StuTel"
            label="电话" maxlength="20" />
        </div>
        <div class="col-3">
          <q-input @keyup.enter="resetSearch" @clear="resetSearch" dense clearable filled v-model="msg.QQ" label="QQ"
            maxlength="20" />
        </div>
        <div class="col-3">
          <q-input @keyup.enter="resetSearch" @clear="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 class="col-3">
          <q-field filled label="客户状态" dense stack-label>
            <template v-slot:control>
              <q-radio dense v-model="msg.QStudentStatus" @input="resetSearch" :val="1" label="有效" size="xs" />
              &nbsp;&nbsp;
              <q-radio dense v-model="msg.QStudentStatus" @input="resetSearch" :val="2" label="无效" size="xs" />
            </template>
          </q-field>
        </div>
        <div class="col-3">
          <q-select filled stack-label option-value="Id" @input="resetSearch" dense option-label="Name"
            v-model="msg.AdvisorStatus" ref="AdvisorStatus" :options="consultList" clearable label="当前状态" emit-value
            map-options />
        </div>
        <div class="col-3">
          <q-select filled stack-label option-value="Id" @input="resetSearch" dense option-label="Name"
            v-model="msg.StuChannel" :options="channelList" clearable label="渠道" emit-value map-options />
        </div>
        <div class="col-3">
          <q-select filled stack-label option-value="Id" @input="resetSearch" dense option-label="Name"
            v-model="msg.IsSureConsultTime" :options="visitList" clearable label="有效到访" emit-value map-options />
        </div>
        <div class="col-3">
          <q-select filled stack-label option-value="Id" @input="resetSearch" dense option-label="Name"
            v-model="msg.QOrderBy" :options="sortList" label="排序" emit-value map-options />
        </div>
      </div>
    </div>
    <div class="page-content">
      <stulist :dataList="data" @success="refreshPage" :StudentType="msg.StudentType"  :loading="loading" ref="stuList" :authObj="AuthObj"
        :queryMsg="msg" :Count="AuthObj.Count">
      </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 {
    GetStudentAdvisorConfigList
  } from "../../api/customerstudent/customerstudent";
  import {
    GetStuChannelList
  } from "../../api/sale/sale";
  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: '',
          QStudentStatus: 1, //客户状态 1有效 2无效
          AdvisorStatus: '', //当前状态
          StuChannel: "",
          CreateIds: [],
          CreateType: "", //来源类型
          StuSourceId: "", //来源人编号
          CategoryId: "", //同行编号
          IsSureConsultTime: 0, // 0不限 1有效到访 2无效到访
          QOrderBy: 0, //排序
          StudentType:2,
        },
        dateArray: [], //日期数组
        pageCount: 0,
        employeeList: [],
        myEmployeeList: [],
        //客户阶段状态列表
        customState: [],
        customTypeList: [], //客户类型
        AuthObj: {
          isShowDownload: true,
          Count: 0
        },
        consultList: [],
        visitList: [{
            Name: '不限',
            Id: 0
          },
          {
            Name: '只看有效到访',
            Id: 1
          },
          {
            Name: '只看无效到访',
            Id: 2
          },
        ],
        //排序
        sortList: [{
            Id: 0,
            Name: "默认"
          },
          {
            Id: 1,
            Name: "跟进时间倒序"
          },
          {
            Id: 2,
            Name: "跟进时间升序"
          },
        ],
        //渠道列表
        channelList: [],
      }
    },
    computed: {
      ...mapGetters(["userInfo"])
    },
    created() {
      this.getEmployeeList();
      this.getStuStageList();
      this.getCustomTypeList();
      this.queryChannelList();
    },
    mounted() {
      this.currentUrl = this.$route.path;
      if (this.$route.query.startTime) {
        this.dateArray.push(this.$route.query.startTime);
        this.msg.StartTime = this.$route.query.startTime;
      }
      if (this.$route.query.endTime) {
        this.dateArray.push(this.$route.query.endTime);
        this.msg.EndTime = this.$route.query.endTime;
      }
      if (this.$route.query.ChannelId) {
        this.msg.StuChannel = Number(this.$route.query.ChannelId);
      }
      if (this.$route.query.createBy) {
        this.msg.CreateBy = Number(this.$route.query.createBy);
      }
      if (this.$route.query.CreateType) {
        this.msg.CreateType = Number(this.$route.query.CreateType);
      }
      if (this.$route.query.StuSourceId) {
        this.msg.StuSourceId = Number(this.$route.query.StuSourceId);
      }
      if (this.$route.query.CategoryId) {
        this.msg.CategoryId = this.$route.query.CategoryId;
      }
      this.getStatusList();
      this.getStudent()
    },
    methods: {
      //获取渠道列表
      queryChannelList() {
        GetStuChannelList({}).then(res => {
          if (res.Code == 1) {
            this.channelList = res.Data;
          }
        })
      },
      //获取跟进状态下拉
      getStatusList() {
        let msg = {
          Name: ''
        }
        GetStudentAdvisorConfigList(msg).then(res => {
          if (res.Code == 1) {
            this.consultList = res.Data;
          }
        })
      },
      //获取客户阶段列表
      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.AuthObj.Count = res.Data.Count
          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>
