<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="旺旺" prop="wangwang">
        <el-input v-model="queryParams.wangwang" placeholder="请输入旺旺" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入用户名" clearable @keyup.enter.native="handleQuery" />
      </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>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:log:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="logList">
      <el-table-column label="旺旺" align="center" prop="wangwang" />
      <el-table-column label="ip" align="center" prop="ip" />
      <el-table-column label="用户名" align="center" prop="createBy" />
      <el-table-column show-overflow-tooltip label="操作系统" align="center" prop="os" />
      <el-table-column show-overflow-tooltip label="内容" align="center" prop="content" />
      <el-table-column show-overflow-tooltip label="更新内容" align="center" prop="updateContent" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="bindOrder(scope.row)" v-hasPermi="['system:log:edit']">绑定</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:log:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    <!-- 添加或修改绑定订单对话框 -->
    <el-dialog :title="title" v-model="open" width="800px" append-to-body>
      <el-form ref="bind_form" :model="bindForm" label-width="130px">
        <el-form-item label="订单号" prop="orderSn">
          <el-input v-model="bindForm.orderSn" placeholder="请输入关联的订单号" />
        </el-form-item>
        <el-form-item label="订单备注" prop="content">
          <el-input v-model="bindForm.content" placeholder="请输入订单备注" />
        </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 { listLog, getLog, delLog, addLog, updateLog } from '@/api/system/log';

const { proxy } = getCurrentInstance();

const title = ref('绑定订单');
const open = ref(false);
// 显示搜索条件
const showSearch = ref(true);
const loading = ref(false);
const data = reactive({
  bindForm: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    wangwang: null,
    ip: null,
    userName: null,
  },
  rules: {},
});

const { queryParams, bindForm, rules } = toRefs(data);
// 总条数
const total = ref(0);
// 查询日志表格数据
const logList = ref([]);
//绑定订单
function bindOrder(row) {
  let { id, content } = row;

  bindForm.value = { id, content };
  open.value = true;
}
//关闭弹窗
function cancel() {
  open.value = false;
}
//提交信息
function submitForm() {
  open.value = false;
}
function getList() {
  loading.value = true;
  listLog(queryParams.value).then(response => {
    logList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm('queryForm');
  handleQuery();
}
function handleExport() {
  download(
    'system/log/export',
    {
      ...queryParams.value,
    },
    `log_${new Date().getTime()}.xlsx`,
  );
}
getList();
</script>
