Newer
Older
KaiFengPC / src / views / preassess / scaleConfig / index.vue
@zhangdeliang zhangdeliang on 23 May 3 KB 初始化项目
<template>
  <div class="scaleConfig">
    <div class="top">
      <el-form ref="ruleForm" inline :model="form">
        <el-form-item label="使用状态:" prop="status">
          <el-select v-model="form.status" placeholder="使用状态">
            <el-option label="全部" value="" />
            <el-option label="启用" value="1" />
            <el-option label="停用" value="0" />
          </el-select>
        </el-form-item>
        <el-form-item label="生效时间:" prop="time">
          <el-date-picker
            v-model="form.time"
            type="daterange"
            range-separator="~"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="search"> 查询</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row class="mb8">
        <el-button type="primary" plain icon="Plus" @click="openDialog({}, 'add')">新增</el-button>
      </el-row>
    </div>
    <new-table :data="tableData" :columns="columns" :loading="loading" />
    <pagination :total="total" v-model:page="pageNum" v-model:limit="pageSize" @pagination="getTableList" />
    <el-dialog
      v-model="visible"
      :title="`${opts.text}建议比例配置`"
      :close-on-click-modal="false"
      width="70%"
      :before-close="close"
      class="dialog"
    >
      <tableDalgo v-if="visible" ref="tableDalgoRef" :id="row.id || ''" :opts="opts.type"></tableDalgo>
      <template #footer v-if="opts.type !== 'view'">
        <div class="dialog-footer">
          <el-button type="primary" @click="submit">保存</el-button>
          <el-button @click="close">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import tableDalgo from './tableDalgo.vue';
import { reactive, onMounted } from 'vue';
import { usePagination } from '@/hooks';
import useColumns from './useColumns';
import { getFacilitiesSuggestRateConfigPage, facilitiesSuggestRateConfigAddWithItem } from '@/api/preassess/scaleConfig';
const { proxy } = getCurrentInstance();
const form = reactive({
  status: '',
  time: [],
});

const params = computed(() => {
  const args = JSON.parse(JSON.stringify(form));
  const { time } = args;
  delete args.time;
  return {
    ...args,
    updateTimeStart: time[0] || '',
    updateTimeEnd: time[1] || '',
  };
});

const { pageNum, pageSize, tableData, total, loading, getTableList } = usePagination(getFacilitiesSuggestRateConfigPage, params);

const { columns, visible, row, opts, openDialog } = useColumns(proxy, getTableList);

const search = () => {
  pageNum.value = 1;
  getTableList();
};

const resetQuery = () => {
  proxy.$refs.ruleForm.resetFields();
  search();
};

const close = type => {
  visible.value = false;
  opts.type = '';
  opts.text = '';
  row.value = {};
  if (type === 'add') search();
  else if (type === 'edit') getTableList();
};

const submit = async () => {
  if (opts.type === 'add') {
    const data = proxy.$refs.tableDalgoRef.tableData;
    console.log(data);
    const res = await facilitiesSuggestRateConfigAddWithItem(data);
    if (res?.code !== 200) return;
    proxy.$modal.msgSuccess('操作成功!');
    close(opts.type);
  } else {
    close(opts.type);
  }
};

onMounted(() => {
  getTableList();
});
</script>

<style lang="scss" scoped>
.scaleConfig {
  padding: 20px;
  height: 90vh;
  overflow-y: hidden;
  .top {
    margin-bottom: 15px;
  }
}

:deep(.dialog) {
  .el-dialog__body {
    padding-bottom: 20px !important;
  }
  .el-dialog__footer {
    padding-top: 0 !important;
  }
}
</style>