<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      v-show="showSearch"
      :inline="true"
    >
      <el-form-item label="活动名称" prop="researchName">
        <el-input
          v-model="queryParams.researchName"
          placeholder="请输入活动名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="活动状态" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择">
          <el-option label="未开始" value="1"></el-option>
          <el-option label="进行中" value="2"></el-option>
          <el-option label="已结束" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="数据编号" prop="researchId" />
      <el-table-column
        label="活动名称"
        prop="researchName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="活动报名截止时间"
        align="center"
        prop="createTime"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动开始时间" align="center" prop="createTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动结束时间" align="center" prop="createTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="活动报名时间" align="center" prop="createTime">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <el-tag type="info">未开始</el-tag>
          <el-tag type="success">进行中</el-tag>
          <el-tag type="danger">已结束</el-tag>
        </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="750px" append-to-body>
      <el-form ref="roleRef" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="活动名称:" prop="name">
          <el-input v-model="form.name" placeholder="请输入活动名称" />
        </el-form-item>
        <el-form-item label="联系人:">
          <el-input v-model="form.username" placeholder="请输入专家姓名" />
        </el-form-item>
        <el-form-item label="联系电话:">
          <el-input v-model="form.phone" placeholder="默认专家电话" />
        </el-form-item>

        <div class="hide_required">
          <CityOptions v-model="form" :labelWidth="100" :is_required="false" />
        </div>

        <div class="hide_required">
          <FieldSingle v-model="form" :labelWidth="100" />
        </div>

        <el-form-item label="合作模式:" prop="mode">
          <el-input v-model="form.mode" />
        </el-form-item>
        <el-form-item label="合作内容:" prop="describe">
          <el-input
            v-model="form.describe"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 6 }"
            placeholder="请输入想要合作的需求"
          ></el-input>
        </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>
import CityOptions from "@/views/identity/components/CityOptions";
import FieldSingle from "@/views/identity/components/FieldSingle";
import {
  addRole,
  changeRoleStatus,
  dataScope,
  delRole,
  getRole,
  listRole,
  updateRole,
} from "@/api/system/role";
import {
  roleMenuTreeselect,
  treeselect as menuTreeselect,
} from "@/api/system/menu";
import {
  treeselect as deptTreeselect,
  roleDeptTreeselect,
} from "@/api/system/dept";

const router = useRouter();
const { proxy } = getCurrentInstance();

const dataList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const title = ref("");

const formData = reactive({
  industrys: [],
});

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    researchName: undefined,
    type: undefined,
  },
  rules: {
    name: [{ required: true, message: "活动名称不能为空", trigger: "blur" }],
    mode: [{ required: true, message: "合作模式不能为空", trigger: "blur" }],
    describe: [
      { required: true, message: "合作内容不能为空", trigger: "blur" },
    ],
  },
});

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

/** 查询数据列表 */
function getList() {
  loading.value = true;
  dataList.value = [1];
  total.value = 15;
  loading.value = false;
  // listRole(queryParams.value).then(
  //   (response) => {
  //     dataList.value = response.rows;
  //     total.value = response.total;
  //     loading.value = false;
  //   }
  // );
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 删除按钮操作 */
function handleDelete(row) {
  proxy.$modal
    .confirm('是否确认删除数据编号为"' + row.id + '"的数据项?')
    .then(function () {
      return delRole(researchIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}

/** 重置新增的表单以及其他数据  */
function reset() {
  form.value = {
    id: undefined,
    name: undefined,
    username: undefined,
    phone: undefined,
    industrys: [],

    mode: undefined,
    describe: undefined,
  };
  proxy.resetForm("roleRef");
}
/** 添加数据 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加数据";
}
/** 修改数据 */
function handleUpdate(row) {
  reset();
  form.value = Object.assign({}, row);
  open.value = true;
  title.value = "修改数据";
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["roleRef"].validate((valid) => {
    if (valid) {
      console.log(form.value);
      // if (form.value.researchId != undefined) {
      //   updateRole(form.value).then((response) => {
      //     proxy.$modal.msgSuccess("修改成功");
      //     open.value = false;
      //     getList();
      //   });
      // } else {
      //   addRole(form.value).then((response) => {
      //     proxy.$modal.msgSuccess("新增成功");
      //     open.value = false;
      //     getList();
      //   });
      // }
    }
  });
}
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

getList();
</script>
