<template>
  <div class="app-container">
    <div class="filter-container">

      <el-input size="mini" v-model="search.keyWord" placeholder="关键字" style="width: 200px;" class="filter-item" />
      <el-button size="mini" class="filter-item" type="primary" icon="el-icon-search" @click="searchData">
        搜索
      </el-button>
      <el-button
        size="mini"
        class="filter-item"
        style="margin-left: 10px;"
        type="primary"
        icon="el-icon-plus"
        @click="handleCreateAdd">
        增加纸张品牌档案
      </el-button>
      <el-checkbox size="mini" @change="checkDisable" v-model="disableLock" label="已禁用" border></el-checkbox>
    </div>
    <div class="table-con">
      <el-table
        :data="tableData"
        v-loading="listLoading"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        border
      >
        <el-table-column
          label="#"
          align="center"
          type="index"
          :index="indexMethod">
        </el-table-column>
        <el-table-column label="操作" align="left" width="100" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <el-button @click="editStatus(row.id,'1')" type="danger" v-if="row.voidFlag==0" size="mini">
              禁用
            </el-button>
            <el-button @click="editStatus(row.id,'0')" v-else="row.voidFlag==1" size="mini">
              启用
            </el-button>


          </template>
        </el-table-column>
        <el-table-column
          prop="brandName"
          label="品牌名称">
        </el-table-column>
        <el-table-column
          prop="companyName"
          label="生产公司名称">
        </el-table-column>
        <el-table-column
          label="创建时间"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.createTime">{{scope.row.createTime | getTime}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="状态" class-name="status-col" width="100">
          <template slot-scope="{row}">
            <el-tag v-if="row.voidFlag==0" type="success">
              启用
            </el-tag>
            <el-tag v-else="row.voidFlag==1" type="danger">
              禁用
            </el-tag>
          </template>
        </el-table-column>

      </el-table>
      <pagination v-show="listData.total>0" :total="listData.total" :page.sync="listData.page" :limit.sync="listData.pageSize" @pagination="getTableInfo" />
    </div>
    <cancledialog @tableRefresh="getTableInfo" ref="confirmDialog"></cancledialog>

    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="450px">
      <el-form label-width="130px" label-position="right">
        <el-form-item label="品牌名称">
          <el-input v-model="form.brandName"></el-input>
        </el-form-item>
        <el-form-item label="生产公司名称">
          <el-input v-model="form.companyName"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogStatus==='1'?addBtn():editBtn()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getPaperBrandList,
  addPaperBrand
} from '@/api/baseInfo/paper/paperInfo.js'
import Cancledialog from '@/components/Dialog/Cancledialog.vue'
import Pagination from '@/components/Pagination'
export default {
  name: "list",
  components: {
    Cancledialog,Pagination
  },
  data() {
    return {
      disableLock: false,
      dialogStatus: 1,//1增加，2修改
      dialogTitle: '',
      dialogVisible: false,
      listLoading: false,
      tableData: [],
      search: {
        keyWord:'',
        voidFlag:'',
      },
      listData:{
        total:0,
        page: 1,
        pageSize:10
      },
      form:{}
    }
  },
  mounted() {
    this.getTableInfo();
  },
  methods: {
    checkDisable(val) {
      // console.log(val);
      this.listData.page = 1;
      this.getTableInfo()
    },
    //启用禁用
    editStatus(id,status){
      var _that = this;
      var paperBrand = {
        id:id,
        voidFlag:status
      }
      var params = {
        "paperBrand": JSON.stringify(paperBrand),
      }

      var url = '/doc/voidPaperBrand';
      _that.$refs.confirmDialog.updataClick(params, url);
    },
    addBtn(){
      const _that = this;
      if(!_that.form.brandName){
        _that.$message("品牌名称不能为空");
        return
      }
      var info =JSON.stringify(_that.form)
      var data = {
        "paperBrand": info
      }
      addPaperBrand(data).then(res => {
        // console.log(res);
        if(res.httpCode == 200){
          _that.dialogVisible = false
          _that.$message({
            message: '增加成功',
            type: 'success'
          });
          _that.getTableInfo();
          _that.dialogVisible = false;
        }else{
          _that.$message.error(res.msg);
          _that.dialogVisible = false;
        }
      }).catch(err => {
        // _that.$message.error(err)
        _that.dialogVisible = false;
      })
    },
    editBtn(){},
    //增加
    handleCreateAdd(){
      const _that = this
      _that.form={
        brandName:'',
        companyName:''
      }
      _that.dialogTitle = '增加纸张品牌档案'
      _that.dialogStatus = '1';
      _that.dialogVisible = true;

    },
    //获取表格数据
    getTableInfo(){
      const _that = this
      _that.listLoading = true
      var params = _that.search;
      if(_that.disableLock){
        _that.search.voidFlag = 1;
      }else {
        _that.search.voidFlag = 0;
      }
      var page = {
        pageIndex:_that.listData.page,
        pageSize: _that.listData.pageSize,
      }
      var data = {
        "params": JSON.stringify(params),
        "page": JSON.stringify(page),
      }
      // console.log(data);
      getPaperBrandList(data).then(response => {
        // console.log("tableData",response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data
        _that.listData.total = response.total
        // console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.listLoading = false
      })
    },
    //搜索
    searchData(){
      this.listData.page = 1;
      this.getTableInfo()
    },
    //序号
    indexMethod(index) {
      return index+1;
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-checkbox.is-bordered.is-checked {
  border-color: #F56C6C;
}
::v-deep .el-checkbox__input.is-checked .el-checkbox__inner,
::v-deep .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  border-color: #F56C6C !important;
  background-color: #F56C6C !important;
}

::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
  color: #F56C6C !important;
}

::v-deep .el-checkbox__inner:hover {
  border-color: #F56C6C !important;
}

::v-deep .el-checkbox__input.is-focus .el-checkbox__inner {
  border-color: #F56C6C !important;
}

.app-container {
  background-color: #fff;
  padding: 30px;
  min-height: calc(100vh - 84px);
}
.filter-container {
  margin-bottom: 15px;
}
</style>
