<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>
            <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="发送者ID" prop="senderId" align="center" width="150" />
      <el-table-column label="标题" prop="title" align="center" width="150" />
      <el-table-column label="内容" prop="content" align="center" width="150" />
      <el-table-column label="创建时间" prop="createTime" align="center" width="250" />
      <el-table-column label="定时发送时间" prop="scheduledTime" align="center" width="250" />
      <el-table-column label="消息类型" prop="title" align="center" width="150">
        <template #default="{ row }">
          {{ row.msgType == 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-input v-model="dataparams.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="指定">
          <el-button @click="logmess = false" :style="{ background: logmess == false ? '#FFB6C1' : '' }">{{ '指定角色' }}</el-button>
          <el-button @click="logmess = true" :style="{ background: logmess == true ? '#FFB6C1' : '' }">{{ '指定具体人' }}</el-button>
        </el-form-item>
        <el-form-item label="发送手机号" v-show="logmess == true">
          <el-input v-model="dataparams.sendScope" placeholder="请输入要送的手机号" />
        </el-form-item>
        <el-form-item label="发送部分" v-show="logmess == false">
          <el-select v-model="dataparams.sendScope" placeholder="请选择类型">
            <el-option v-for="(item, index) in sendScopelist" :label="item.label" :value="item.value" :key="index" />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="类型">
          <el-select v-model="dataparams.msgType" placeholder="请选择类型">
            <el-option v-for="(item, index) in select" :label="item.label" :value="item.value" :key="index" />
          </el-select>
        </el-form-item> -->
        <el-form-item label="内容">
          <Editor v-model="dataparams.content" placeholder="请输入内容" type="url"></Editor>
        </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 { listlist, listAdd } from '@/api/set/messageindex';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const showSearch = ref(true);
const queryFormRef = ref<ElFormInstance>();
import { LeaveForm, LeaveQuery, LeaveVO, LeaveListVO } from '@/api/set/messagetype';
const data = reactive<PageData<LeaveForm, LeaveQuery>>({
  form: {},
  queryParams: {
    current: 1,
    size: 10,
    startLeaveDays: undefined,
    endLeaveDays: undefined
  },
  rules: {}
});
const isExpandAll = ref(true);
const { queryParams } = toRefs(data);
const messList = ref<LeaveVO[]>([]);
const total = ref(0);
const showRefuteDialog = ref<boolean>(false);
const logmess = ref<boolean>(false);
const getlist = async () => {
  const res = await listlist(queryParams.value);
  console.log(res);
  if (res.code == 200) {
    messList.value = res.data.records;
    total.value = res.data.total;
  }
};
const dataparams = ref<LeaveListVO>({
  content: null,
  title: null,
  sendScope: null
});
const rules = reactive({
  title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  // msgType: [{ required: true, message: '请选择类型', trigger: 'change' }],
  content: [{ required: true, message: '请输入备注内容', trigger: 'blur' }],
  model: [{ required: true, message: '请输入 model 内容', trigger: 'blur' }]
});
const select = ref([
  { label: '自动', value: 0 },
  { label: '手动', value: 1 }
]);
const handleQuery = () => {};
const resetQuery = () => {};
const formRef = ref<ElFormInstance>();
const sendScopelist = ref([
  { label: '全部', value: 'all' },
  { label: '达人', value: 'expert' },
  { label: '商户', value: 'merchant' },
  { label: '用户', value: 'user' }
]);
//发送消息
const cilcikgAdd = async () => {
  const res = await listAdd(dataparams.value);
  if (res.code == 200) {
    // dataparams.value = {
    //   content: undefined,
    //   title: undefined,
    //   msgType: undefined,
    // }
    showRefuteDialog.value = false;
    getlist();
  }
};
onMounted(() => {
  getlist();
});
</script>
