import { splitColumns } from '../config/split/columns';
import { splitFormItems } from '../config/split/formitems';

export let splitModule = {
    data() {
        return {
            splitVisible: false,
            splitColumns: splitColumns,
            splitFormItems: splitFormItems,
            splitOriginItem: null,
            splitOriginItemIndex: null,
            confirmLoading: false,
        }
    },

    methods: {

        showSplitBill(record,index,dataSource) {
            this.splitOriginItem = record
            this.splitOriginItemIndex = index
            this.splitVisible = true
        },

        splitedCallback(item) {
            item.pieceQty = item.conversionRate * item.oddCaseQty + item.oddPieceQty
            item.qty = (item.pieceQty / item.conversionRate).toFixed(2)
        },

        handleSpliteOk(list) {
            let id = this.splitOriginItem.asnLineId;
            let refAsnLineId = this.splitOriginItem.refAsnLineId;
            let ref = this.queryRefFromName('list')
            ref.setDataSource(list.shift(), [id]) // 改变原需要拆分的项
            console.log(list,'list');
            list.forEach((t,i) => {
                // 原需要拆分的项中复制出新项，并赋值数量
                ref.addRow(1, this.splitOriginItemIndex, this.splitOriginItemIndex+i+1, {
                    ...t,
                    refAsnLineId: refAsnLineId + '-' + Math.floor(Math.random() * 100000),
                    asnLineId: id + '_cus_' + Math.floor(Math.random() * 1000),
                    whAreaCategoryCode: ''
                })
            })
            this.splitVisible = false
            // this.confirmLoading = false;
            this.$message.success(this.$lang('拆单成功'))
        },

    },


};