useSendToPrinterStore.js 1.63 KB
import { defineStore } from 'pinia';
import { reactive, ref, watch } from 'vue';

export const useSendToPrinterStore = defineStore('send-2Printer', () => {
    const account = ref('aaa');
    const selecteditem = ref('queue');

    const remarks = ref('');

    const purposeitems = reactive([
        {
            key: 'purpose1'
        },
        {
            key: 'purpose2'
        },
        {
            key: 'purpose3'
        }
    ]);

    const productitems = reactive([
        {
            key: 'product1'
        },
        {
            key: 'product2'
        },
        {
            key: 'product3'
        }
    ]);

    const printeritems = reactive([
        {
            key: 'printer1'
        },
        {
            key: 'printer2'
        },
        {
            key: 'printer3'
        }
    ]);

    const selectedPurpose = ref('');
    const selectedProduct = ref('');
    const selectedPrinter = ref('');

    const handleSelectPurpose = (key) => {
        selectedPurpose.value = key;
    };

    const handleSelectProduct = (key) => {
        selectedProduct.value = key;
    };

    const handleSelectPrinter = (key) => {
        selectedPrinter.value = key;
    };

    watch(
        () => account.value,
        () => {
            selecteditem.value = account.value === 'aaa' ? 'queue' : 'auto';
        }
    );

    return {
        account,
        selecteditem,
        remarks,
        purposeitems,
        productitems,
        printeritems,
        selectedPurpose,
        selectedProduct,
        selectedPrinter,
        handleSelectPurpose,
        handleSelectProduct,
        handleSelectPrinter
    };
});