<template>
  <div class="export">
    <normal-page-index>
      <template v-slot:headerdataarea>
        <!--搜索-->
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item prop="content">
            <el-input
              v-model="queryParams.content"
              placeholder="请输入关键字"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="cyan" 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="warning"
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['system:price:export']"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getMainPageTableListData"></right-toolbar>
        </el-row>
      </template>

      <template v-slot:maindataarea>
        <el-table v-loading="mainPageObj.loading" :data="mainPageObj.tableDataList" border>
          <el-table-column label="序号" align="center" type="index" :show-overflow-tooltip="true" />
          <el-table-column
            label="店铺名称"
            align="center"
            prop="shopName"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="法人/负责人"
            align="center"
            prop="legalPerson"
            :show-overflow-tooltip="true"
          />
          <el-table-column label="联系人" align="center" prop="contact" :show-overflow-tooltip="true" />
          <el-table-column label="联系电话" align="center" prop="phone" :show-overflow-tooltip="true" />
          <el-table-column
            label="操作"
            align="center"
            width="180"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="handleView(scope.row)">查看</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:price:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="mainPageObj.total>0"
          :total="mainPageObj.total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getMainPageTableListData"
        />
      </template>
    </normal-page-index>

    <!-- 查看详情弹框界面 -->
    <comm-dialog-table-page
      :dialogTitle="viewDialogObj.title"
      :isVisibleDialog="viewDialogObj.open"
      :fieldList="viewDialogObj.fieldList"
      :fieldLableObj="viewDialogObj.fieldLableObj"
      :fieldValueObj="viewDialogObj.fieldValueObj"
      @custCommDialogTablePageClose="handleViewDialogCloseClick"
    ></comm-dialog-table-page>
  </div>
</template>

<script>
import {
  exportListData,
  exportViewData,
  exportDeleteData,
  exportExportData
} from "@/api/excle/export";

export default {
  name: "export",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        content: ''
      },
      /**主页面对象 */
      mainPageObj: {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 表格数据
        tableDataList: [],
      },
      /** 查看弹框对象 */
      viewDialogObj: {
        title: "",
        open: false,
        fieldList: [
          'shopName',
          'legalPerson',
          'contact',
          'phone',
          'license',
          'cutOff',
          'taxpayerCode',
          'creditCode',
          'address',
          'businessScope',
          'longitude',
          'latitude'
        ],
        fieldLableObj: {
          'shopName': '店铺名称',
          'legalPerson': '法人/负责人',
          'contact': '联系人',
          'phone': '联系电话',
          'license': '生产/经验许可证号',
          'cutOff': '经营有效期止',
          'taxpayerCode': '纳税人识别号',
          'creditCode': '统一社会信用代码',
          'address': '地址',
          'businessScope': '经营范围',
          'longitude': '经度',
          'latitude': '纬度'
        },
        fieldValueObj: {}
      }
    };
  },
  created() {
    this.initData();
  },
  methods: {
    /** 初始化数据 */
    initData() {
      this.getMainPageTableListData();
    },
    /** 查询数据列表 */
    getMainPageTableListData() {
      this.mainPageObj.loading = true;
      exportListData(this.queryParams).then(
        (response) => {
          this.mainPageObj = {
            ...this.mainPageObj,
            tableDataList: response.rows || [],
            total: response.total || 0,
            loading: false
          };
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getMainPageTableListData();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查看按钮事件 */
    handleView(row) {
      exportViewData(row.id).then((response) => {
        this.viewDialogObj = {
          ...this.viewDialogObj,
          fieldValueObj: Object.assign(((response.rows || []).length > 0) ? (response.rows || [])[0] : {}),
          title: '查看',
          open: true
        };
      });
    },
    /** 查看弹框之关闭按钮事件 */
    handleViewDialogCloseClick() {
      this.viewDialogObj = {
        ...this.viewDialogObj,
        fieldValueObj: {},
        title: '',
        open: false
      };
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm(
        '是否确认删除店铺名称为“' + row.shopName + '”的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        return exportDeleteData(row.id);
      }).then(() => {
        this.getMainPageTableListData();
        this.msgSuccess("删除成功");
      }).catch(() => {
        this.msgWarning('您取消了删除数据操作！');
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出当前关键字过滤的数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "info",
      }).then(() => {
        return exportExportData(this.queryParams.content);
      }).then((response) => {
        this.download(response.msg);
      }).catch(() => {
        this.msgWarning('您取消了导出数据操作！');
      });
    }
  }
};
</script>
