<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="年份" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入年份"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校编码" prop="collegeCode">
        <el-input
          v-model="queryParams.collegeCode"
          placeholder="请输入学校编码"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校名称" prop="collegeName">
        <el-input
          v-model="queryParams.collegeName"
          placeholder="请输入学校名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编辑" prop="editor">
        <el-input
          v-model="queryParams.editor"
          placeholder="请输入编辑"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="summary" prop="summary">
        <el-input
          v-model="queryParams.summary"
          placeholder="请输入summary"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="isArt" prop="isArt">
        <el-input
          v-model="queryParams.isArt"
          placeholder="请输入isArt"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="元数据描述" prop="metaDescription">
        <el-input
          v-model="queryParams.metaDescription"
          placeholder="请输入元数据描述"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="tags" prop="tags">
        <el-input
          v-model="queryParams.tags"
          placeholder="请输入tags"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否显示" prop="isShow">
        <el-select v-model="queryParams.isShow" placeholder="请选择是否显示" clearable>
          <el-option
            v-for="dict in bool_values"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="点击量" prop="hits">
        <el-input
          v-model="queryParams.hits"
          placeholder="请输入点击量"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="元数据关键词" prop="metaKeywords">
        <el-input
          v-model="queryParams.metaKeywords"
          placeholder="请输入元数据关键词"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排名" prop="rank">
        <el-input
          v-model="queryParams.rank"
          placeholder="请输入排名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型名称" prop="typeName">
        <el-input
          v-model="queryParams.typeName"
          placeholder="请输入类型名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择创建日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建日期" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择创建日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="数据库创建日期" prop="createTime2">
        <el-date-picker clearable
          v-model="queryParams.createTime2"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择数据库创建日期">
        </el-date-picker>
      </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
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['system:bBusiWishUniversitiesEnrollBrochure:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:bBusiWishUniversitiesEnrollBrochure:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:bBusiWishUniversitiesEnrollBrochure:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['system:bBusiWishUniversitiesEnrollBrochure:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bBusiWishUniversitiesEnrollBrochureList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="年份" align="center" prop="year" />
      <el-table-column label="学校编码" align="center" prop="collegeCode" />
      <el-table-column label="学校名称" align="center" prop="collegeName" />
      <el-table-column label="编辑" align="center" prop="editor" />
      <el-table-column label="summary" align="center" prop="summary" />
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="isArt" align="center" prop="isArt" />
      <el-table-column label="类型" align="center" prop="type" />
      <el-table-column label="元数据描述" align="center" prop="metaDescription" />
      <el-table-column label="简章内容" align="center" prop="content" />
      <el-table-column label="tags" align="center" prop="tags" />
      <el-table-column label="是否显示" align="center" prop="isShow">
        <template #default="scope">
          <dict-tag :options="bool_values" :value="scope.row.isShow"/>
        </template>
      </el-table-column>
      <el-table-column label="点击量" align="center" prop="hits" />
      <el-table-column label="链接" align="center" prop="url" />
      <el-table-column label="元数据关键词" align="center" prop="metaKeywords" />
      <el-table-column label="排名" align="center" prop="rank" />
      <el-table-column label="类型名称" align="center" prop="typeName" />
      <el-table-column label="创建日期" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建日期" align="center" prop="updateTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据库创建日期" align="center" prop="createTime2" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime2, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:bBusiWishUniversitiesEnrollBrochure:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:bBusiWishUniversitiesEnrollBrochure:remove']">删除</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="title" v-model="open" width="500px" append-to-body>
      <el-form ref="bBusiWishUniversitiesEnrollBrochureRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="年份" prop="year">
          <el-input v-model="form.year" placeholder="请输入年份" />
        </el-form-item>
        <el-form-item label="学校编码" prop="collegeCode">
          <el-input v-model="form.collegeCode" placeholder="请输入学校编码" />
        </el-form-item>
        <el-form-item label="学校名称" prop="collegeName">
          <el-input v-model="form.collegeName" placeholder="请输入学校名称" />
        </el-form-item>
        <el-form-item label="编辑" prop="editor">
          <el-input v-model="form.editor" placeholder="请输入编辑" />
        </el-form-item>
        <el-form-item label="summary" prop="summary">
          <el-input v-model="form.summary" placeholder="请输入summary" />
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="isArt" prop="isArt">
          <el-input v-model="form.isArt" placeholder="请输入isArt" />
        </el-form-item>
        <el-form-item label="元数据描述" prop="metaDescription">
          <el-input v-model="form.metaDescription" placeholder="请输入元数据描述" />
        </el-form-item>
        <el-form-item label="简章内容">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="tags" prop="tags">
          <el-input v-model="form.tags" placeholder="请输入tags" />
        </el-form-item>
        <el-form-item label="是否显示" prop="isShow">
          <el-select v-model="form.isShow" placeholder="请选择是否显示">
            <el-option
              v-for="dict in bool_values"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="点击量" prop="hits">
          <el-input v-model="form.hits" placeholder="请输入点击量" />
        </el-form-item>
        <el-form-item label="链接" prop="url">
          <el-input v-model="form.url" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="元数据关键词" prop="metaKeywords">
          <el-input v-model="form.metaKeywords" placeholder="请输入元数据关键词" />
        </el-form-item>
        <el-form-item label="排名" prop="rank">
          <el-input v-model="form.rank" placeholder="请输入排名" />
        </el-form-item>
        <el-form-item label="类型名称" prop="typeName">
          <el-input v-model="form.typeName" placeholder="请输入类型名称" />
        </el-form-item>
        <el-form-item label="数据库创建日期" prop="createTime2">
          <el-date-picker clearable
            v-model="form.createTime2"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择数据库创建日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="BBusiWishUniversitiesEnrollBrochure">
import { listBBusiWishUniversitiesEnrollBrochure, getBBusiWishUniversitiesEnrollBrochure, delBBusiWishUniversitiesEnrollBrochure, addBBusiWishUniversitiesEnrollBrochure, updateBBusiWishUniversitiesEnrollBrochure } from "@/api/system/bBusiWishUniversitiesEnrollBrochure"

const { proxy } = getCurrentInstance()
const { bool_values } = proxy.useDict('bool_values')

const bBusiWishUniversitiesEnrollBrochureList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    year: null,
    collegeCode: null,
    collegeName: null,
    editor: null,
    summary: null,
    title: null,
    isArt: null,
    type: null,
    metaDescription: null,
    content: null,
    tags: null,
    isShow: null,
    hits: null,
    url: null,
    metaKeywords: null,
    rank: null,
    typeName: null,
    createTime: null,
    updateTime: null,
    createTime2: null
  },
  rules: {
    collegeCode: [
      { required: true, message: "学校编码不能为空", trigger: "blur" }
    ],
    collegeName: [
      { required: true, message: "学校名称不能为空", trigger: "blur" }
    ],
    editor: [
      { required: true, message: "编辑不能为空", trigger: "blur" }
    ],
    summary: [
      { required: true, message: "summary不能为空", trigger: "blur" }
    ],
    title: [
      { required: true, message: "标题不能为空", trigger: "blur" }
    ],
    type: [
      { required: true, message: "类型不能为空", trigger: "change" }
    ],
    isShow: [
      { required: true, message: "是否显示不能为空", trigger: "change" }
    ],
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询院校简章大纲列表 */
function getList() {
  loading.value = true
  listBBusiWishUniversitiesEnrollBrochure(queryParams.value).then(response => {
    bBusiWishUniversitiesEnrollBrochureList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    year: null,
    collegeCode: null,
    collegeName: null,
    editor: null,
    summary: null,
    title: null,
    isArt: null,
    type: null,
    metaDescription: null,
    content: null,
    tags: null,
    isShow: null,
    hits: null,
    url: null,
    metaKeywords: null,
    rank: null,
    typeName: null,
    createTime: null,
    updateTime: null,
    createTime2: null
  }
  proxy.resetForm("bBusiWishUniversitiesEnrollBrochureRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加院校简章大纲"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getBBusiWishUniversitiesEnrollBrochure(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改院校简章大纲"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["bBusiWishUniversitiesEnrollBrochureRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateBBusiWishUniversitiesEnrollBrochure(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addBBusiWishUniversitiesEnrollBrochure(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除院校简章大纲编号为"' + _ids + '"的数据项？').then(function() {
    return delBBusiWishUniversitiesEnrollBrochure(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/bBusiWishUniversitiesEnrollBrochure/export', {
    ...queryParams.value
  }, `bBusiWishUniversitiesEnrollBrochure_${new Date().getTime()}.xlsx`)
}

getList()
</script>
