<template>
  <div style="display: flex;flex-direction: column;height: 86vh">
    <div style="flex-grow: 1;">
      <!-- 表格头部 操作按钮 -->
      <div class="table-header">
        <div class="header-button-lf">
          <el-form :model="queryParams" label-width="auto"  :inline="true">
            <el-form-item>
              <!-- <el-button  style="margin-left: 10px" type="primary" plain  @click="handleAdd"> 新增 </el-button> -->
            </el-form-item>
          </el-form>
        </div>
      </div>
      <!-- 表格主体 -->
      <el-table stripe ref="tableRef" :border="true" :data="processTableData"  size="small" style="height: 70vh">
        <el-table-column align="left" label="序号" width="45px" :show-overflow-tooltip="true">
          <template #default="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <template v-for="item in columns" :key="item">
          <el-table-column v-bind="item" :align="item.align ?? 'left'" :reserve-selection="item.type == 'selection'" :show-overflow-tooltip="true">
            <template #default="scope">
              <template v-if="item.prop === 'ftp_type'">
                <div>{{ scope.row.ftp_type == 1 ? '自动下载' : '自动上传' }}</div>
              </template>
              <template v-if="item.prop === 'use_able'">
                <div>{{ scope.row.use_able == 1 ? '已启用' : '已停用' }}</div>
              </template>

              <!-- <template v-if="item.prop === 'operation'">
                <el-tooltip
                  class="box-item"
                  effect="dark"
                  content="编辑"
                  placement="top"
                >
                  <el-button type="primary" link @click="handleUpdate">
                    <el-icon >
                      <Edit />
                    </el-icon>
                  </el-button>
                </el-tooltip>
                <el-tooltip
                  class="box-item"
                  effect="dark"
                  content="删除"
                  placement="top"
                >
                  <el-button type="primary" link  @click="handleDelete(scope.row)">
                    <el-icon >
                      <Delete />
                    </el-icon>
                  </el-button>
                </el-tooltip>
              </template> -->
            </template>
          </el-table-column>
        </template>

        <!-- 无数据 -->
        <template #empty>
          <div class="table-empty">
            <slot name="empty">
              <img src="@/assets/images/notData.png" alt="notData" />
              <div>暂无数据</div>
            </slot>
          </div>
        </template>
      </el-table>
    </div>
    <div class="disposition-bottom">
      <el-button  disabled> 重置 </el-button>
      <el-button type="primary" disabled> 确定 </el-button>
    </div>
    <!-- 添加或修改对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" append-to-body>
      <el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入FTP名称" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入FTP地址" />
        </el-form-item>
        <el-form-item label="端口" prop="port">
          <el-input v-model="form.port" placeholder="请输入FTP端口" />
        </el-form-item>
        <el-form-item label="账号" prop="account">
          <el-input v-model="form.account" placeholder="请输入FTP账号" />
        </el-form-item>
        <el-form-item label="密码" prop="name">
          <el-input v-model="form.name" placeholder="请输入FTP密码" />
        </el-form-item>
        <el-form-item label="事务" prop="password">
          <el-input v-model="form.password" placeholder="请输入FTP事务" />
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-radio-group v-model="form.state">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive,onMounted } from "vue";
import { ColumnProps } from "@/components/ProTable/interface";
import { ElMessageBox } from 'element-plus'
import { getFTPAllSysItem } from "@/api/modules/allData";


const queryParams = ref({
  pageNum: 1,
});

// 查询功能
const handleQuery = () => {
  queryParams.value.pageNum = 1;
};

//搜索功能
const resetQuery = () => {
  queryParams.value.pageNum = 1;
};


const processTableData = ref<any>([]);
const getList=async ()=>{
  const {data}=await getFTPAllSysItem()
  processTableData.value=data.list

}
// 表格配置项
const columns = reactive<ColumnProps[]>([
  { prop: "ftp_name", label: "FTP名称" },
  { prop: "ftp_ip", label: "FTP地址" },
  { prop: "ftp_port", label: "FTP端口" },
  { prop: "ftp_account", label: "FTP账号" },
  { prop: "ftp_type", label: "FTP事务" },
  { prop: "use_able", label: "是否启用" },
  { prop: "operation", label: "操作", width:150,align: 'center' }
]);

const dialog = reactive<any>({
  visible: false,
  title: ''
});
const formRef = ref<any>();
const rules = ref<any>(
  {
    name: [{ required: true, message: "FTP名称不能为空", trigger: "blur" }],
    address: [{ required: true, message: "FTP地址不能为空", trigger: "blur" }],
    port: [{ required: true, message: "FTP端口不能为空", trigger: "blur" }],
    account: [{ required: true, message: "FTP账号不能为空", trigger: "blur" }],
    password: [{ required: true, message: "FTP密码不能为空", trigger: "blur" }],
    affairs: [{ required: true, message: "FTP事务不能为空", trigger: "blur" }],
    state: [{ required: true, message: "请选择启用", trigger: "blur" }],
  }
);


const initFormData = ref<any>(
  {
    name: "",
    address: "",
    port: "",
    account:"",
    password:"",
    affairs:"",
    state:"1"
  }
);


const form = ref<any>({...initFormData});

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = "FTP信息新增";
}

/** 修改按钮操作 */
const handleUpdate = async (row?: any) => {
  reset();
  dialog.visible = true;
  dialog.title = "FTP信息编辑";
}

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
}
/** 表单重置 */
const reset = () => {
  form.value = { ...initFormData };
  formRef.value?.resetFields();
}

/** 提交按钮 */
const submitForm = () => {
  formRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      dialog.visible = false;
    }
  });
}

/** 删除按钮操作 */
const handleDelete = async (row?: any) => {
  ElMessageBox.confirm('是否确认删除编号为"' + row.b + '"的数据项？', {
    confirmButtonText: '删除',
    cancelButtonText: '取消',
    type: 'warning',
    title:'删除数据',
    draggable: true
  })
    .then(() => {

    })
    .catch(() => {

    })
}
onMounted(() => {
  getList()
});

</script>

<style scoped>
</style>
