<template>
  <div>
    <el-card>
      <span style="margin-left: 5px">产品名称:</span>
      <el-select v-model="ProductValue" size="small" style="width:160px;" clearable placeholder="请选择产品">
        <el-option
          v-for="item in Product"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <el-button :disabled="loading" type="success" plain icon="el-icon-search" size="small" style="margin-left: 20px" @click="pageSize=10;pageList=1;searchTable()">查询</el-button>
    </el-card>

    <el-card>
      <div style="margin-top: 5px">
        <h4 style="margin: 10px;color: black">全部申请：</h4>
        <el-table
          v-loading="loading"
          :data="tableData"
          :header-cell-style="{background:'#F5F5F5'}"
          highlight-current-row
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
          tooltip-effect="dark"
          style="width: 100%;margin-top: 10px"
          height="500"
          border
          size="mini"
          @row-click="rowClick">
          <el-table-column align="center" label="产品名称" min-width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.产品名称 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="上传图片" min-width="90" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.url===0">——</span>
              <el-tooltip v-else class="item" effect="dark" content="点击预览，如需下载，可右键保存到本地" placement="top">
                <img :src="scope.row.url" style="height: 80px;width: 80px; margin: 2px auto;display: block" @click="showPicture(scope.row)">
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column align="center" label="管理员审核状态" min-width="90" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag v-if="scope.row.是否审核通过==='1'" type="success" size="small">已通过</el-tag>
              <el-tag v-if="scope.row.是否审核通过==='2'" type="danger" size="small">未通过</el-tag>
              <el-tag v-if="scope.row.是否审核通过==='0'" type="info" size="small">未审核</el-tag>
            </template>
          </el-table-column>
          <el-table-column align="center" label="处理结果" min-width="90" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag v-if="scope.row.是否处理==='1'" type="success" size="small">已通过</el-tag>
              <el-tag v-if="scope.row.是否处理==='2'" type="danger" size="small">未通过</el-tag>
              <el-tag v-if="!scope.row.是否处理" type="info" size="small">未审核</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            v-if="!loading"
            :current-page="pageList"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            :total="total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
        </div>
      </div>
    </el-card>

    <el-card>
      <div style="margin-top: 5px">
        <h4 style="margin: 10px;color: black">结果反馈：</h4>
        <el-table
          v-loading="loading2"
          :data="tableData2"
          :header-cell-style="{background:'#F5F5F5'}"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
          stripe
          tooltip-effect="dark"
          style="width: 100%;margin-top: 10px"
          height="500"
          border
          size="mini">
          <el-table-column align="center" label="反馈图片" min-width="90" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.url===0">——</span>
              <el-tooltip v-else class="item" effect="dark" content="点击预览，如需下载，可右键保存到本地" placement="top">
                <img :src="scope.row.url" style="height: 80px;width: 80px; margin: 2px auto;display: block" @click="showPicture(scope.row)">
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column align="center" label="问题反馈" min-width="90" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.问题反馈 }}
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            v-if="!loading2"
            :current-page="pageList2"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize2"
            :total="total2"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"/>
        </div>
      </div>
    </el-card>
    <el-dialog :visible.sync="dialogVisible2">
      <img :src="dialogImageUrl" width="100%" alt="">
    </el-dialog>
  </div>
</template>

<script>
import { ExecDatabase } from '@/main'
import { mapGetters } from 'vuex'
import { ImageUrl } from '@/utils/request'
export default {
  data() {
    return {
      ProductValue: '',
      Product: [],
      loading: false,
      tableData: [],
      total: 0, // 总条数
      pageSize: 10, // 每页显示条数
      pageList: 1, // 后台获取页
      dialogFormVisible: false,
      form: {
        问题描述: ''
      },
      rules: {
        问题描述: [{ required: true, message: '请输入问题描述', trigger: 'blur' }]
      },
      dialogVisible2: false,
      dialogImageUrl: '',
      loading2: false,
      tableData2: [],
      total2: 0, // 总条数
      pageSize2: 10, // 每页显示条数
      pageList2: 1 // 后台获取页
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'name',
      'id'
    ])
  },
  watch: {
    EnterpriseValue() {
      this.EnterpriseChange()
    },
    ProductValue(val) {
      this.productChange()
    }
  },
  created() {
    this.getProduct()
  },
  methods: {
    // 初始化获取产品
    getProduct() {
      this.ProductValue = ''
      this.Product = []
      var param = []
      param[0] = ['企业代码', this.id]
      var Data = this.CreateData('11', '基础数据_产品名称_查询数据', param)
      ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.Product.push({
            label: response.data[i].产品名称,
            value: response.data[i].产品代码
          })
        }
      }).then(() => {
        this.ProductValue = this.Product[0].value
      })
    },
    productChange() {
      if (this.ProductValue) {
        this.searchTable()
      } else {
        this.tableData = []
      }
    },
    // 查询
    searchTable() {
      this.loading = true
      this.tableData = []
      var param = []
      param[0] = ['产品代码', this.ProductValue]
      var Data = this.CreateData('11', '标签检测_企业审核状态查询_查询数据', param, this.pageSize, this.pageList)
      ExecDatabase(Data).then(response => {
        if (response.data.rows.length !== 0) {
          response.data.rows.map(v => {
            this.tableData.push({
              标签流水号: v.标签流水号,
              产品名称: v.产品名称,
              url: ImageUrl + v.图片保存名称 + '.' + v.suffix,
              是否审核通过: v.是否审核通过,
              是否处理: v.是否处理
            })
          })
        }
        this.total = response.data.total
        this.loading = false
      })
    },
    // 图片预览
    showPicture(row) {
      this.dialogImageUrl = row.url
      this.dialogVisible2 = true
    },
    rowClick(row) {
      this.loading2 = true
      this.tableData2 = []
      var param = []
      param[0] = ['标签流水号', row.标签流水号]
      var Data = this.CreateData('11', '标签检测_企业查看检测结果_查询数据', param, this.pageSize2, this.pageList2)
      ExecDatabase(Data).then(response => {
        if (response.data.rows.length !== 0) {
          response.data.rows.map(v => {
            if (v.图片保存名称 === null) {
              this.tableData2.push({
                是否通过: v.是否通过,
                操作时间: v.操作时间,
                问题反馈: v.问题反馈,
                url: 0
              })
            } else {
              this.tableData2.push({
                是否通过: v.是否通过,
                操作时间: v.操作时间,
                问题反馈: v.问题反馈,
                url: ImageUrl + v.图片保存名称 + '.' + v.suffix
              })
            }
          })
        }
        this.total2 = response.data.total
        this.loading2 = false
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pageList = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageList = val
      this.searchTable()
    },
    handleSizeChange2(val) {
      this.pageList2 = 1
      this.pageSize2 = val
      this.rowClick()
    },
    handleCurrentChange2(val) {
      this.pageList2 = val
      this.rowClick()
    }
  }
}
</script>

<style>
  .el-transfer-panel {
    width:300px;
  }
  .el-transfer-panel__body {
    height: 500px;
    width: 300px;
  }
  .el-transfer-panel__list {
    height: 500px;
    width: 300px;
  }
  .el-transfer-panel__list.is-filterable{
    height: 100%;
  }
  .el-card{
    margin-top: 5px;
  }
</style>
