<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="true" class="search">
        <el-form ref="queryFormRef" :model="queryParams" :inline="true">
          <el-form-item label="类型" prop="type">
            <el-select v-model="queryParams.type" placeholder="请选择类型" clearable @keyup.enter="handleQuery">
              <el-option label="商家" value="1" />
              <el-option label="代理" value="2" />
              <el-option label="平台" value="3" />
            </el-select>
          </el-form-item>
          <el-form-item label="商家名称" prop="type">
            <el-input v-model="queryParams.storeName" placeholder="请输入商家名称" clearable />
          </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>
      </div>
    </transition>
    <el-card shadow="hover">
      <el-table :data="devices" border style="width: 100%; height: 100%; font-size: 14px">
        <el-table-column label="账户名称" align="center" prop="storeName" :show-overflow-tooltip="true" />
        <el-table-column label="钱包" align="center" prop="wallet" :show-overflow-tooltip="true" />
        <el-table-column label="应收" align="center" prop="revenue" :show-overflow-tooltip="true" />
        <el-table-column label="积分" align="center" prop="integralBalance" :show-overflow-tooltip="true" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
        <el-table-column label="账户类型" align="center" prop="type" width="180">
          <template #default="scope">
            {{ scope.row.type === 1 ? '商家' : scope.row.type === 2 ? '代理' : '平台' }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <pagination
          v-if="totalref > 0"
          :total="totalref"
          v-model:page="queryParams.current"
          v-model:limit="queryParams.size"
          @pagination="getListList"
        />
      </div>
    </el-card>
    <el-dialog v-model="showRefuteDialog" title="添加" width="600px" append-to-body>
      <el-form> </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="showRefuteDialog = false">取消</el-button>
          <el-button type="primary" @click="handleAdd">添加</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Online" lang="ts">
import { AccountQuery, VersionList, VersionAdd } from '@/api/agent/types';
import { getList, postAdd } from '@/api/agent/index';
import { propTypes } from '@/utils/propTypes';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_device_type } = toRefs<any>(proxy?.useDict('sys_device_type'));
//查询参数
const queryParams = ref<AccountQuery>({
  current: 1,
  size: 10,
  type: '',
  storeName: ''
});
//列表
const devices = ref<VersionList[]>([]);
//总条数
const totalref = ref<number>(0);
const getListList = async () => {
  const res = await getList(queryParams.value);
  if (res.code === 200) {
    devices.value = res.data.records;
    totalref.value = res.data.total;
  }
};
const handleQuery = () => {
  getListList();
};
const showRefuteDialog = ref(false);
const resetQuery = () => {
  queryParams.value = {
    current: 1,
    size: 10,
    type: '',
    storeName: ''
  };
  getListList();
};
const headDate = ref<VersionAdd>({
  platformType: '',
  versionCode: '',
  versionName: '',
  downloadUrl: '',
  isForceUpdate: null,
  releaseNotes: '',
  status: null
});
const handleAdd = async () => {
  const res = await postAdd(headDate.value);
  if (res.code === 200) {
    ElMessage.success('添加成功');
    headDate.value = {
      platformType: '',
      versionCode: '',
      versionName: '',
      downloadUrl: '',
      isForceUpdate: null,
      releaseNotes: '',
      status: null
    };
    showRefuteDialog.value = false;
    getListList();
  }
};
// 修改
// const handleStatusChange = async (row: any) => {
//   const obj = {
//     id: row.id,
//     status: row.status == 1 ? 0 : 1
//   };
//   const res = await getupdate(obj);
//   if (res.code === 200) {
//     ElMessage.success('修改成功');
//     getListList();
//   }
// };
const handldDelOnline = (row: any) => {
  ElMessageBox.confirm('确定要删除吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    const obj = {
      id: row.id
    };
    // const res = await getDel({ id: row.id });
    // if (res.code === 200) {
    //   ElMessage.success('删除成功');
    //   getListList();
    // }
  });
};
onMounted(() => {
  getListList();
});
</script>
