Newer
Older
HuangJiPC / src / pages / views / performance / setKhPay.vue
@zhangdeliang zhangdeliang on 21 Jun 11 KB update
<template>
  <!-- 考核支付系数配置 -->
  <div class="payPage">
    <div class="searchBoxs">
      <n-space>
        <n-button type="primary"
                  @click="handleClick('add')">
          <template #icon>
            <n-icon>
              <Add />
            </n-icon>
          </template>新增
        </n-button>
      </n-space>
    </div>
    <!-- 表格 -->
    <div class="tableBox">
      <n-data-table :bordered="false"
                    :max-height="700"
                    striped
                    :columns="columns"
                    :data="tableData"
                    :loading="tableLoading"
                    :remote="true"
                    :pagination="pagination">
      </n-data-table>
    </div>
    <!-- 新增修改弹窗 -->
    <n-modal :title="modalTitle"
             :mask-closable="false"
             preset="dialog"
             :show-icon="false"
             :style="{ width: '800px'}"
             v-model:show="modalShow">
      <n-form ref="formRef"
              :label-width="150"
              label-align="right"
              require-mark-placement="left"
              :rules="formInfo.rules"
              :model="formInfo.data"
              label-placement="left">
        <n-form-item label="上边界分数:"
                     path="upRange">
          <n-input-number v-model:value="formInfo.data.upRange"
                          :show-button="false"
                          min="0"
                          max="100"
                          style="width:100%" />
        </n-form-item>
        <n-form-item label="是否包含上边界"
                     path="upExpress">
          <n-select v-model:value="formInfo.data.upExpress"
                    :options="isupExpress"
                    clearable>
          </n-select>
        </n-form-item>
        <n-form-item label="下边界分数:"
                     path="dnRange">
          <n-input-number v-model:value="formInfo.data.dnRange"
                          :show-button="false"
                          min="0"
                          max="100"
                          style="width:100%" />
        </n-form-item>
        <n-form-item label="是否包含下边界"
                     path="dnExpress">
          <n-select v-model:value="formInfo.data.dnExpress"
                    :options="isdnExpress"
                    clearable>
          </n-select>
        </n-form-item>
        <n-form-item label="支付方式:"
                     path="payType">
          <n-input v-model:value="formInfo.data.payType" />
        </n-form-item>
        <n-form-item label="支付基数比例:"
                     path="payRadixRate">
          <n-input-number v-model:value="formInfo.data.payRadixRate"
                          :show-button="false"
                          min="0"
                          max="1"
                          style="width:100%" />
        </n-form-item>
        <n-form-item label="支付计算系数:"
                     path="payComputeFactorRate">
          <n-input-number v-model:value="formInfo.data.payComputeFactorRate"
                          :show-button="false"
                          min="0"
                          max="1"
                          style="width:100%" />
        </n-form-item>
      </n-form>
      <template #action>
        <n-space>
          <n-button style="right:300px"
                    type="primary"
                    @click="handleClick('submit')">保存
          </n-button>
          <n-button style="right:280px"
                    @click="() => (modalShow = false)">取消</n-button>
        </n-space>
      </template>
    </n-modal>

  </div>
</template>

<script>
import { toRefs, onMounted, reactive, h, ref, nextTick } from "vue"
import { Search, Add } from "@vicons/ionicons5"
import { NButton, NImage } from "naive-ui"
import {
  AssessPaymentInfo, AssessPaymentDel, AssessPaymenSave, AssessPaymenUpdate
} from "@/services"
import { resetForm, formatDate } from "@/utils/util"
import Editor from "./editor.vue"

export default {
  name: "payPage",
  components: { Search, Add, NButton, Editor },
  setup() {
    const allData = reactive({
      uploadList: [],
      modalTitle: "新增支付系数配置",
      modalShow: false,
      isupExpress: [
        { value: "eq", label: "是" },
        { value: "ne", label: "否" },
      ],
      isdnExpress: [
        { value: "eq", label: "是" },
        { value: "ne", label: "否" },
      ],
      formInfo: {
        data: {
          upRange: null,
          dnRange: null,
          payType: null,
          payRadixRate: null,
          upExpress: null,
          dnExpress: null,
          payComputeFactorRate: null,
        },
        rules: {
          upRange: {
            required: true,
            type: "number",
            trigger: ["blur"],
            message: "请输入上边界值",
          },
          upExpress: {
            required: true,
            trigger: ["change"],
            message: "请选择",
          },
          dnExpress: {
            required: true,
            trigger: ["change"],
            message: "请选择",
          },
          dnRange: {
            required: true,
            type: "number",
            trigger: ["blur"],
            message: "请输入下边界值",
          },
          payType: {
            required: true,
            trigger: ["blur"],
            message: "请输入考核支付方式",
          },
          payRadixRate: {
            required: true,
            type: "number",
            trigger: ["blur"],
            message: "请输入支付基数比例",
          },
          payComputeFactorRate: {
            required: true,
            type: "number",
            trigger: ["blur"],
            message: "请输入支付计算系数",
          },
        },
      },
      tableLoading: true,
      tableData: [],
      columns: [
        {
          title: "序号",
          align: "center",
          width: "80",
          render(row, index) {
            return (paginationReactive.page - 1) * paginationReactive.pageSize + index + 1;
          }
        },
        { title: "上边界值", align: "center", key: "upRange" },
        { title: "是否包含上边界", align: "center", key: "upExpress" },
        { title: "下边界值", align: "center", key: "dnRange" },
        { title: "是否包含下边界", align: "center", key: "dnExpress" },
        { title: "考核支付方式", align: "center", key: "payType" },
        { title: "支付基数比例", align: "center", key: "payRadixRate" },
        { title: "支付计算系数", align: "center", key: "payComputeFactorRate" },
        {
          title: "操作",
          key: "actions",
          width: "220",
          align: "center",
          render(row) {
            const btn = allData.actionColumn.map((item, index) => {
              return h(
                NButton,
                {
                  text: true,
                  size: item.size,
                  style: {
                    margin: "10px",
                  },
                  type: item.btnType,
                  onClick: () => handleClick(item.type, row),
                },
                { default: () => item.default }
              );
            });
            return btn;
          },
        },
      ],
      actionColumn: [
        {
          size: "small",
          btnType: "primary",
          type: "edit",
          default: "修改",
        },
        {
          size: "small",
          btnType: "error",
          type: "delete",
          default: "删除",
        },
      ],
    })
    //分页
    const paginationReactive = reactive({
      page: 1,
      pageSize: 10,
      showSizePicker: true,
      pageSizes: [10, 20, 50],
      showQuickJumper: true,
      pageCount: 0,
      itemCount: 0,
      prefix: () => {
        return "共 " + paginationReactive.itemCount + " 项";
      },
      onChange: (page) => {
        paginationReactive.page = page;
        getTableData();
      },
      onPageSizeChange: (pageSize) => {
        paginationReactive.pageSize = pageSize;
        paginationReactive.page = 1;
        getTableData();
      },
    });
    //获取表格数据
    const getTableData = async () => {
      allData.tableLoading = true;
      let pramas = {
        current: paginationReactive.page,
        size: paginationReactive.pageSize,
      };
      let res = await AssessPaymentInfo(pramas);
      if (res && res.code == 200) {
        allData.tableData = res.data.records;
        paginationReactive.pageCount = res.data.pages;
        paginationReactive.itemCount = res.data.total;
        res.data.records.map(item => {
          if (item.upExpress == "eq") {
            item.upExpress = "是"
          } else {
            item.upExpress = "否"
          };
          if (item.dnExpress == "eq") {
            item.dnExpress = "是"
          } else {
            item.dnExpress = "否"
          }
        });
      }
      allData.tableLoading = false;
    };
    const formRef = ref(null);
    const richEditor = ref(null);
    // 点击事件
    const handleClick = async (type, row) => {
      switch (type) {
        case "search":
          getTableData();
          break;
        case "add":
          allData.modalTitle = "新增支付系数配置";
          resetForm(allData.formInfo.data);
          allData.modalShow = true;
          allData.uploadList = [];
          break;
        case "edit":
          allData.modalTitle = "修改";
          allData.formInfo.data = { ...row };
          allData.modalShow = true;
          break;
        case "submit":
          formRef.value.validate((errors) => {
            if (!errors) {
              submitData();
            } else {
              $message.error("验证失败,请检查必填项");
            }
          });
          break;
        case "delete":
          $dialog.info({
            title: "提示",
            content: `确定删除该数据吗?`,
            positiveText: '确定',
            negativeText: '取消',
            onPositiveClick: () => {
              let ids = [row.id];
              dataDel(ids)
            }
          })
          break;
      }
    }
    // 删除数据
    async function dataDel(ids) {
      let res = await AssessPaymentDel({ ids: ids });
      if (res && res.code === 200) {
        $message.success("删除成功");
        getTableData();
      }
    }
    // 提交数据
    async function submitData() {
      let params = { ...allData.formInfo.data };
      if (allData.modalTitle == "新增支付系数配置") {
        let res = await AssessPaymenSave(params);
        if (res && res.code == 200) {
          $message.success("操作成功");
          getTableData();
          allData.modalShow = false;
        }
      } else {
        let res = await AssessPaymenUpdate(params);
        if (res && res.code == 200) {
          $message.success("操作成功");
          getTableData();
          allData.modalShow = false;
        }
      }
    }
    onMounted(() => {
      getTableData();
    })
    return {
      ...toRefs(allData),
      pagination: paginationReactive,
      handleClick,
      getTableData,
      formRef,
      richEditor,
    }
  }
}
</script>

<style lang="less" scoped >
.payPage {
  width: 100%;
  .searchBoxs {
    margin: 10px;
  }
}
</style>