<template>
  <div>
    <el-card class="box-card">
      <byTable
        :source="sourceList.data"
        :pagination="sourceList.pagination"
        :config="config"
        :loading="loading"
        :searchConfig="searchConfig"
        highlight-current-row
        :action-list="[
          {
            text: '新增',
            action: () => clickModal(),
          },
        ]"
        @get-list="getList"
        @clickReset="clickReset">
      </byTable>
    </el-card>
  </div>
</template>

<script setup>
import byTable from "/src/components/byTable/index";

const { proxy } = getCurrentInstance();
const sourceList = ref({
  data: [],
  pagination: {
    total: 0,
    pageNum: 1,
    pageSize: 10,
    name: "",
  },
});
const loading = ref(false);
const searchConfig = computed(() => {
  return [
    {
      type: "input",
      prop: "name",
      label: "规则名称",
    },
  ];
});
const config = computed(() => {
  return [
    {
      attrs: {
        label: "规则名称",
        prop: "name",
      },
    },
    {
      attrs: {
        label: "种类",
        prop: "species",
        width: 180,
      },
      render(val) {
        return proxy.dictKeyValue(val, proxy.useUserStore().allDict["bom_species"]);
      },
    },
    {
      attrs: {
        label: "操作",
        width: 120,
        align: "center",
        fixed: "right",
      },
      renderHTML(row) {
        return [
          {
            attrs: {
              label: "编辑",
              type: "primary",
              text: true,
            },
            el: "button",
            click() {
              clickUpdate(row);
            },
          },
        ];
      },
    },
  ];
});
const getList = async (req, status) => {
  if (status) {
    sourceList.value.pagination = {
      pageNum: sourceList.value.pagination.pageNum,
      pageSize: sourceList.value.pagination.pageSize,
    };
  } else {
    sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  }
  loading.value = true;
  proxy.post("/priceBillingStandard/page", sourceList.value.pagination).then((res) => {
    sourceList.value.data = res.rows;
    sourceList.value.pagination.total = res.total;
    setTimeout(() => {
      loading.value = false;
    }, 200);
  });
};
getList();
const clickReset = () => {
  getList("", true);
};
const clickModal = () => {
  proxy.$router.replace({
    path: "/charging-standard/addOrModify",
    query: {
      random: proxy.random(),
    },
  });
};
const clickUpdate = (row) => {
  proxy.$router.replace({
    path: "/charging-standard/addOrModify",
    query: {
      id: row.id,
      random: proxy.random(),
    },
  });
};
</script>

<style lang="scss" scoped>
:deep(.el-dialog) {
  margin-top: 10px !important;
  margin-bottom: 10px !important;
}
</style>
