<template>
  <!-- 查询Wms钢产品执行标准数据 -->
  <div class="getWmsStandardReal">
    <div class="box">
        <div class="box-top">
          <el-form style="overflow: hidden;" :style="filterForm.show ? null : { height: '0px' }"
            class="box-top-form" size="mini" label-width="60px">
            <el-row>
              <el-col :span="8">
                <el-form-item label="执行代码">
                  <el-input clearable v-model="filterForm.data.basecode"
                    placeholder="执行代码: 10080101" style="width: 95%;" ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="执行标准">
                  <el-input clearable v-model="filterForm.data.basename"
                    placeholder="执行标准: GB/T699-199" style="width: 95%;" ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div class="box-top-gjl">
            <div style="float:right; text-align: right;">
                <el-button class="button" type="primary" size="mini" icon="el-icon-search"
                  v-privilege="activeMenu + 'QUERY'" :loading="rightTable.loading" @click="getTableData()" >查询</el-button>
                <el-button class="button" type="primary" size="mini" icon="el-icon-refresh"
                  v-privilege="activeMenu + 'QUERY'" :loading="rightTable.loading" @click="tableDataCancel();" >重置</el-button>
                <el-button size="mini" :icon="filterForm.show ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"
                  :title="filterForm.show ? '收起搜索区' : '展开搜索区'" @click="filterForm.show = !filterForm.show;
                    $nextTick(() => { singleTableHeight = getRoleHeight($refs['singleTable'].$el) - 45; });"
                >{{ filterForm.show ? '收起' : '展开' }}</el-button>
            </div>
          </div>
        </div>
        <div class="box-bottom">
            <el-table stripe border highlight-current-row id="singleTable" ref="singleTable" style="width: 100%;" size="mini"
              :data="frontEndPageChange" v-loading="rightTable.loading" :height="singleTableHeight" show-summary :summary-method="getSummaries">
                <el-table-column sortable prop="basecode" label="执行编码" min-width="80px" align="center"
                  :show-overflow-tooltip="true">
                  </el-table-column>
                <el-table-column sortable prop="basename" label="执行标准" min-width="86px" align="center"
                  :show-overflow-tooltip="true">
                </el-table-column>
            </el-table>
          <el-pagination layout="total, sizes, prev, pager, next, jumper" style="text-align: right;margin-top: 10px;"
            :page-sizes="[10, 20, 50, 100, 500, 1000]"
            :total="rightTable.total" :page-size="rightTable.pageSize" :current-page.sync="rightTable.pageNum"
            @size-change="tableSizeChange" ></el-pagination>
        </div>
    </div>
  </div>
</template>

<script>
import { zCheckNumber1 } from '~/utils/validator.js';
import store from '@/store/index.js';
import {formatDate, XtcommonSummaries} from '@/utils/util.js';
export default {
  name: 'getDzMaterialReal',
  data () {
    return {
      activeMenu: '',
      singleTableHeight: 100,
      tableData: {
          arr: [],
          obj: {}
        },
      filterForm: {
        show: true,
        data: {
          basecode: '',
          basename: ''
        }
      },
      rightTable: {
        total: 0,
        pageNum: 1,
        pageSize: 20,
        loading: false,
        tableLoading: false,
        tableData: {
          arr: [],
          obj: {}
        }
      }
    }
  },
  created () {
      this.activeMenu = window.localStorage.getItem('activeMenu');
  },
  mounted () {
    let that = this;
    window.PEDataObj = {
      // 将数据绑定到window上，供main页面使用
      vm: that,
      // tableArr：用于导出成Excel的表格的信息
      tableArr: [{
        name: '',
        id: 'singleTable'
      }]
    };
    that.$nextTick(() => {
      // 立即获取的height有一定偏差，通过setTimeout延迟来解决
      setTimeout(() => {
        that.singleTableHeight = that.getRoleHeight(that.$refs['singleTable'].$el) - 45;
      }, 1);
    });
    // 这里写页面加载需要调用的代码
    that.getTableData();
  },
  computed: {
    frontEndPageChange () {
      let that = this;
      let Tdata = [];
      let start = (that.rightTable.pageNum - 1) * that.rightTable.pageSize;
      if (start >= that.rightTable.tableData.arr.length) start = 0;
      let end = that.rightTable.pageNum * that.rightTable.pageSize;
      if (end >= that.rightTable.tableData.arr.length) end = that.rightTable.tableData.arr.length;
      // that.rightTable.tableData.arr = that.rightTable.tableData.arr.slice(start, end);
      that.rightTable.total = that.rightTable.tableData.arr.length;
      Tdata = that.rightTable.tableData.arr;
      Tdata = Tdata.filter(data => !that.filterForm.data.basecode || data.basecode.toLowerCase()
        .includes(that.filterForm.data.basecode.toLowerCase()));
      Tdata = Tdata.filter(data => !that.filterForm.data.basename || data.basename.toLowerCase()
        .includes(that.filterForm.data.basename.toLowerCase()));
      // Tdata = Tdata.filter(data => (!that.filterForm.data.cinvname || !data.cinvname) || data.cinvname.toLowerCase()
      //   .includes(that.filterForm.data.cinvname.toLowerCase()));
      // Tdata = Tdata.filter(data => (!that.filterForm.data.cinvstd || !data.cinvstd) || data.cinvstd.toLowerCase()
      //   .includes(that.filterForm.data.cinvstd.toLowerCase()));
      // Tdata = Tdata.filter(data => (!that.filterForm.data.cwhname || !data.cwhname) || data.cwhname.toLowerCase()
      //   .includes(that.filterForm.data.cwhname.toLowerCase()));
      // Tdata = Tdata.filter(data => (!that.filterForm.data.djlx || !data.djlx) || data.djlx.toLowerCase()
      //   .includes(that.filterForm.data.djlx.toLowerCase()));
      // Tdata = Tdata.filter(data => (!that.filterForm.data.place || !data.place) || data.place.toLowerCase()
      //   .includes(that.filterForm.data.place.toLowerCase()));
      that.rightTable.total = Tdata.length;
      return Tdata.slice(start, end);
    }
  },
  methods: {
    //  计算树区域高度
    getRoleHeight (dom) {
        return window.innerHeight - dom.offsetTop;
    },
    // 自定义的表格合计方法：只给指定列进行合计
    getSummaries (param) {
        const prop = []; // 合计列绑定的prop
        return XtcommonSummaries(param, prop);
    },
    // 获取表格中的数据
    getTableData (pageNum) {
        let that = this, obj = {};
        let url = 'pass/product/v1/emsstandard/getStandards';
        that.rightTable.loading = true;
        that.axios.get(url)
          .then(function (res) {
            if (res.code=='0') {
              that.tableData.arr = res.data;
              that.rightTable.tableData.arr = res.data;
            }else{
              that.$message.error(res.message)
            }
            that.rightTable.loading = false;
          }).catch(function () {
            that.rightTable.loading = false;
          });
    },
    // 改变表格显示条数
    tableSizeChange (val) {
        let that = this;
        that.rightTable.pageSize = val;
    },
    // 重置搜索
    tableDataCancel () {
      let that = this;
      that.filterForm.data.basecode = '';
      that.filterForm.data.basename = '';
    },
    rounding (row, column) {
      // return parseFloat(row[column.property]).toFixed(2)
    }
  } 
}
</script>

<style lang="less">
.getWmsStandardReal {
  min-width: 700px;
  height: 100%;
  .box {
    height: 100%;
    padding: 15px 15px 0 15px;
    .box-left {
      float: left;
      width: 200px;
      height: calc(100% - 3px);
      overflow: auto;
      .box-left-bt {
        line-height: 35px;
        font-size: 16px;
        border-bottom: 1px solid #ccc;
      }
      .box-left-tree {
        height: calc(100% - 50px);
        overflow: auto;
        padding: 7px 7px 0 0;
          .tree-row-on {
            color: #3279e8;
            font-weight: 600;
          }
      }
    }
    .box-top {
      .box-top-form {
        padding-left: 7px;
        .el-form-item {
          margin-bottom: 7px;
        }
      }
      .box-top-gjl {
        overflow: hidden;
        padding: 7px 0 7px 7px;
        border-top: 1px solid #ccc;
      }
    }
    .box-bottom {
      padding-left: 7px;
    }

    .el-table .el-table__row {
      height: 35px;
    }
    .el-table__body .el-form-item--mini.el-form-item {
      margin: 0px;
      .error {
        overflow: hidden;
        color: #f56c6c;
        font-size: 12px;
        line-height: 1;
      }
    }
  }
  .color_no {
    color: #7a7a7a;
  }
  .color_yes {
    color: #1a9f17;
  }
}
</style>
