<template>

  <div class="box-center">
    <!-- 头 -->
    <div class="app-top">
      <div class="app-titel" style="margin-top: 5px">
        <div class="label" v-if="orgType!=3">楼盘：</div>
        <div v-if="orgType!=3">
          <el-select
            v-model="projectId"
            @change="houseChange"
            placeholder="请选择"
            filterable
          >
            <el-option
              v-for="item in houseList"
              :key="item.id"
              :label="item.propertyName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div class="label">状态：</div>
        <div>
          <el-select
            v-model="statetest"
            placeholder="请选择"
          >
            <el-option
              v-for="item in stateList"
              :key="item.id"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div style="margin-left: 20px">
          <el-button style="background: #2671e2; color: #ffffff" @click="Screening()">筛选</el-button>
        </div>
         <div style="margin-left: 20px">
          <el-button @click="editorinfo()" style="background: #2671e2; color: #ffffff"
            >添加模板</el-button
          >
        </div>
      </div>
    </div>

    <!-- 表格 -->
    <div class="cen-tab">
        <el-table
          :data="tableData"
          stripe
          height="500"
          style="width: 100%">
          <el-table-column
            prop="houseName"
            label="楼盘名称"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="name"
            label="状态"
             align="center"
           >
            <template slot-scope="scope">
                <p v-if="scope.row.status==1">停用</p>
                <p v-if="scope.row.status==0">启用</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="count"
            label="大类个数"
             align="center">
          </el-table-column>

          <el-table-column
            prop="createTime"
            label="创建时间"
            align="center"
          >
          </el-table-column>
         <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button type="text" size="small" v-if="scope.row.status==1" @click="clickstateis(scope.row)">启用</el-button>
              <el-button type="text" size="small" v-if="scope.row.status==0" @click="clickstateno(scope.row)">停用</el-button>
              <el-button type="text" size="small" @click="clickbianji(scope.row)">编辑</el-button>
               <el-button type="text" size="small" @click="templatedel(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="display: flex;justify-content:flex-end;margin-top: 10px;">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage4"
              :page-sizes="[8, 16, 24, 32]"
              :page-size="4"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
        </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      currentPage4:1,
      total:0,//总条数
      pageNum:1,
      pageSize:8,
      houseList:[],
      projectId:"",
      orgType:localStorage.getItem('orgType'),
      stateList:[
        {label:'请选择',value:''},
        {label:'停用',value:'1'},
        {label:'启用',value:'0'},
      ],
      statetest:'',
    };
  },
  mounted() {
    this.zkhousePage()
  },
  methods: {
    //停用
    clickstateno(item){
      this.$confirm('此操作将停用此模板, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.http.templatestartOrStop({
            id:item.id,
            status:1
          }).then((res) => {
              console.log(res);
              if(res.code==0){
                   this.$message({
                    type: 'success',
                    message: '停用成功!'
                  });
                   this.getcompanyList()
              }else{
                 this.$message({
                  type: 'info',
                  message: res.msg
                });
              }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    },
    //启用
    clickstateis(item){
        this.$confirm('此操作将启用此模板, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.http.templatestartOrStop({
            id:item.id,
            status:0
          }).then((res) => {
              console.log(res);
              if(res.code==0){
                   this.$message({
                    type: 'success',
                    message: '启用成功!'
                  });
                  this.getcompanyList()
              }else{
                 this.$message({
                  type: 'info',
                  message: res.msg
                });
              }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    },
    //筛选
    Screening(){
      this.pageNum=1;
      this.getcompanyList()
    },
     //获取楼盘
     zkhousePage() {
      this.$api.api.findHouseByUser({
        orgType: localStorage.getItem("orgType"),
      }).then((res) => {
          this.houseList = res.data;
          if(localStorage.getItem('orgType')==3){
            this.projectId=localStorage.getItem('houseId')
          }else{
            this.projectId = res.data[0].id;
          }
          // this.projectId = res.data[0].id;
          this.getcompanyList()
        });
    },
    //切换楼盘
    houseChange(){
      this.pageNum=1;
       this.getcompanyList()
    },
    // 获取列表
    getcompanyList() {
      this.tableData=[];
      let parmest={
          current: this.pageNum,
          size: this.pageSize,
          houseId:this.projectId,
          status:this.statetest
      }
      this.$api.http.templatefindByPage(parmest).then((res) => {
          this.tableData=res.data.records;
          this.total=res.data.total
        });
    },
    //templatedel删除模板
    templatedel(item){
     this.$confirm('此操作将删除此模板, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.http.templatedel({
            id:item.id,
          }).then((res) => {
              console.log(res);
              if(res.code==0){
                   this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                  this.getcompanyList()
              }else{
                 this.$message({
                  type: 'info',
                  message: res.msg
                });
              }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    },
    handleSizeChange(val) {
      this.pageSize=val;
      this.getcompanyList()
    },
    handleCurrentChange(val) {
      this.pageNum=val;
      this.getcompanyList()
    },


    //編輯
    clickbianji(row){
          let Userrecord={
					id:row.id,
          houseId:this.projectId,
				}
      this.$router.push({ path: "/Template/Pinspeakwords", query: { flag: Userrecord } });
    },
    //添加
     editorinfo(){
        let Userrecord={
					id:'',
          houseId:this.projectId,
				}
      this.$router.push({ path: "/Template/Pinspeakwords", query: { flag: Userrecord } });
    },

  },
};
</script>

<style scoped="scoped" lang="scss" >
.box-center {
  width: 100%;
  padding: 15px;
  min-width: 1200px;
  padding-bottom: 40px;
}
.cen-tab{
  width: 100%;
  padding: 15px;
  background: #FFFFFF;
  margin-top: 15px;
}
.tophove {
  color: #ffffff;
  background: #2671e2;
}
.app-top {
  width: 100%;
  background: #ffffff;
  box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  padding-top: 15px;
  padding-bottom: 15px;
  .app-titel {
    width: 100%;
    display: flex;
    align-items: center;
    .label {
      font-size: 14px;
      font-weight: 400;
      color: #32363d;
      line-height: 14px;
      margin-left: 15px;
    }
    .toptimeqhuan {
      height: 30px;
      background: #ffffff;
      display: flex;
      align-items: center;
    }
    .toptimeqhuan div {
      padding-left: 20px;
      padding-right: 20px;
      text-align: center;
      line-height: 30px;
      font-size: 14px;
      margin-right: 15px;
      border-radius: 4px;
      border: 1px solid #e0e0e0;
    }
  }
}
</style>
