<template>
  <div class="brandManagement">
    <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="addTopic">新增</el-button>
      </div>
    </div>
    <div class="content">
      <div style="display: flex;flex-direction: row;align-items: center">
        <div class="block">
          <span style="margin-left: 10px">品牌名</span>
          <el-input @keyup.enter.native="msg.pageIndex=1,getList()" @clear="msg.pageIndex=1,getList()"
            style="display:inline-block;width:225px;height:30px" placeholder="请输入品牌名" v-model="msg.BrandName"
            size="small" clearable>
          </el-input>
          <span style="margin-left: 10px">商铺性质</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 10px;"
            v-model="msg.ProjectType" size="small" placeholder="请选择商铺性质">
            <el-option label="不限" :value="0"></el-option>
            <el-option :label="x.Name" :value="x.Id" v-for="(x,y) in ProjectTypeList" :key="y"></el-option>
          </el-select>
          <span style="margin-left: 10px">品牌分类</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 10px;"
            v-model="msg.BrandClassId" size="small" placeholder="请选择">
            <el-option label="不限" :value="0"></el-option>
            <el-option :label="x.ClassName" :value="x.ID" v-for="(x,y) in BrandClassList" :key="y"></el-option>
          </el-select>
        </div>
      </div>
      <div style="display: flex;flex-direction: row;align-items: center;flex-wrap: wrap">
        <div class="block" style="margin-top: 15px;margin-left: 10px">
          <span>上下水</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 5px;" v-model="msg.Plumbing"
            size="small" placeholder="请选择">
            <el-option label="不限" :value="-1"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </div>
        <div class="block" style="margin-top: 15px;margin-left: 10px">
          <span>管径</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 5px;" v-model="msg.Caliber"
            size="small" placeholder="请选择">
            <el-option label="不限" :value="-1"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </div>
        <div class="block" style="margin-top: 15px;margin-left: 10px">
          <span>排污</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 5px;" v-model="msg.Sewage"
            size="small" placeholder="请选择">
            <el-option label="不限" :value="-1"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </div>
        <div class="block" style="margin-top: 15px;margin-left: 10px">
          <span>燃气</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 5px;" v-model="msg.RanQi"
            size="small" placeholder="请选择">
            <el-option label="不限" :value="-1"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </div>
        <div class="block" style="margin-top: 15px;margin-left: 10px">
          <span>排烟量</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 5px;" v-model="msg.PaiYan"
            size="small" placeholder="请选择">
            <el-option label="不限" :value="-1"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </div>
        <div class="block" style="margin-top: 15px;margin-left: 10px">
          <span>空调</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 5px;" v-model="msg.KongTiao"
            size="small" placeholder="请选择">
            <el-option label="不限" :value="-1"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </div>
        <div class="block" style="margin-top: 15px;margin-left: 10px">
          <span>新风</span>
          <el-select class="w100" @change="msg.pageIndex=1,getList()" style="margin-left: 5px;" v-model="msg.XinFeng"
            size="small" placeholder="请选择">
            <el-option label="不限" :value="-1"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </div>
      </div>
    </div>
    <div style="padding: 20px;background: #fff;">
      <el-table :data="dataList" header-cell-class-name="headClass" style="width: 100%" border>
        <el-table-column prop="Id" label="ID" width="100">
          <template slot-scope="scope">
            <span @click="goRecruit(scope.row.ID)">{{scope.row.ID}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="ClassName" label="分类" width="150">
        </el-table-column>
        <el-table-column prop="BrandName" label="品牌">
        </el-table-column>
        <el-table-column prop="Logo" label="Logo" width="100">
          <template slot-scope="scope">
            <el-image v-if="scope.row.Logo" :src="scope.row.Logo" style="width:50px;" :preview-src-list="scope.row.LogoList">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="ShopNum" label="店铺数量" width="80">
        </el-table-column>
        <el-table-column prop="BuiltUpArea" label="建筑面积" width="200">
          <template slot-scope="scope">
            <span>{{scope.row.BuiltUpArea}} 至 {{scope.row.EndBuiltUpArea}} 平</span>
          </template>
        </el-table-column>
        <el-table-column prop="ProjectName" label="商铺性质" width="150">
        </el-table-column>
        <el-table-column prop="BrandType" label="品牌定位" width="180">
        </el-table-column>
        <el-table-column prop="CustomerType" label="客群定位" width="160">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <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="total, prev, pager, next" :current-page.sync="msg.pageIndex" :total="pageCount">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  export default {
    name: "brandManagement",
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 20,
          BrandName: '', //品牌名
          ProjectType: 0, //商铺性质
          Plumbing: -1, //上下水（0-否1-有）
          Caliber: -1, //管径（0-否1-有）
          Sewage: -1, //排污（0-否1-有）
          RanQi: -1, //燃气（0-否1-有）
          DianLiang: "", //电量（0-否1-有）
          PaiYan: -1, //排烟量（0-否1-有）
          KongTiao: -1, //空调（0-否1-有）
          XinFeng: -1, //新风（0-否1-有）
          BrandClassId: 0, //分类
        },
        dataList: [],
        pageCount: 0,
        loading: false,
        BrandClassList: [], //品牌分类列表
        ProjectTypeList: [], //商铺性质列表
      }
    },
    created() {
      this.getBrandClassList();
      this.getProjectType();
    },
    mounted() {
      this.getList();
    },
    methods: {
      //获取商铺性质
      getProjectType() {
        this.apipost(
          "/api/Trade/GetProjectTypeEnumList", {},
          res => {
            if (res.data.resultCode == 1) {
              this.ProjectTypeList = res.data.data;
            } else {
              this.Error(res.data.message);
            }
          },
        );
      },
      getList() {
        this.apipost(
          "/api/Trade/GetBrandPageList", this.msg,
          res => {
            if (res.data.resultCode == 1) {
              this.dataList = res.data.data.pageData;
              this.pageCount = res.data.data.count;
              this.dataList.forEach(x=>{
                x.LogoList=[]
                x.LogoList.push(x.Logo);
              })
            } else {
              this.Error(res.data.message);
            }
          },
        );
      },
      getBrandClassList() {
        this.apipost(
          "/api/Trade/GetBrandClassList", {},
          res => {
            if (res.data.resultCode == 1) {
              this.BrandClassList = res.data.data;
            } else {
              this.Error(res.data.message);
            }
          },
        );
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      //新增品牌
      addTopic() {
        this.$router.push('/addbrand');
      },
      //删除品牌
      delete_b(row) {
        let that = this;
        that.Confirm("是否删除?", function () {
          that.apipost(
            "/api/Trade/RemoveBrand", {
              Id: row.ID
            },
            res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getList();
              } else {
                that.Error(res.data.message);
              }
            },
          );
        });
      },
      //编辑数据
      Edit(row) {
        this.$router.push({
          name: 'addbrand',
          query: {
            ID: row.ID,
            blank: "y"
          }
        });
      },
      //切换
      changeSwitch(item) {
        let msg = {
          Id: item.Id,
          IsOpen: item.IsOpen
        }
        this.apipost("/api/Education/UpdateEducationTalkShow", msg, res => {
          if (res.data.resultCode == 1) {
            this.Success(res.data.message);
            this.getList();
          }
        })
      }
    },
  }

</script>

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

  }

  .brandManagement .content {
    background: #fff;
    margin-top: 10px;
    padding: 15px;
    box-sizing: border-box;
  }

</style>
