<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业名称" prop="shopsName">
        <el-input
          v-model="queryParams.shopsName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业位置" prop="shopsAddress">
        <el-input
          v-model="queryParams.shopsAddress"
          placeholder="请输入企业位置"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="shopsStatus">
        <el-select v-model="queryParams.shopsStatus" placeholder="请选择审核状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.hj_exa_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="审核人" prop="reviewerName">-->
<!--        <el-input-->
<!--          v-model="queryParams.reviewerName"-->
<!--          placeholder="请输入审核人"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <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-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['shops:shops:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['shops:shops:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">

        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          :disabled="multiple"
          @click="handleUpDateOK"
        >批量通过</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleUpDateNO"
        >批量不通过</el-button>
      </el-col>


      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['shops:shops:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="shopsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="shopsId" />-->
      <el-table-column label="企业名称" align="center" prop="shopsName" />
      <el-table-column label="企业位置" align="center" prop="shopsAddress" />

      <el-table-column label="店铺电话" align="center" prop="shopsTel" />
      <el-table-column label="审核状态" align="center" prop="shopsStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hj_exa_status" :value="scope.row.shopsStatus"/>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateOK(scope.row)"
            v-hasPermi="['shops:shops:edit']"
          >审核通过</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateNO(scope.row)"
            v-hasPermi="['shops:shops:edit']"
          >审核不通过</el-button>

<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['shops:shops:edit']"-->
<!--          >修改</el-button>-->


          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['shops:shops:edit']"
          >查看详情</el-button>


<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['shops:shops: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"
    />

    <!-- 添加或修改店铺信息对话框 -->
    <el-dialog :title="title" :visible.sync="openShow" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业名称" prop="shopsName">
          <el-input v-model="form.shopsName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="企业位置" prop="shopsAddress">
          <el-input v-model="form.shopsAddress" placeholder="请输入企业位置" />
        </el-form-item>
        <el-form-item label="店铺优惠" prop="shopsDiscount">
          <el-input v-model="form.shopsDiscount" placeholder="请输入店铺优惠" />
        </el-form-item>
        <el-form-item label="店铺介绍" prop="shopsIntroduce">
          <el-input v-model="form.shopsIntroduce" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="经营许可证">
          <imageUpload v-model="form.shopsPic"/>
        </el-form-item>
        <el-form-item label="店铺电话" prop="shopsTel">
          <el-input v-model="form.shopsTel" placeholder="请输入店铺电话" />
        </el-form-item>
        <el-form-item label="店铺类型" prop="shopsType">
          <el-select v-model="form.shopsType" placeholder="请选择店铺类型">
            <el-option
              v-for="dict in dict.type.shops_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="审核状态" prop="shopsStatus">
          <el-select v-model="form.shopsStatus" placeholder="请选择审核状态">
            <el-option
              v-for="dict in dict.type.hj_exa_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="审核理由" prop="remark">
          <el-input v-model="form.remark"  type="textarea" placeholder="请输入备注" />
        </el-form-item>


        <el-form-item label="登录账号" prop="shopsTel">
          <el-input v-model="form.userLogin" placeholder="请输入店铺电话" />
        </el-form-item>
        <el-form-item label="法人姓名" prop="shopsTel">
          <el-input v-model="form.userName" placeholder="请输入店铺电话" />
        </el-form-item>
        <el-form-item label="法人电话" prop="shopsTel">
          <el-input v-model="form.userTel" placeholder="请输入店铺电话" />
        </el-form-item>

<!--        <el-form-item label="审核状态" prop="shopsStatus">-->
<!--          <el-select v-model="form.shopsStatus" placeholder="请选择审核状态">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.hj_exa_status"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="审核人" prop="reviewerName">-->
<!--          <el-input v-model="form.reviewerName" placeholder="请输入审核人" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



    <!-- 添加或修改店铺信息对话框 -->
    <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="remark">
          <el-input v-model="form.remark" placeholder="请输审核理由" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormOne">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!--
    批量审核通过对话框
          openhandleUpDateOK:false,
      openhandleUpDateNO:false,
      -->
    <el-dialog :title="title" :visible.sync="openhandleUpDateOK" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="审核理由" prop="remark">
          <el-input v-model="form.remark" placeholder="请输审核理由" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitHandleUpDateOKForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog :title="title" :visible.sync="openhandleUpDateNO" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="审核理由" prop="remark">
          <el-input v-model="form.remark" placeholder="请输审核理由" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitHandleUpDateNOForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listShops, getShops, delShops, addShops, updateShops, exportShops,handleUpDateOKShops } from "@/api/shops/shops";

export default {
  name: "Shops",
  dicts: ['hj_exa_status','shops_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺信息表格数据
      shopsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openhandleUpDateOK:false,
      openhandleUpDateNO:false,
      openShow:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopsName: null,
        shopsAddress: null,
        shopsStatus: null,
        reviewerName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询店铺信息列表 */
    getList() {
      this.loading = true;
      listShops(this.queryParams).then(response => {
        this.shopsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this. openhandleUpDateOK= false;
      this. openhandleUpDateNO= false;
      this.openShow=false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        shopsId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        shopsName: null,
        shopsAddress: null,
        shopsLng: null,
        shopsLat: null,
        shopsDiscount: null,
        shopsIntroduce: null,
        shopsPic: null,
        shopsTel: null,
        shopsStatus: null,
        shopsReviewer: null,
        reviewerTime: null,
        reviewerName: null,
        userLogin:null,
        shopsType:null,
        userName:null,
        userTel: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.shopsId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加店铺信息";
    },
    /** 修改按钮操作 */

    handleUpdateOK(row){
      this.reset();
      const shopsId = row.shopsId || this.ids
      this.open = true;
      this.title = "审核通过店铺信息";
      this.form.shopsId = shopsId;
      this.form.shopsStatus=2;
    },
    handleUpdateNO(row){
      this.reset();
      const shopsId = row.shopsId || this.ids
      this.open = true;
      this.title = "审核不通过店铺信息";
      this.form.shopsId = shopsId;
      this.form.shopsStatus=3;
    },
    handleUpdate(row) {
      this.reset();
      const shopsId = row.shopsId || this.ids
      getShops(shopsId).then(response => {
        this.form = response.data;
        this.openShow = true;
        this.title = "查看店铺信息";
      });
    },
    submitFormOne(){
      handleUpDateOKShops(this.form.shopsId,this.form).then(response => {
        this.$modal.msgSuccess("审核成功");
        this.open = false;
        this.openhandleUpDateOK= false;
        this.openhandleUpDateNO= false;
        this.openShow=false;
        this.reset();
        this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.shopsId != null) {
            updateShops(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addShops(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    formSubmit(){
      const shopsIds =  this.ids;
      console.log(this.ids)
      handleUpDateOKShops(shopsIds,this.form).then(response => {
        this.$modal.msgSuccess("批量审核成功");
        this.open = false;
        this.openhandleUpDateOK= false;
        this.openhandleUpDateNO= false;
        this.openShow=false;
        this.reset();
        this.getList();
      });
    },
    submitHandleUpDateNOForm(){
      this.form.shopsStatus=3;
      this.formSubmit()
    },
    submitHandleUpDateOKForm(){
      this.form.shopsStatus=2;
      this.formSubmit()
    },

    handleUpDateOK(row){

      this.reset();
      this.openhandleUpDateOK = true;
      this.title = "批量审核通过";
    },

    handleUpDateNO(){

      this.reset();
      this.openhandleUpDateNO = true;
      this.title = "批量审核拒绝";
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const shopsIds = row.shopsId || this.ids;
      this.$modal.confirm('是否确认删除店铺信息编号为"' + shopsIds + '"的数据项？').then(function() {
        return delShops(shopsIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有店铺信息数据项？').then(() => {
        this.exportLoading = true;
        return exportShops(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
