<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属单位" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入所属单位"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门主键" prop="visDeptId">
        <el-input
          v-model="queryParams.visDeptId"
          placeholder="请输入部门主键"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="显示部门" prop="disDeptId">
        <el-input
          v-model="queryParams.disDeptId"
          placeholder="请输入显示部门"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目编号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目简称" prop="simpleName">
        <el-input
          v-model="queryParams.simpleName"
          placeholder="请输入项目简称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目等级" prop="projiectLevel">
        <el-input
          v-model="queryParams.projiectLevel"
          placeholder="请输入项目等级"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目负责人" prop="projectPerson">
        <el-input
          v-model="queryParams.projectPerson"
          placeholder="请输入项目负责人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人电话" prop="projectPersonPhone">
        <el-input
          v-model="queryParams.projectPersonPhone"
          placeholder="请输入负责人电话"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标识" prop="isDel">
        <el-select v-model="queryParams.isDel" placeholder="请选择删除标识" clearable>
          <el-option
            v-for="dict in sys_is_del"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </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="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['manage:proProjectInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manage:proProjectInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manage:proProjectInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['manage:proProjectInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="proProjectInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="所属单位" align="center" prop="deptId" />
      <el-table-column label="部门主键" align="center" prop="visDeptId" />
      <el-table-column label="显示部门" align="center" prop="disDeptId" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目编号" align="center" prop="projectCode" />
      <el-table-column label="项目简称" align="center" prop="simpleName" />
      <el-table-column label="项目类型" align="center" prop="projectType" />
      <el-table-column label="项目等级" align="center" prop="projiectLevel" />
      <el-table-column label="项目区县" align="center" prop="projectRegional" />
      <el-table-column label="项目地址" align="center" prop="projectAddress" />
      <el-table-column label="项目建设属性" align="center" prop="projectNature" />
      <el-table-column label="许可证号" align="center" prop="licenceNumber" />
      <el-table-column label="项目负责人" align="center" prop="projectPerson" />
      <el-table-column label="负责人电话" align="center" prop="projectPersonPhone" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="项目工期" align="center" prop="projectTimeLimit" />
      <el-table-column label="总投资" align="center" prop="totalInvestment" />
      <el-table-column label="建筑面积" align="center" prop="floorArea" />
      <el-table-column label="开累产值" align="center" prop="totalOutputValue" />
      <el-table-column label="计划完工时间" align="center" prop="plannedCompletionTime" />
      <el-table-column label="计划开始时间" align="center" prop="scheduledStartTime" />
      <el-table-column label="实际开始时间" align="center" prop="actualOperatingTime" />
      <el-table-column label="实际完工时间" align="center" prop="actualCompletionTime" />
      <el-table-column label="合同总金额" align="center" prop="contractAmount" />
      <el-table-column label="已支付金额" align="center" prop="paidAmount" />
      <el-table-column label="挂账金额" align="center" prop="onAccountAmount" />
      <el-table-column label="项目进度" align="center" prop="projectSchedule">
        <template #default="scope">
          <dict-tag :options="pro_project_schedule" :value="scope.row.projectSchedule"/>
        </template>
      </el-table-column>
      <el-table-column label="项目概述" align="center" prop="projectSummarize" />
      <el-table-column label="项目二维码" align="center" prop="projectQrCode" />
      <el-table-column label="项目状态" align="center" prop="projectStatus" />
      <el-table-column label="项目排序" align="center" prop="projectSort" />
      <el-table-column label="删除标识" align="center" prop="isDel">
        <template #default="scope">
          <dict-tag :options="sys_is_del" :value="scope.row.isDel"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['manage:proProjectInfo:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['manage:proProjectInfo:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="proProjectInfoRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属单位" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入所属单位" />
        </el-form-item>
        <el-form-item label="部门主键" prop="visDeptId">
          <el-input v-model="form.visDeptId" placeholder="请输入部门主键" />
        </el-form-item>
        <el-form-item label="显示部门" prop="disDeptId">
          <el-input v-model="form.disDeptId" placeholder="请输入显示部门" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目编号" prop="projectCode">
          <el-input v-model="form.projectCode" placeholder="请输入项目编号" />
        </el-form-item>
        <el-form-item label="项目简称" prop="simpleName">
          <el-input v-model="form.simpleName" placeholder="请输入项目简称" />
        </el-form-item>
        <el-form-item label="项目等级" prop="projiectLevel">
          <el-input v-model="form.projiectLevel" placeholder="请输入项目等级" />
        </el-form-item>
        <el-form-item label="项目区县" prop="projectRegional">
          <el-input v-model="form.projectRegional" placeholder="请输入项目区县" />
        </el-form-item>
        <el-form-item label="项目地址" prop="projectAddress">
          <el-input v-model="form.projectAddress" placeholder="请输入项目地址" />
        </el-form-item>
        <el-form-item label="项目建设属性" prop="projectNature">
          <el-input v-model="form.projectNature" placeholder="请输入项目建设属性" />
        </el-form-item>
        <el-form-item label="许可证号" prop="licenceNumber">
          <el-input v-model="form.licenceNumber" placeholder="请输入许可证号" />
        </el-form-item>
        <el-form-item label="项目负责人" prop="projectPerson">
          <el-input v-model="form.projectPerson" placeholder="请输入项目负责人" />
        </el-form-item>
        <el-form-item label="负责人电话" prop="projectPersonPhone">
          <el-input v-model="form.projectPersonPhone" placeholder="请输入负责人电话" />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="项目工期" prop="projectTimeLimit">
          <el-input v-model="form.projectTimeLimit" placeholder="请输入项目工期" />
        </el-form-item>
        <el-form-item label="总投资" prop="totalInvestment">
          <el-input v-model="form.totalInvestment" placeholder="请输入总投资" />
        </el-form-item>
        <el-form-item label="建筑面积" prop="floorArea">
          <el-input v-model="form.floorArea" placeholder="请输入建筑面积" />
        </el-form-item>
        <el-form-item label="开累产值" prop="totalOutputValue">
          <el-input v-model="form.totalOutputValue" placeholder="请输入开累产值" />
        </el-form-item>
        <el-form-item label="计划完工时间" prop="plannedCompletionTime">
          <el-input v-model="form.plannedCompletionTime" placeholder="请输入计划完工时间" />
        </el-form-item>
        <el-form-item label="计划开始时间" prop="scheduledStartTime">
          <el-input v-model="form.scheduledStartTime" placeholder="请输入计划开始时间" />
        </el-form-item>
        <el-form-item label="实际开始时间" prop="actualOperatingTime">
          <el-input v-model="form.actualOperatingTime" placeholder="请输入实际开始时间" />
        </el-form-item>
        <el-form-item label="实际完工时间" prop="actualCompletionTime">
          <el-input v-model="form.actualCompletionTime" placeholder="请输入实际完工时间" />
        </el-form-item>
        <el-form-item label="合同总金额" prop="contractAmount">
          <el-input v-model="form.contractAmount" placeholder="请输入合同总金额" />
        </el-form-item>
        <el-form-item label="已支付金额" prop="paidAmount">
          <el-input v-model="form.paidAmount" placeholder="请输入已支付金额" />
        </el-form-item>
        <el-form-item label="挂账金额" prop="onAccountAmount">
          <el-input v-model="form.onAccountAmount" placeholder="请输入挂账金额" />
        </el-form-item>
        <el-form-item label="项目进度" prop="projectSchedule">
          <el-input v-model="form.projectSchedule" placeholder="请输入项目进度" />
        </el-form-item>
        <el-form-item label="项目概述" prop="projectSummarize">
          <el-input v-model="form.projectSummarize" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="项目二维码" prop="projectQrCode">
          <el-input v-model="form.projectQrCode" placeholder="请输入项目二维码" />
        </el-form-item>
        <el-form-item label="项目排序" prop="projectSort">
          <el-input v-model="form.projectSort" placeholder="请输入项目排序" />
        </el-form-item>
        <el-form-item label="删除标识" prop="isDel">
          <el-select v-model="form.isDel" placeholder="请选择删除标识">
            <el-option
              v-for="dict in sys_is_del"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" 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 name="ProProjectInfo">
import { listProProjectInfo, getProProjectInfo, delProProjectInfo, addProProjectInfo, updateProProjectInfo } from "@/api/manage/proProjectInfo";

const { proxy } = getCurrentInstance();
const { sys_is_del } = proxy.useDict('sys_is_del');

const proProjectInfoList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    deptId: null,
    visDeptId: null,
    disDeptId: null,
    projectName: null,
    projectCode: null,
    simpleName: null,
    projectType: null,
    projiectLevel: null,
    projectPerson: null,
    projectPersonPhone: null,
    projectStatus: null,
    isDel: null,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询项目信息列表 */
function getList() {
  loading.value = true;
  listProProjectInfo(queryParams.value).then(response => {
    proProjectInfoList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    deptId: null,
    visDeptId: null,
    disDeptId: null,
    projectName: null,
    projectCode: null,
    simpleName: null,
    projectType: null,
    projiectLevel: null,
    projectRegional: null,
    projectAddress: null,
    projectNature: null,
    licenceNumber: null,
    projectPerson: null,
    projectPersonPhone: null,
    longitude: null,
    latitude: null,
    projectTimeLimit: null,
    totalInvestment: null,
    floorArea: null,
    totalOutputValue: null,
    plannedCompletionTime: null,
    scheduledStartTime: null,
    actualOperatingTime: null,
    actualCompletionTime: null,
    contractAmount: null,
    paidAmount: null,
    onAccountAmount: null,
    projectSchedule: null,
    projectSummarize: null,
    projectQrCode: null,
    projectStatus: null,
    projectSort: null,
    isDel: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null
  };
  proxy.resetForm("proProjectInfoRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加项目信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getProProjectInfo(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改项目信息";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["proProjectInfoRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateProProjectInfo(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addProProjectInfo(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除项目信息编号为"' + _ids + '"的数据项？').then(function() {
    return delProProjectInfo(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('manage/proProjectInfo/export', {
    ...queryParams.value
  }, `proProjectInfo_${new Date().getTime()}.xlsx`)
}

getList();
</script>
