priceCalculateNew.vue 7.15 KB
<route lang="yaml">
  name: priceCalculate
  </route>

<script lang="ts" setup name="priceCalculate">
import { ref } from 'vue';
import TableTools from '@/components/Tools/table_tools.vue';
import { TableColumnWidth, commonPageConfig } from '@/utils/enum';
import { ElMessage, ElMessageBox } from "element-plus";
import { CirclePlus } from "@element-plus/icons-vue";
import { useRouter, useRoute } from "vue-router";
import useUserStore from "@/store/modules/user";
import useDataAssetStore from "@/store/modules/dataAsset";
import { getAllFlowData } from '@/api/modules/queryService';
import { changeNum } from "@/utils/common";
import {
  getDiseaseAll,
  getPriceList,
  deletePrice,
} from '@/api/modules/dataPricing';

const router = useRouter();
const userStore = useUserStore()
const assetStore = useDataAssetStore();
const userData = JSON.parse(userStore.userData)
const { proxy } = getCurrentInstance() as any;

const searchItemList = ref([
  {
    type: "input",
    label: "",
    field: "dataResourceName",
    default: "",
    placeholder: "数据资源名称",
    clearable: true,
  },
  {
    type: "cascader",
    label: "",
    field: "diseaseName",
    placeholder: "疾病名称",
    default: "",
    options: [],
    showAllLevels: false,
    props: {
      checkStrictly: true,
      label: "diseaseName",
      value: "guid",
      children: 'childList',
      emitPath: false
    },
    filterable: true,
    clearable: true,
  }
]);

const typeMap: any = ref({});
const selectRowData: any = ref([])
const currTableData: any = ref({});
const page: any = ref({
  ...commonPageConfig,
  dataResourceName: '',
  diseaseName: ''
});
const tableField: any = ref([
  { label: "序号", type: "index", width: TableColumnWidth.INDEX, align: "center" },
  { label: "定价模型名称", field: "modelName", width: 200 },
  { label: "数据资源名称", field: "dataResourceName", width: 200 },
  { label: "疾病名称", field: "diseaseName", width: 200 },
  {
    label: "交易价格(元)", field: "dataTransactionPrice", width: 120, align: 'right', getName: (scope) => {
      return scope.row.dataTransactionPrice ? changeNum(parseFloat(scope.row.dataTransactionPrice), 2) : '-';
    }
  },
  { label: "创建人", field: "createUserName", width: 120 },
  { label: "创建时间", field: "createTime", width: TableColumnWidth.DATETIME },
]);
const tableInfo = ref({
  id: 'api-data-table',
  rowKey: 'guid',
  loading: false,
  fields: tableField.value,
  data: [],
  page: {
    type: "normal",
    rows: 0,
    ...page.value,
  },
  actionInfo: {
    label: "操作",
    type: "btn",
    isMore: false,
    width: 120,
    btns: [
      { label: "编辑", value: "edit" },
      { label: "删除", value: "del" }
    ]
  }
});

const setTableField = () => {
  tableField.value.splice(4, 0, {
    label: "交易用途", field: "dataUsage", width: 120, getName: (scope) => {
      return typeMap.value['dataUsage'].find((item) => item.value == scope.row['dataUsage'])?.label || '-';
    }
  });
  tableInfo.value.fields = tableField.value;
}

// 获取所有疾病数据
const getDiseaseData = () => {
  getDiseaseAll().then((res: any) => {
    if (res.code == proxy.$passCode) {
      const data = res.data || [];
      searchItemList.value[1].options = data;
    }
  })
}

// 获取数据字典
const getDataType = (dictType, fieldName) => {
  getAllFlowData({ dictType }).then((res: any) => {
    if (res.code == proxy.$passCode) {
      const data = res.data || [];
      typeMap.value[fieldName] = JSON.parse(JSON.stringify(data));
      setTableField()
    } else {
      proxy.$ElMessage.error(res.msg);
    }
  })
}

const toSearch = (val: any, clear: boolean = false) => {
  page.value.curr = 1;
  if (clear) {
    searchItemList.value.map((item) => (item.default = ""));
    page.value.dataResourceName = ''
    page.value.diseaseName = '';
  } else {
    page.value.dataResourceName = val.dataResourceName || '';
    page.value.diseaseName = val.diseaseName || '';
  }
  getTableData();
};

const getTableData = () => {
  tableInfo.value.loading = true;
  getPriceList({
    pageSize: page.value.limit,
    pageIndex: page.value.curr,
    dataResourceName: page.value.dataResourceName,
    diseaseName: page.value.diseaseName,
  }).then((res: any) => {
    tableInfo.value.loading = false;
    if (res.code == proxy.$passCode) {
      const data = res.data || {};
      tableInfo.value.data = data.records || [];
      tableInfo.value.page.limit = data.pageSize
      tableInfo.value.page.curr = data.pageIndex
      tableInfo.value.page.rows = data.totalRows
    } else {
      proxy.$ElMessage.error(res.msg);
    }
  })
}

const tablePageChange = (info) => {
  page.value.curr = Number(info.curr);
  page.value.limit = Number(info.limit);
  tableInfo.value.page.limit = page.value.limit;
  tableInfo.value.page.curr = page.value.curr;
  getTableData();
};

const tableBtnClick = (scope, btn) => {
  const type = btn.value;
  const row = scope.row;
  currTableData.value = row;
  if (type === 'edit') { // 编辑
    if (row.belongingTheme) {
      router.push(
        {
          name: 'calculateConfig',
          query: {
            guid: row.guid,
            name: row.modelName,
            type: 'edit'
          }
        }
      );
    } else {
      router.push(
        {
          name: 'calculateConfigNew',
          query: {
            guid: row.guid,
            name: row.modelName,
            type: 'edit'
          }
        }
      );
    }
  } else if (type === 'del') { // 删除
    open('确定要删除该条数据吗?', 'warning');
  }
};

const open = (msg, type, isBatch = false) => {
  ElMessageBox.confirm(msg, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: type,
  }).then(() => {
    let guids = [currTableData.value.guid]
    if (isBatch) {
      guids = selectRowData.value
    }
    deletePrice(guids).then((res: any) => {
      if (res.code == proxy.$passCode) {
        getTableData();
        ElMessage({
          type: "success",
          message: "删除成功",
        });
      } else {
        proxy.$ElMessage.error(res.msg);
      }
    });
  });
};

const addDisease = () => {
  router.push(
    {
      name: 'calculateConfigNew',
      query: {
        type: 'create'
      }
    }
  );
}

onBeforeMount(() => {
  getDiseaseData();
  getDataType('数据用途', 'dataUsage')
});

onActivated(() => {
  if (assetStore.isRefresh) {//如果是首次加载,则不需要调用
    toSearch(null, true);
    assetStore.set(false);
  }
})

</script>

<template>
  <div class="container_wrap">
    <div class="table_tool_wrap">
      <TableTools :searchItems="searchItemList" :searchId="'data-source-search'" @search="toSearch" />
      <div class="tools_btns">
        <el-button type="primary" @click="addDisease" v-preReClick>新增</el-button>
      </div>
    </div>
    <div class="table_panel_wrap">
      <Table :tableInfo="tableInfo" @tablePageChange="tablePageChange" @tableBtnClick="tableBtnClick" />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.table_tool_wrap {
  width: 100%;
  height: 84px !important;
  padding: 0 8px;

  .tools_btns {
    padding: 0px 0 0;
  }
}

.table_panel_wrap {
  width: 100%;
  height: calc(100% - 84px);
  padding: 0px 8px 0;
}
</style>