Newer
Older
KaiFengPC / src / views / longoPeration / MaterialManagement.vue
@鲁yixuan 鲁yixuan on 27 Aug 7 KB updata
<template>
  <!-- 物资管理 -->
  <div class="publicContainer">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="物资储备地点:" prop="specificLocation">
        <el-input v-model="queryParams.specificLocation" placeholder="请输入物资储备地点" clearable style="width: 180px" />
      </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">新增</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 表格 -->
    <el-table :data="dataList" v-loading="loading" stripe :max-height="620">
      <el-table-column type="index" width="55" label="序号" />
      <el-table-column label="物资储备地点" prop="specificLocation" />
      <el-table-column label="具体位置" prop="address" />
      <el-table-column label="主要储备物资" prop="materialDetails" width="600" />
      <el-table-column label="负责人" prop="header" />
      <el-table-column label="联系方式" prop="headerPhone" />
      <el-table-column label="操作" width="280">
        <template #default="scope">
          <el-button link icon="View" type="primary" @click="handleDetail(scope.row, 'view')">详情</el-button>
          <el-button link type="warning" icon="Edit" @click="handleUpdate(scope.row, 'view')">修改</el-button>
          <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row, 'view')">删除</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="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="roleRef" :model="form" :rules="rules" label-width="130px" :disabled="multiple">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="负责人:" prop="header">
              <el-input v-model="form.header" placeholder="请输入负责人" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系方式:" prop="headerPhone">
              <el-input v-model="form.headerPhone" placeholder="请输入联系方式" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="物资储备地点:" prop="specificLocation">
              <el-input v-model="form.specificLocation" placeholder="请输入物资储备地点" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="具体位置:" prop="address">
              <el-input v-model="form.address" placeholder="请输入具体位置" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="经度:" prop="lon">
              <el-input v-model="form.lon" placeholder="请输入经度" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="纬度:" prop="lat">
              <el-input v-model="form.lat" placeholder="请输入纬度" clearable style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="主要储备物资:" prop="materialDetails">
              <el-input
                type="textarea"
                :rows="5"
                v-model="form.materialDetails"
                placeholder="请输入主要储备物资"
                clearable
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </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="MaterialManagement">
import {
  FloodPreventionMaterialpage,
  FloodPreventionMaterialedit,
  FloodPreventionMaterialadd,
  FloodPreventionMaterialdelete,
} from '@/api/longoPeration/MaterialManagement';
const { proxy } = getCurrentInstance();
const open = ref(false);
const multiple = ref(false);
const showSearch = ref(true);
const loading = ref(true);
const total = ref(0);
const title = ref('');
const dataList = ref([]);
const AllData = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    specificLocation: '',
  },
  rules: {
    header: [{ required: true, message: '请输入负责人', trigger: 'blur' }],
    headerPhone: [{ required: true, message: '请输入联系方式', trigger: 'blur' }],
  },
});
const { queryParams, form, rules } = toRefs(AllData);

//搜索
function handleQuery() {
  getList();
}
//重置
function resetQuery() {
  proxy.resetForm('queryRef');
  handleQuery();
}
// 新增
function handleAdd() {
  title.value = '新增物资管理';
  open.value = true;
  form.value = {};
  multiple.value = false;
}
// 新增中取消事件
function cancel() {
  open.value = false;
  proxy.resetForm('roleRef');
}

//查看详情操作
function handleDetail(row) {
  open.value = true;
  multiple.value = true;
  title.value = '查看物资管理';
  form.value = { ...row };
}
// 修改按钮操作
function handleUpdate(row) {
  open.value = true;
  title.value = '修改物资管理';
  multiple.value = false;
  form.value = { ...row };
}

/** 搜索列表 */
const getList = async () => {
  loading.value = true;
  let res = await FloodPreventionMaterialpage(queryParams.value);
  dataList.value = res.data;
  total.value = res.total;
  loading.value = false;
};

/** 新增弹框 修改弹框 提交按钮 */
async function submitForm() {
  proxy.$refs['roleRef'].validate(valid => {
    if (valid) {
      if (form.value.id != undefined) {
        FloodPreventionMaterialedit(form.value).then(() => {
          proxy.$modal.msgSuccess('修改成功');
          open.value = false;
          getList();
        });
      } else {
        FloodPreventionMaterialadd(form.value).then(() => {
          proxy.$modal.msgSuccess('新增成功');
          open.value = false;
          getList();
        });
      }
    }
  });
}
// 表格删除
function handleDelete(row) {
  proxy.$modal
    .confirm('是否确认删除?')
    .then(async () => {
      const res = await FloodPreventionMaterialdelete(row.id);
      if (res?.code !== 200) return;
      proxy.$modal.msgSuccess('操作成功!');
      getList();
    })
    .catch(() => {});
}
onMounted(() => {
  getList();
});
</script>
<style scoped lang="scss">
.dituclass {
  width: 100%;
  height: 300px;
  // background: red;
  margin-bottom: 10px;
  border: 1px solid #004565;
}
</style>