123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { defineStore } from "pinia";
- import { getYpZdGroup } from "@/api/zhu-yuan-yi-sheng/yi-zhu-lu-ru";
- type CodeName = {
- code: string;
- name: string;
- isDefault: true;
- };
- export const useYfGroupStore = defineStore("groupStore", {
- state: () => ({
- // 西药
- xy: null as CodeName[],
- // 草药
- cy: null as CodeName[],
- }),
- getters: {
- getXyCodeList(state) {
- return state.xy.map(item => item.code);
- },
- getXyCodeName(state) {
- return (code: string) =>
- state.xy.find(item => item.code === code)?.name || "";
- },
- getCyCodeList(state) {
- return state.cy.map(item => item.code);
- },
- getCyCodeName(state) {
- return (code: string) =>
- state.cy.find(item => item.code === code)?.name || "";
- },
- getDefaultCode(state) {
- return (code: keyof typeof state) => {
- const tmp = state[code];
- if (state[code]?.length > 0) {
- return tmp?.find(item => item.isDefault)?.code || tmp[0].code;
- }
- return "";
- };
- },
- getDefaultXyCode() {
- return this.getDefaultCode("xy");
- },
- getDefaultCyCode() {
- return this.getDefaultCode("cy");
- },
- },
- actions: {
- async init() {
- const tmp = await getYpZdGroup().catch(() => {
- return {
- // 西药
- xy: [],
- // 草药
- cy: [],
- };
- });
- this.xy = tmp.xy;
- this.cy = tmp.cy;
- },
- },
- });
|