<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row class="last">
        <p><span>搜索条件</span> <i></i></p>
        <el-col :span="24">
          <el-col :span="8">
            <el-form-item label="企业名称" prop="name">
              <el-input
                v-model="queryParams.name"
                placeholder="请输入企业名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="唯一编码" prop="coding">
              <el-input
                v-model="queryParams.coding"
                placeholder="请输入唯一编码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
              <el-form-item label="法人名称" prop="legalPersonName">
                <el-input
                  v-model="queryParams.legalPersonName"
                  placeholder="请输入法人名称"
                  clearable
                  @keyup.enter.native="handleQuery"
                />
              </el-form-item>
          </el-col>
        </el-col>



        <el-col :span="8">
          <el-form-item label="证件号码" prop="legalPersonCard">
            <el-input
              v-model="queryParams.legalPersonCard"
              placeholder="请输入法人证件号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="联系号码" prop="phone">
            <el-input
              v-model="queryParams.phone"
              placeholder="请输入法人联系号码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="审核结果" prop="isAudit">
            <el-select v-model="queryParams.isAudit" placeholder="请选择审核结果，0: 未操作 1：不同意，2：同意" clearable>
              <el-option
                v-for="dict in dict.type.sys_replacement_result"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="审核意见" prop="auditOpinion">
            <el-input
              v-model="queryParams.auditOpinion"
              placeholder="请输入审核意见"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>

      </el-row>

    </el-form>


<div class="navde">
     <el-row :gutter="10" class="mb8">
       <p><span>企业申请</span> <i></i></p>
    <!-- <el-col :span="1.5">
      <el-button
        type="success"
        plain
        icon="el-icon-edit"
        size="mini"
        :disabled="single"
        @click="handleUpdate"
        v-hasPermi="['system:apply:edit']"
      >同意</el-button>
    </el-col> -->
    <el-col :span="1.5">
      <el-button
        type="danger"
        plain
        icon="el-icon-delete"
        size="mini"
        :disabled="multiple"
        @click="handleDelete"
        v-hasPermi="['system:apply:remove']"
      >删除</el-button>
    </el-col>
    <el-col :span="1.5">
      <el-button
        type="warning"
        plain
        icon="el-icon-download"
        size="mini"
        @click="handleExport"
        v-hasPermi="['system:apply:export']"
      >导出</el-button>
    </el-col>
    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  </el-row>

  <el-table v-if="kdie" v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55" align="center" />
    <el-table-column label="企业名称" align="center" prop="name" />
    <el-table-column label="唯一编码" align="center" prop="coding" />
    <el-table-column label="法人名称" align="center" prop="legalPersonName" />
    <el-table-column label="证件类型" align="center" prop="cardType" />
    <el-table-column label="法人证件号" align="center" prop="legalPersonCard" width="180"/>
    <el-table-column label="法人联系号码" align="center" prop="phone" width="120"/>
    <el-table-column label="审核结果" align="center" prop="isAudit">
      <template slot-scope="scope">
        <dict-tag :options="dict.type.sys_replacement_result" :value="scope.row.isAudit"/>
      </template>
    </el-table-column>
    <el-table-column label="审核意见" align="center" prop="auditOpinion" />


    <el-table-column label="备注" align="center" prop="remark" />
    <el-table-column label="查看图片" align="center" class-name="small-padding fixed-width" width="100">
       <template slot-scope="scope">
         <!-- <image-preview :src="scope.row.enterprisePhotoList" :width="100" :height="100"/> -->
       <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.url"
            :preview-src-list="scope.row.uif"
           >
          </el-image>
           <!-- :preview-src-list="uif" -->
       </template>
    </el-table-column>
    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="text"
          icon="el-icon-edit"
          @click="handleUpdate(scope.row)"
          v-hasPermi="['system:apply:edit']"
        >同意</el-button>
        <el-button
          size="mini"
          type="text"
          icon="el-icon-delete"
          @click="handleDeletes(scope.row)"
          v-hasPermi="['system:apply:remove']"
        >驳回</el-button>
       <!-- <el-button
          size="mini"
          type="text"
          icon="el-icon-delete"
          @click="handleDelete(scope.row)"
          v-hasPermi="['system:apply:remove']"
        >删除</el-button> -->
      </template>
    </el-table-column>
  </el-table>

  <pagination
    v-show="total>0"
    :total="total"
    :page.sync="queryParams.pageNum"
    :limit.sync="queryParams.pageSize"
    @pagination="getList"
  />
</div>


    <!-- 添加或修改企业信息审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="唯一编码" prop="coding">
          <el-input v-model="form.coding" placeholder="请输入唯一编码" />
        </el-form-item>
        <el-form-item label="法人名称" prop="legalPersonName">
          <el-input v-model="form.legalPersonName" placeholder="请输入法人名称" />
        </el-form-item>
        <el-form-item label="法人证件号" prop="legalPersonCard">
          <el-input v-model="form.legalPersonCard" placeholder="请输入法人证件号" />
        </el-form-item>
        <el-form-item label="法人联系号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入法人联系号码" />
        </el-form-item>
        <el-form-item label="审核结果" prop="isAudit">
          <el-select v-model="form.isAudit" placeholder="请选择审核结果，0: 未操作 1：不同意，2：同意">
            <el-option
              v-for="dict in dict.type.sys_replacement_result"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核意见" prop="auditOpinion">
          <el-input v-model="form.auditOpinion" placeholder="请输入审核意见" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApply, getApply, delApply, addApply, updateApply } from "@/api/system/apply";
const defaultSettings = require("@/settings.js");
export default {
  name: "Apply",
  dicts: ['sys_replacement_result'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      process: process.env.VUE_APP_BASE_API,
      // 总条数
      total: 0,
      // 企业信息审核表格数据
      applyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        coding: null,
        legalPersonName: null,
        cardType: null,
        legalPersonCard: null,
        phone: null,
        isAudit: null,
        auditOpinion: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      url:'',
      kdie:false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业信息审核列表 */
    getList() {
      this.loading = true;
      listApply(this.queryParams).then(response => {

        response.rows.filter(router =>{
          router.uif = []
          router.url = defaultSettings.urls   + router.enterprisePhotoList[0].path
          console.log(this.url)
          if(router.enterprisePhotoList !== null){
            router.enterprisePhotoList.filter(rou =>{
              rou.path = defaultSettings.urls + rou.path
               router.uif.push(rou.path)
               console.log(router.uif)
            })
          }

        })
        this.applyList = response.rows;
        this.kdie = true
        console.log(this.applyList)
        console.log(this.applyList[0].uif)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        coding: null,
        legalPersonName: null,
        cardType: null,
        legalPersonCard: null,
        phone: null,
        isAudit: null,
        auditOpinion: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业信息审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const ids = row.id || this.ids;
      let dnhs = {'id':ids,'isAudit':1}
      this.$modal.confirm('是否确认同意申请？').then(function() {
        return updateApply(dnhs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
      // this.reset();
      // const id = row.id || this.ids
      // getApply(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改企业信息审核";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateApply(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApply(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除企业信息审核编号为"' + ids + '"的数据项？').then(function() {
        return delApply(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 驳回按钮操作 */
    handleDeletes(row) {
      const ids = row.id || this.ids;
      let dnhs = {'id':ids,'isAudit':2}
      this.$prompt('请输入驳回意见', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
              }).then(({ value }) => {
                dnhs.auditOpinion = value
                updateApply(dnhs);
                 this.getList();
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '取消输入'
                });
              });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/apply/export', {
        ...this.queryParams
      }, `apply_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
