<template>
  <div class="directorGuideList">
    <div class="el-card__header">
      <span>导游管理</span>
      <div style="display: flex;flex-direction: row;align-items: center">
        <el-button type="primary" class="el-button--small" @click="addRecharge">新增</el-button>
        <el-button type="primary" @click="SetProduct(0)" style="margin-left:10px;" class="el-button--small">启用</el-button>
        <el-button type="primary" @click="SetProduct(1)" style="margin-left:10px;" class="el-button--small">冻结</el-button>
      </div>
    </div>
    <div class="content">
      <div style="display: flex;flex-direction: row;align-items: center">
        <div class="block" >
          <div class="searchInput" style="width:200px">
            <el-input style="display:inline-block;width:170px;height:30px"
                      placeholder="请输入导游名称"
                      v-model="msg.Name"
                      size="small"
                      @clear="getList"
                      @keyup.enter.native="getList"
                      clearable>
            </el-input>
            <span @click="getList" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
          </div>
          <div class="searchInput" style="width:200px">
            <el-input style="display:inline-block;width:170px;height:30px"
                      placeholder="请输入导游ID"
                      v-model="searchId"
                      size="small"
                      @clear="getList"
                      @keyup.enter.native="getList"
                      type="number"
                      :min="0"
                      clearable>
            </el-input>
            <span @click="getList" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
          </div>
          <span>状态：</span>
          <el-select class="w120" @change="msg.pageIndex=1,getList()" v-model="msg.IsEnable" size="small"
                     placeholder="请选择">
            <el-option v-for="item in IsEnableList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
          <span style="margin-left: 15px">注册时间：</span>
          <el-date-picker v-model="dateList" @change="msg.pageIndex=1,getList()" size="small" type="datetimerange" range-separator="至"
                          value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </div>

      </div>
    </div>
    <div class="content" style="margin-top: 0px">
      <div style="display: flex;flex-direction: row;align-items: center">
        <div class="block" >
          <span style="margin-left: 10px">工作年限：</span>
          <el-input style="display:inline-block;width:100px;height:30px" :min="0" placeholder="请输入" v-model="msg.StartWorkYears" size="small" type="number"></el-input>
          <span style="margin: 0 10px ;">~</span>
          <el-input style="display:inline-block;width:100px;height:30px" :min="0" placeholder="请输入" v-model="msg.EndWorkYears" size="small" type="number"></el-input>

          <span style="margin-left: 20px">评分：</span>
          <el-input style="display:inline-block;width:100px;height:30px" placeholder="请输入" v-model="msg.StartScore" size="small" type="number"></el-input>
          <span style="margin: 0 10px ;">~</span>
          <el-input style="display:inline-block;width:100px;height:30px" placeholder="请输入" v-model="msg.EndScore" size="small" type="number"></el-input>
          <el-button type="primary" @click="getList()" size="small" style="margin-left: 5px">查询</el-button>
        </div>
      </div>
    </div>



    <div style="padding: 20px;background: #fff;">
      <el-table
        :data="tableData"
        header-cell-class-name="headClass"
        style="width: 100%"
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" style="text-align:center;"></el-table-column>

        <el-table-column
          prop="ID"
          label="编号"
          width="100">
        </el-table-column>

        <el-table-column
          prop="Name"
          label="导游信息">
            <template slot-scope="scope">
              <div class="app-image" :style="{backgroundImage:'url(' + scope.row.GuidePhoto + ')',backgroundSize:'cover'}"></div>
              <div flex="dir:left cross:center">
                {{scope.row.Name}}
              </div>
            </template>
        </el-table-column>


        <el-table-column
          prop="WorkYears"
          label="工作年限"
          width="120">
        </el-table-column>
        <el-table-column
          prop="Score"
          label="评分"
          width="120">
        </el-table-column>
        <el-table-column
          prop="SiteName"
          label="站点名称">
        </el-table-column>
        <el-table-column
          prop="OrderNum"
          width="100"
          label="订单数">
        </el-table-column>
        <el-table-column
          prop="GoodsNum"
          width="100"
          label="商品数">
        </el-table-column>
        <el-table-column
          prop="CreateDateStr"
          width="170"
          label="注册时间">
        </el-table-column>
        <el-table-column
          prop="IsEnable"
          width="100"
          label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.IsEnable==0">正常</span>
            <span v-if="scope.row.IsEnable==1">冻结</span>
          </template>

        </el-table-column>

        <el-table-column
          prop="Telephone"
          label="联系电话">
        </el-table-column>
        <el-table-column
          prop="EmergencyPhone"
          label="紧急联系电话">
        </el-table-column>


        <el-table-column
          fixed="right"
          label="操作"
          width="180"
        >
          <template slot-scope="scope">

            <el-tooltip class="item" effect="dark" content="编辑" placement="top" >
              <img src="../../assets/img/setup/edit.png" alt="" class="imgstyle" @click="Edit(scope.row)">
            </el-tooltip>
<!--            <el-tooltip class="item" effect="dark" content="删除" placement="top" >-->
<!--              <img src="../../assets/img/setup/del.png" alt="" class="imgstyle" @click="delete_b(scope.row)">-->
<!--            </el-tooltip>-->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination style="text-align:right"
                     background
                     @current-change="handleCurrentChange"
                     :page-size="msg.pageSize"
                     layout="prev, pager, next"
                     :current-page.sync="msg.pageIndex"
                     :total="count">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    name: "directorGuideList",
    data(){
      return{
        msg:{
          pageIndex:1,
          pageSize:20,
          Name:'',
          ID:'',
          StartWorkYears:'',
          EndWorkYears:'',
          IsEnable:-1,
          StartTime:'',
          EndTime:'',
          StartScore:'',
          EndScore:'',
        },
        dateList:[],
        IsEnableList:[
          {id:-1,name:'不限'},
          {id:0,name:'正常'},
          {id:1,name:'冻结'},
        ],
        tableData:[],
        count:0,
        loading:false,
        EnableMsg:{
          Ids:'',
          IsEnable:0,
        },
        searchId:'', //输入框ID
      }
    },
    created(){
      this.getDateList();

    },
    methods:{
      getDateList(){
        this.loading=true;
        if(this.searchId==''){
          this.msg.ID=0
        }else{
          this.msg.ID = parseInt(this.searchId);
        }
        if (this.dateList && this.dateList.length > 0) {
          this.msg.StartTime = this.dateList[0];
          this.msg.EndTime = this.dateList[1];
        } else {
          this.msg.StartTime = '';
          this.msg.EndTime = '';
        }
        if(parseInt(this.msg.StartWorkYears) > parseInt(this.msg.EndWorkYears)){
          this.Error('工作年限由低到高')
          return false
        }
        if(parseInt(this.msg.StartScore) > parseInt(this.msg.EndScore)){
          this.Error('评分由低到高')
          return false
        }
        this.apipost("/api/GuideCar/GetGuidePageListRepository", this.msg, res => {
          this.loading=false;
          if(res.data.resultCode==1){
            this.tableData = res.data.data.pageData;
            this.count = res.data.data.count;
          }else {
            this.Info(res.data.message);
          }

        })
      },
      addRecharge(){
        this.$router.push('/addGuide');

      },

      Edit(row){
        this.$router.push({
          name: 'addGuide',
          query: {
            ID:row.ID,
            blank: "y"
          }
        });
      },
      delete_b(row){
        let that=this;
        that.Confirm("是否删除?", function () {
          that.apipost(
            "/api/GuideCar/DelGuideCarSiteInfo",
            {Id:row.ID},
            res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getDateList();
              } else {
                that.Error(res.data.message);
              }
            },
          );
        });
      },

      enableGuideCar(){
        this.apipost("/api/GuideCar/EnableGuideCarGuideInfo", this.EnableMsg, res => {
          if(res.data.resultCode==1){
            this.Success(res.data.message)
            this.getList()
          }
        })
      },
      //点击启用和冻结导游
      SetProduct(type){
        this.EnableMsg.IsEnable = type;
        if(this.EnableMsg.Ids.length==0){
          this.Info('请选择导游');
          return
        }
        this.EnableMsg.Ids = this.EnableMsg.Ids.join(",");
        this.enableGuideCar()
      },
      //勾选导游
      handleSelectionChange(val){
        var selectRow = JSON.parse(JSON.stringify(val));
        let array= [];
        selectRow.forEach(x => {
          let obj = {}
          obj = x.ID;
          array.push(obj)
        });
        this.EnableMsg.Ids = array
      },

      getList(){
        this.msg.pageIndex = 1
        this.getDateList()
      },

      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getDateList();
      },
    },
  }
</script>

<style >
  .directorGuideList .el-card__header{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #fff;

  }
  .directorGuideList .el-button--small{
    padding: 9px 15px;
  }
  .directorGuideList .content .searchInput{
    border: 1px solid #DCDFE6;
    border-radius: 4px;
    /*margin-left: 10px;*/
  }
  .directorGuideList .content .searchInput .el-input__inner{
    border:none;outline:none;
    height: 30px;
    line-height: 30px;
  }
  .directorGuideList .content .searchInput{
    line-height: normal;
    display: inline-table;
    border-collapse: separate;
    border-spacing: 0;
    width:250px;
  }
  .directorGuideList .content{
    background: #fff;
    margin-top:10px;
    padding: 15px;
    box-sizing: border-box;
  }
  .directorGuideList .el-tag{
    margin-right: 5px;
  }
  .directorGuideList .app-image{
    background-position: center center;
    width: 50px;
    height: 50px;
    border-radius:0%;
    float: left;
    margin-right: 8px;
  }
</style>
