<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true">
        <el-form-item label="行业名称">
          <el-input placeholder="请输入" v-model="queryParams.name" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @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
              @click="open = true;openForm = {name: ''};"
              icon="Plus"
          >新增</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="list" show-overflow-tooltip style="width: 100%;">
        <el-table-column label="行业名称" prop="name" />
        <el-table-column label="创建时间" prop="createTime" align="center" width="160"/>
        <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width" >
          <template #default="{row}">
            <el-button link type="primary" icon="Edit" @click="open=true;openForm={
                name: row.name,
                id: row.id,
            }">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize" @pagination="getList" />
      <!-- 添加或修改账号问答框 -->
      <el-dialog title="新增企业" v-model="open" width="400px" append-to-body>
        <el-form label-width="80px">
          <el-form-item label="行业名称" prop="name">
            <el-input v-model="openForm.name" placeholder="请输入姓名"/>
          </el-form-item>
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button type="primary" @click="submit">提 交</el-button>
            <el-button @click="open = false">取 消</el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </template>
  
  <script setup>
  import { orgList,orgSave } from "@/api/industry";
  import { ref } from "vue";
  const { proxy } = getCurrentInstance();
  const list = ref([]);
  const loading = ref(false);
  const total = ref(0);
  const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
  })
  const open = ref(false);
  const openForm = ref({
    name: '',
  })
  /** 查询列表 */
  function getList() {
    const form = { ...queryParams.value }
    if (form.time && form.time.length == 2) {
      form.startTime = form.time[0] + ' 00:00:00'
      form.endTime = form.time[1] + ' 23:59:59'
    }
    delete form.time;
    loading.value = true;
    orgList(form).then(res => {
      list.value = res.data.list;
      total.value = res.data.total;
      loading.value = false;
    });
  }
  function submit() {
    if (!openForm.value.name) {
      return proxy.$modal.msgError("请输入行业名称");
    }
    orgSave(openForm.value).then(res => {
      proxy.$modal.msgSuccess("操作成功");
      open.value = false;
      getList();
    })
  }
  
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    queryParams.value.pageSize = 10;
    getList();
  }
  /** 重置按钮操作 */
  function resetQuery() {
    queryParams.value = {
      pageNum: 1,
      pageSize: 10,
    }
    handleQuery();
  }
  getList();
  </script>
  <style lang="scss" scoped>
  .el-dialog .el-dialog__body {
    max-height: 650px;
  }
  </style>