import { reactive } from 'vue';

// TODO 处理：运单号/提单号
export default function useAddBillMainOrder(onClose: Function, onShow: Function, emit) {
    // 定义基础数据
    const state = reactive({
        form: {
            textarea: ''
        }
    })

    // 显示操作
    const show = (row) => {
        if (row) {
            state.form.textarea = row.join('\n')
        }
        onShow()
    }

    // 取消弹窗
    const hanleOnClose = () => {
        state.form.textarea = ''
        onClose()
    }

    // 获取的数据
    const confirm = () => {
        const waybillNoList = []
        const strArr = state.form.textarea.split('\n')
        for (const item of strArr) {
            if (item) {
                waybillNoList.push(item.trim() as never)
            }
        }
        emit("saveOrder", waybillNoList)
        // 取消弹窗
        hanleOnClose()
    }

    return {
        show,
        confirm,
        hanleOnClose,
        state
    }
}