<template>
  <div>
    <el-form :model="form" inline>
      <el-form-item label="账号类型">
        <el-select v-model="form.accountType" placeholder="类型">
          <el-option label="企微内部账号" :value="1" />
          <el-option label="企微应用" :value="2" />
          <el-option label="pywechat 个人号" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="渠道">
        <el-input v-model="form.channelType" placeholder="wecom" />
      </el-form-item>
      <el-form-item label="账号ID">
        <el-input v-model="form.accountId" placeholder="账号唯一标识" />
      </el-form-item>
      <el-form-item label="名称">
        <el-input v-model="form.accountName" placeholder="名称" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleCreate">创建</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="accounts" border>
      <el-table-column prop="id" label="ID" width="80" />
      <el-table-column prop="accountType" label="类型" />
      <el-table-column prop="channelType" label="渠道" />
      <el-table-column prop="accountId" label="账号ID" />
      <el-table-column prop="accountName" label="名称" />
      <el-table-column prop="loginStatus" label="登录状态" />
      <el-table-column prop="onlineStatus" label="在线状态" />
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { createChannelAccount } from '@/api/channel'

const form = reactive({
  accountType: 1,
  channelType: 'wecom',
  accountId: '',
  accountName: '',
})

const accounts = ref<any[]>([])

async function handleCreate() {
  try {
    const res: any = await createChannelAccount(form)
    accounts.value.unshift(res.data)
    ElMessage.success('创建成功')
  } catch (e: any) {
    ElMessage.error(e.message)
  }
}
</script>
