<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="68px"
      class="search-form"
    >
      <el-row :gutter="10" type="flex" class="search-form-left">
        <el-col :span="6">
          <el-form-item label="应用名" prop="appName">
            <el-input
              v-model="queryParams.appName"
              placeholder="请输入应用名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="模块名" prop="moduleName">
            <el-input
              v-model="queryParams.moduleName"
              placeholder="请输入模块名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="服务名" prop="serviceName">
            <el-input
              v-model="queryParams.serviceName"
              placeholder="请输入服务名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="备注" prop="memo">
            <el-input
              v-model="queryParams.memo"
              placeholder="请输入备注"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label-width="0" class="search-form-buttons">
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="openForm(undefined)"
          >新增</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="list"
      :stripe="true"
      :show-overflow-tooltip="true"
      border
    >
      <el-table-column label="应用名" align="center" prop="appName" />
      <el-table-column
        label="服务名"
        align="center"
        prop="serviceName"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <router-link
            :to="'/docking/docking-item?id=' + scope.row.id"
            class="link-type"
          >
            <span>{{ scope.row.serviceName }}</span>
          </router-link>
        </template></el-table-column
      >
      <el-table-column label="模块名" align="center" prop="moduleName" />
      <el-table-column
        label="备注"
        align="center"
        prop="memo"
        show-overflow-tooltip
      />
      <el-table-column label="是否启用" align="center" prop="isEnabled">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.MES_COMMON_STATUS"
            :value="scope.row.isEnabled"
          /> </template
      ></el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="160"
        class-name="small-padding fixed-width"
      >
        <template v-slot="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="openForm(scope.row.id)"
            >修改</el-button
          >
          <!-- v-hasPermi="['mes:system-docking-master:update']" -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            class="text-danger"
            :loading="deleteLoading"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
          <!-- v-hasPermi="['mes:system-docking-master:delete']" -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="viewDetail(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 对话框(添加 / 修改) -->
    <SystemDockingMasterForm ref="formRef" @success="getList" />
  </div>
</template>

<script>
import * as SystemDockingMasterApi from "@/api/system/dev/dockingMaster";
import SystemDockingMasterForm from "./SystemDockingMasterForm.vue";
import { DICT_TYPE } from "@/utils/dict";
export default {
  name: "SystemDockingMaster",
  components: {
    SystemDockingMasterForm,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 配置列表
      list: [],
      deleteLoading: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        appName: null,
        serviceName: null,
        suffix: null,
        pref: null,
        moduleName: null,
        memo: null,
        iUrl: null,
        isEnabled: null,
        isThird: null,
        createTime: [],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true;
        const res = await SystemDockingMasterApi.getSystemDockingMasterPage(
          this.queryParams
        );
        this.list = res.data.list;
        this.total = res.data.total;
      } finally {
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      this.loading = true;
      await this.$modal.confirm(
        '是否确认删除服务名为"' + row.serviceName + '"的数据项?'
      );
      try {
        await SystemDockingMasterApi.deleteSystemDockingMaster(id);
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } finally {
        this.loading = false;
      }
    },
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm("是否确认导出所有配置数据项?");
      try {
        this.exportLoading = true;
        const res = await SystemDockingMasterApi.exportSystemDockingMasterExcel(
          this.queryParams
        );
        this.$download.excel(res, "配置.xls");
      } finally {
        this.exportLoading = false;
      }
    },
    // 查看
    viewDetail(row) {
      const { id } = row;
      this.$router.push({
        path: "/docking/system-docking-detail",
        query: { id },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.search-form {
  display: flex;
  width: 100%;
  justify-content: space-between;
  margin-bottom: 10px;
  &-left {
    flex: 1;
  }
  &-buttons {
    flex-grow: 0;
    flex-shrink: 0;
    margin-left: 5px;
  }
}
</style>
