<template>
  <div class="pl">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="search">
        <el-form ref="queryFormRef" :model="queryParams" :inline="true">
          <el-form-item label="模板名称" prop="phone">
            <el-input v-model="queryParams.templateName" placeholder="请输入模板名称" clearable @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="模板编号" prop="phone">
            <el-input v-model="queryParams.templatecode" placeholder="请输入模板编码" clearable @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="类型" prop="phone">
            <el-select v-model="queryParams.templateType" placeholder="请选择类型">
              <el-option label="通知" value="0" />
              <el-option label="公告" value="1" />
            </el-select>
          </el-form-item>
          <el-form-item label="状态" prop="phone">
            <el-select v-model="queryParams.status" placeholder="请选择类型">
              <el-option label="停用" value="1" />
              <el-option label="正常" value="0" />
            </el-select>
          </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-button type="primary" @click="showRefuteDialog = true">新增</el-button>
      </div>
    </transition>
    <el-table
      ref="categoryTableRef"
      :data="messList"
      row-key="categoryId"
      border
      :default-expand-all="isExpandAll"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column label="id" prop="id" align="center" width="150" />
      <el-table-column label="模板名称" prop="templateName" align="center" width="150" />
      <el-table-column label="模板名称" prop="templateName" align="center" width="150" />
      <el-table-column label="模版类型" prop="templateType" align="center" width="150">
        <template #default="{ row }">
          {{ row.templateType == 1 ? '公告' : '通知' }}
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="status" align="center" width="150">
        <template #default="{ row }">
          {{ row.status == 1 ? '停用' : '正常' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <!-- <el-tooltip content="审核" placement="top">
            <el-button link type="primary" @click="handleAdd(scope.row)" v-hasPermi="['workflow:video:add']">审核</el-button>
          </el-tooltip>-->
          <el-tooltip content="删除" placement="top">
            <el-button link type="primary" v-hasPermi="['workflow:video:remove']">删除</el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <pagination v-if="total > 0" :total="total" v-model:page="queryParams.current" v-model:limit="queryParams.size" @pagination="getlist" />
    </div>
    <el-dialog v-model="showRefuteDialog" title="消息发送">
      <el-form :model="dataparams" :rules="rules">
        <el-form-item label="模板类型">
          <el-select v-model="dataparams.templateType" placeholder="请选择类型">
            <el-option label="通知" value="0" />
            <el-option label="公告" value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="模板编码">
          <el-input v-model="dataparams.templateCode" placeholder="模板编码" />
        </el-form-item>
        <el-form-item label="模板名称">
          <el-input v-model="dataparams.templateName" placeholder="模板名称" />
        </el-form-item>
        <el-form-item label="模板标题">
          <el-input v-model="dataparams.title" placeholder="模板标题" />
        </el-form-item>
        <el-form-item label="模板内容">
          <el-input v-model="dataparams.templateContent" placeholder="模板内容" />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <!-- <el-button @click="showRefuteDialog = false">取消</el-button> -->
          <el-button type="primary" @click="cilcikgAdd">发送</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Leave" lang="ts">
import { listtemplate, templateAdd } from '@/api/set/messageindex';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const showSearch = ref(true);
const queryFormRef = ref<ElFormInstance>();
import { LeaveForm, AccountQuery, AccountOV, paramsaccountOV } from '@/api/set/messagetype';
const data = reactive<PageData<LeaveForm, AccountQuery>>({
  form: {},
  queryParams: {
    current: 1,
    size: 10,
    templateName: undefined,
    templatecode: undefined,
    templateType: undefined,
    status: undefined
  },
  rules: {}
});
const isExpandAll = ref(true);
const { queryParams } = toRefs(data);
const messList = ref<AccountOV[]>([]);
const total = ref(0);
const showRefuteDialog = ref<boolean>(false);
const logmess = ref<boolean>(false);
const getlist = async () => {
  const res = await listtemplate(queryParams.value);
  console.log(res);
  if (res.code == 200) {
    messList.value = res.data.records;
    total.value = res.data.total;
  }
};
const dataparams = ref<paramsaccountOV>({
  templateType: null,
  templateCode: null,
  templateName: null,
  templateContent: null,
  title: null
});
const rules = reactive({
  templateType: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  templateCode: [{ required: true, message: '请输入备注内容', trigger: 'blur' }],
  templateName: [{ required: true, message: '请输入内容', trigger: 'blur' }],
  templateContent: [{ required: true, message: '请输入内容', trigger: 'blur' }],
  title: [{ required: true, message: '请输入标题内容', trigger: 'blur' }]
});
const handleQuery = () => {
  getlist();
};
const resetQuery = () => {
  queryParams.value = {
    templateType: undefined,
    status: undefined,
    templateName: undefined,
    templatecode: undefined,
    current: 1,
    size: 10
  };
  getlist();
};
const formRef = ref<ElFormInstance>();

const cilcikgAdd = async () => {
  const res = await templateAdd(dataparams.value);
  if (res.code == 200) {
    showRefuteDialog.value = false;
    getlist();
  }
};
onMounted(() => {
  getlist();
});
</script>
