<template>
  <div class="guideCarSiteList">
    <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" style="display: flex;flex-direction: row;justify-content: space-between;width: 100%;">
          <div class="searchInput" style="width:250px">
            <el-input style="display:inline-block;width:225px;height:30px"
                      placeholder="请输入站点名称搜索"
                      v-model="msg.SiteName"
                      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 style="display: flex;flex-direction: row;">
            <el-button type="primary" @click="SetProduct(1)" size="small">开启</el-button>
            <el-button type="primary" @click="SetProduct(0)" size="small">关闭</el-button>
          </div>
        </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="ID"
          width="100">
        </el-table-column>

        <el-table-column
          prop="SiteName"
          label="站点名称">
        </el-table-column>



        <el-table-column
          prop="RegionList"
          label="地区">
          <template slot-scope="scope">
            <el-tag v-for="(item,index) in scope.row.RegionList"  :key="index">{{item}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="SiteName"
          width="130"
          label="是否开启">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.IsEnable" active-color="#409EFF" :active-value="1"
                       :inactive-value="0" @change="changeEnabled(scope.row)">
            </el-switch>
          </template>
        </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: "guideCarSiteList",
    data(){
      return{
        msg:{
          pageIndex:1,
          pageSize:20,
          SiteName:'',
        },
        tableData:[],
        count:0,
        loading:false,
        EnableMsg:{
          Ids:'',
          IsEnable:0,
        },
      }
    },
    created(){
      this.getDateList();

    },
    methods:{
      getDateList(){
        this.loading=true;
        this.apipost("/api/GuideCar/GetGuideCarSiteList", 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('/addSite');

      },

      Edit(row){
        this.$router.push({
          name: 'addSite',
          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);
              }
            },
          );
        });
      },
      changeEnabled(item){
        this.EnableMsg.Ids = item.ID;
        this.EnableMsg.IsEnable = item.IsEnable;
        this.enableGuideCar()

      },
      enableGuideCar(){
        this.apipost("/api/GuideCar/EnableGuideCarSiteInfo", 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 >
  .guideCarSiteList .el-card__header{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #fff;

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