<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline='true'>
        <el-form-item label='客商类型'>
          <el-select v-model="search.merchTypeName" clearable filterable collapse-tags size="small" style="width:200px;margin-right: 10px;" placeholder="请选择查询内容">
            <el-option v-for="item in merchType" :key="item.baseName" :label="item.baseName"
              :value="item.baseName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label='客商名称'>
          <el-input v-model="search.merchName" size="small" placeholder="请输入查询内容" style="width: 200px" @keyup.enter.native="searchData"></el-input>
        </el-form-item>
        <el-form-item label='评价星级'>
          <el-select v-model="search.evaLevelName" clearable filterable collapse-tags size="small" style="width:200px;" placeholder="请选择查询内容">
            <el-option v-for="item in evaLevelNameType" :key="item.baseName" :label="item.baseName"
              :value="item.baseName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" @click="reset">重置</el-button>
        </el-form-item>
      </el-form> 
    </div>
    <div class="common-title-div">
      <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
        客商产品信誉表
      </div>
      <div>
      <el-button icon="el-icon-remove-outline" type="danger" size="mini" @click="deleteData">停用</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData">启用</el-button>
      </div>
    </div>
    <div class="common-table-div" style="margin-bottom:0;margin-top:0">
       <el-table v-loading="dataLoading" ref="dataTable" border :height="height_top" highlight-current-row @selection-change="handleSelectionChange"  @current-change="handleCurrentChange" :data="table.list" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :cell-class-name="tableRowClassName" :summary-method="getSummaries" show-summary>
        <el-table-column type="index" label="NO" fixed="left" align="center">
        </el-table-column>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="merchName" label="客商名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="merchTypeName" label="客商类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="matClassName" label="物料类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="matName" label="物料名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="evaLevelName" label="客户等级" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="validFlag1" label="数据状态" align="center">
          <!-- <template slot-scope="scope">
              <span v-if="scope.row.validFlag == 1">已启用</span>
              <span v-else-if="scope.row.validFlag == 0">已停用</span>
          </template> -->
        </el-table-column>
        <!-- <el-table-column sortable width="" prop="memo" label="备注" align="center"></el-table-column> -->
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="evaTime" label="评价时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="evaMan" label="评价人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" label="创建时间" align="center"></el-table-column>
      </el-table>
    </div>
    <div class="common-foot-style">
        <el-pagination v-loading="dataLoading" @size-change="pageSizeChange" @current-change="pageCurrentChange"
          :current-page="page.pageNum" :page-sizes="[10, 20, 50, 100, 200]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalPage" background>
        </el-pagination>
    </div>
    <div class="common-title-div">
      <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
        客商产品评价表
      </div>
      <div>
      <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" @click="addData2">新增</el-button>
      <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData2">修改</el-button>
      <el-button icon="el-icon-remove-outline" type="danger" size="mini" @click="deleteData2">反审</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData2">审核</el-button>
      <el-button icon="el-icon-circle-close" type="danger" size="mini" @click="deleteData3">删除</el-button>
      </div>
    </div>
    <div class="common-table-div" style="margin-bottom:0;margin-top:0">
       <el-table v-loading="dataLoading2" ref="dataTable2" border :height="height_bot" highlight-current-row @selection-change="handleSelectionChange2" :data="table.list2" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :cell-class-name="tableRowClassName2" :summary-method="getSummaries2" show-summary>
        <el-table-column type="index" label="NO" fixed="left" align="center">
        </el-table-column>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="merchName" label="供应商" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="matClassName" label="物料类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="evaVer" label="评价版本" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="evaLevelName" label="评价等级" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="200px" prop="evaDesc" label="评价描述" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="stateFlag1" label="状态" align="center">
          <!-- <template slot-scope="scope">
              <span v-if="scope.row.stateFlag == 1">审核</span>
              <span v-else-if="scope.row.stateFlag == 0">未审核</span>
          </template> -->
        </el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="apprManName" label="评价人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="apprTime" label="评价时间" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="auditManName" label="审核人" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="auditTime" label="审核时间" align="center"></el-table-column>
        <!-- <el-table-column width="95px" prop="createMan" label="创建人" align="center"></el-table-column>
        <el-table-column width="160px" prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column width="95px" prop="updateMan" label="修改人" align="center"></el-table-column>
        <el-table-column width="160px" prop="updateTime" label="修改时间" align="center"></el-table-column> -->
      </el-table>
    </div>
    <!-- <div class="common-foot-style">
        <el-pagination v-loading="dataLoading2" @size-change="pageSizeChange2" @current-change="pageCurrentChange2"
          :current-page="page2.pageNum" :page-sizes="[10, 20, 50, 100, 200]" :page-size="page2.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page2.totalPage" background>
        </el-pagination>
    </div> -->
    <!-- <div is="alertComponets" :showFlag="showFlag" :Params="Params" @refresh='refresh'></div> -->
    <div is="alertComponets2" :showFlag2="showFlag2" :Params="Params" :Params2="Params2" @refresh='refresh2'></div>
  </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
import alertComponets2 from './alertComponents2';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: {alertComponets2},
  data () {
    return {
      table: {
        list: [],
        list2: []
      },
      dataLoading: false,
      dataLoading2: false,
      icoreFilterFlag: true,
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      mmId: '',
      showFlag: false,
      Params: {},
      showFlag2: false,
      Params2: {},
      merchType: [],
      evaLevelNameType: [],
      multipleSelection3: [],
      multipleSelection4: [],
      ids: [],
      search: {
        merchName: '',
        merchTypeName: '',
        evaLevelName: ''
      },
      height_top:0,
      height_bot:0
    }
  },
  created() {
    this.height_top = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 100;
    this.height_bot = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 100;
  },
 mounted () {
    this.getDataList();
    this.getDataList2(this.mmId);
    this.addScreen();
    this.addScreen2();
    this.getMerchTypeList ();
    this.getEvaLevelName ()
  },
  methods: {
    getSummaries (param) {
      const { columns, data } = param;
      const sums = [];
       columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index === 2) {
            sums[index] = this.page.totalPage;
          }
       });
        return sums;
    },
    getSummaries2 (param) {
      const { columns, data } = param;
      const sums = [];
       columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index === 2) {
            sums[index] = this.page2.totalPage;
          }
       });
        return sums;
    },
     open(mag, typ, time) {
        this.$message({
          showClose: true,
          message: mag,
          type: typ,
          duration: time
        });
      },
    refresh () {
      let _this = this;
      _this.getDataList();
      _this.getDataList2(this.mmId);
    },
    refresh2 () {
      let _this = this;
      _this.getDataList2(this.mmId);
    },
    deleteData () {
       let _this = this;
        if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要停用的数据！')
       } else {
        _this.dialogTableVisible = false;
        // _this.multipleSelection = []
        // _this.multipleSelection.push(_this.multipleSelection3)
        for (var i = 0; i < _this.multipleSelection3.length; i++) {
        _this.multipleSelection3[i].evaMan = userName;
        _this.multipleSelection3[i].evaNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsmerchantsmats/abolish', _this.multipleSelection3, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.open('停用操作成功', 'success', 1200)
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    recoverData () {
       let _this = this;
        if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要启用的数据！')
        } else {
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection3.length; i++) {
        _this.multipleSelection3[i].evaMan = userName;
        _this.multipleSelection3[i].evaNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsmerchantsmats/recover', _this.multipleSelection3, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.open('启用成功', 'success', 1200)
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    addData2 () {
      let _this = this;
     if (_this.multipleSelection3.length !== 1) {
       this.$message.warning('请选择一条客商产品信誉信息数据！')
     } else {
      _this.showFlag2 = !_this.showFlag2;
      _this.Params2 = null;
      _this.Params = _this.multipleSelection3[0]
      }
      //  if (_this.multipleSelection.length !== 1) {
      //   this.$message.warning('请选择一条业务规则信息数据！')
      // } else {
      // _this.showFlag2 = !_this.showFlag2;
      // _this.Params2 = null;
      // _this.Params = _this.multipleSelection
      // }
    },
    modifyData2 () {
      let _this = this;
     if (_this.multipleSelection4.length !== 1) {
        this.$message.warning('请勾选您要修改的一条数据！')
      } else {
        _this.showFlag2 = !_this.showFlag2;
        _this.Params2 = _this.multipleSelection4[0];
        _this.Params = null
      }
    },
    deleteData2 () {
       let _this = this;
       if (_this.multipleSelection4.length < 1) {
        this.$message.warning('请勾选您要反审的数据！')
      } else {
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection4.length; i++) {
        _this.multipleSelection4[i].auditManName = userName;
        _this.multipleSelection4[i].auditNo= userId
        }
        _this.axios.post('pass/baseManagement/v1/limsmerchantsevas/uncheck', _this.multipleSelection4, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.open('反审成功', 'success', 1200)
         _this.refresh2()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    recoverData2 () {
       let _this = this;
        if (_this.multipleSelection4.length < 1) {
        this.$message.warning('请勾选您要审核的数据！')
      } else {
        _this.dialogTableVisible2 = false;
        for (var i = 0; i < _this.multipleSelection4.length; i++) {
        _this.multipleSelection4[i].auditManName = userName;
        _this.multipleSelection4[i].auditNo= userId
        }
        _this.axios.post('pass/baseManagement/v1/limsmerchantsevas/check', _this.multipleSelection4, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.open('审核成功', 'success', 1200)
         _this.refresh2()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    deleteData3 () {
       let _this = this;
       if (_this.multipleSelection4.length < 1) {
        this.$message.warning('请勾选您要删除的数据！')
       } else {
        _this.dialogTableVisible = false;
        // for (var i=0; i<_this.multipleSelection4.length; i++) {
        //     _this.ids[i] = _this.multipleSelection4[i].mvId
        // }
        _this.axios.post('pass/baseManagement/v1/limsmerchantsevas/delete', _this.multipleSelection4, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.open('删除成功', 'success', 1200)
         _this.refresh2()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    searchData () {
        let _this = this;
        _this.dataLoading = true;
        _this.page.pageNum = 1;
        _this.axios.get('pass/baseManagement/v1/limsmerchantsmats/' + 'like/?pageNum=' + _this.page.pageNum + '&pageSize=' + _this.page.pageSize +
          '&merchName=' + _this.search.merchName + '&merchTypeName=' + _this.search.merchTypeName + '&evaLevelName=' + _this.search.evaLevelName)
        .then(res => {
          _this.dataLoading = false;
          _this.table.list = res.data.list;
          for (let i = 0; i < this.table.list.length; i++) {
          if (this.table.list[i].validFlag === '0') {
            this.table.list[i].validFlag1 = '停用'
          } else if (this.table.list[i].validFlag === '1') {
            this.table.list[i].validFlag1 = '正常'
          }
          }
          _this.page.totalPage = res.data.total;
        }).catch(e => {
          _this.dataLoading = false;
        });
      },
    reset () {
      let _this = this;
      _this.search.merchName = '';
      _this.search.merchTypeName = '';
      _this.search.evaLevelName = '';
      _this.searchData();
      _this.getMerchTypeList ();
      _this.getEvaLevelName ()
    },
    handleSelectionChange (val) {
      this.multipleSelection3 = val;
      if(val.length > 0) {
         this.mmId = val[val.length-1].mmId;
         this.getDataList2 (this.mmId);
       }
      // if (val.length === 1) {
      //    this.mmId = '';
      //    this.mmId = val[0].mmId;
      //    this.getDataList2 (this.mmId);
      // } else {
      //    this.mmId = '';
      //    this.getDataList2 (this.mmId);
      // }
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    handleSelectionChange2 (val) {
      // this.multipleSelection2 = [];
      // this.multipleSelection2.push(val);
      this.multipleSelection4 = val;
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.getDataList2(this.mmId);
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.getDataList2(this.mmId);
    },
    handleCurrentChange (val) {
       if (val.mmId === null) {
        this.mmId = '';
      } else {
        this.mmId = val.mmId;
      }
      this.getDataList2 (this.mmId);
    },
    addScreen () {
      this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    addScreen2 () {
     this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable2.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    getDataList () {
      this.dataLoading = true;
      this.axios.get('pass/baseManagement/v1/limsmerchantsmats/' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize)
            .then(res => {
              this.dataLoading = false;
              this.table.list = res.data.list;
              for (let i = 0; i < this.table.list.length; i++) {
              if (this.table.list[i].validFlag === '0') {
                this.table.list[i].validFlag1 = '停用'
              } else if (this.table.list[i].validFlag === '1') {
                this.table.list[i].validFlag1 = '正常'
              }
              }
              this.page.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading = false;
            });
    },
     getDataList2 (mmId) {
      this.dataLoading2 = true;
      if (mmId === null || mmId === '') {
        this.table.list2 = []
        this.dataLoading2 = false;
        return 0
      } else {
        this.axios.get('pass/baseManagement/v1/limsmerchantsevas/' + '?pageNum=' + this.page2.pageNum + '&pageSize=' + this.page2.pageSize +'&mmId=' + mmId)
              .then(res => {
                this.dataLoading2 = false; 
                this.table.list2 = res.data.list;
                for (let i = 0; i < this.table.list2.length; i++) {
                if (this.table.list2[i].stateFlag === '0') {
                 this.table.list2[i].stateFlag1 = '未审核'
                } else if (this.table.list2[i].stateFlag === '1') {
                this.table.list2[i].stateFlag1 = '审核'
                }
                }
                this.page2.totalPage = res.data.total;
              }).catch(e => {
                this.dataLoading2= false;
              });
      }
    },
   getMerchTypeList () {
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4832}, {individualType: 'json'}).then(res => {
              this.dataLoading = false;
              this.merchType = res.data
     })
   },
    getEvaLevelName () {
      this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4837}, {individualType: 'json'}).then(res => {
              this.evaLevelNameType = res.data;
            }).catch(e => {
              // this.dataLoading = false;
            });
      },
   tableRowClassName ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 7) {
        if (row.validFlag !== '1') {
          return 'error-row';
        }
        return '';
        }
      },
    tableRowClassName2 ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 7) {
        if (row.validFlag !== '1') {
          return 'error-row';
        }
        return '';
        }
      },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
