<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :searchForm="searchForm" @search="search">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :sm="8" :xs="24">
          <a-form-item>
            <a-input v-model="searchForm.val" placeholder="请输入" allow-clear>
              <template #prepend>
                <a-select v-model="searchForm.type">
                  <a-option value="1">账号</a-option>
                  <a-option value="2">UID</a-option>
                </a-select>
              </template>
            </a-input>
          </a-form-item>
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
      <template #crudContent>
        <a-descriptions direction="vertical" size="large" title="账号信息" bordered>
          <a-descriptions-item label="账号">
            {{ data[0]?.user_name }}
          </a-descriptions-item>
          <a-descriptions-item label="UID">
            {{ data[0]?.uid }}
          </a-descriptions-item>
          <a-descriptions-item label="注册时间">
            {{ data[0]?.reg_time }}
          </a-descriptions-item>
          <a-descriptions-item label="注册IP">
            {{ data[0]?.reg_ip }}
          </a-descriptions-item>
          <a-descriptions-item label="最后登录IP">
            {{ data[0]?.login_ip }}
          </a-descriptions-item>
          <a-descriptions-item label="最后登录时间">
            {{ data[0]?.login_time }}
          </a-descriptions-item>
          <a-descriptions-item label="真实姓名">
            {{ data[0]?.real_name }}
          </a-descriptions-item>
          <a-descriptions-item label="证件号码">
            {{ data[0]?.id_card }}
          </a-descriptions-item>
          <a-descriptions-item label="手机">
            {{ data[0]?.mobile }}
          </a-descriptions-item>
          <a-descriptions-item label="状态">
            <a-tag color="green" v-if="data[0]?.status == 1">正常</a-tag>
            <a-tag color="red" v-if="data[0]?.status == 0">禁用</a-tag>
          </a-descriptions-item>
          <a-descriptions-item label="操作">
            <a-space v-if="data[0]?.status == 1">
              <a-button status="danger" type="primary" @click="edit('pwd', data[0])" size="small">修改密码</a-button>
              <a-button type="primary" @click="edit('mobile', data[0])" size="small">修改绑定手机号码</a-button>
              <a-button status="warning" type="primary" @click="edit('real', data[0])" size="small"
                >修改实名信息</a-button
              >
            </a-space>
          </a-descriptions-item>
        </a-descriptions>
      </template>
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
// import { Message } from "@arco-design/web-vue";
import EditForm from './edit.vue'
import api from '../../api/customer/account'

// 引用定义
const crudRef = ref()
const editRef = ref()
const viewRef = ref()
const data = ref([])

// 搜索表单
const searchForm = ref({
  val: '',
  type: '1',
})

// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  pageSimple: true,
})

// 页面数据初始化
const initPage = async () => {}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
  data.value = crudRef.value?.getTableData() || []
  console.log('===>', crudRef.value?.getTableData())
}

const edit = async (type, data) => {
  editRef.value?.open(type, data)
}

const search = async () => {
  data.value = crudRef.value?.getTableData() || []
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>

<script>
export default { name: 'v1/customer/account' }
</script>
