<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>
      </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:190px">
            <el-input style="display:inline-block;width:160px;height:30px"
                      placeholder="请输入导游编号搜索"
                      v-model="msg.ID"
                      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>
          <span style="margin-left:15px">状态：</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>
          <el-button @click="SetProduct(0)" style="margin-left:10px;" size="mini">启用导游</el-button>
          <el-button @click="SetProduct(1)" style="margin-left:10px;" size="mini">冻结导游</el-button>

        </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" placeholder="请输入" v-model="msg.StartWorkYears" size="small"  clearable type="number"></el-input>
          <span style="margin: 0 10px ;">~</span>
          <el-input style="display:inline-block;width:100px;height:30px" placeholder="请输入" v-model="msg.EndWorkYears" size="small"  clearable type="number"></el-input>
          <el-button type="primary" @click="getList()" size="small" style="margin-left: 5px">确定</el-button>

          <span style="margin-left: 20px">评分范围：</span>
          <el-input style="display:inline-block;width:100px;height:30px" placeholder="请输入" v-model="msg.StartScore" size="small"  clearable 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"  clearable 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:0,
          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,
        },
      }
    },
    created(){
      this.getDateList();

    },
    methods:{
      getDateList(){
        this.loading=true;
        if(this.msg.ID==''){
          this.msg.ID=0
        }
        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(this.msg.StartWorkYears > this.msg.EndWorkYears){
          this.Error('工作年限由低到高')
          return false
        }
        if(this.msg.StartScore > 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>
