<template>
    <div>
        <div class="customer-head">
            <div class="customer-back">
                <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
                    @click="backToList(0)">返回列表
                </el-button>
            </div>
            <div class="add-customer-btn">
                <el-button class="el-button&#45;&#45;small-yh" style="margin-left: 6px;" type="primary" size="small"
                    v-if="!editButton" @click="confirmEditing">编 辑
                </el-button>
                <el-button class="el-button--small-yh" style="margin-left: 6px;" type="primary" size="small"
                    @click="editCustomer">保 存
                </el-button>
                <el-button class="el-button--small-yh" style="margin-left: 6px;" type="success" size="small"
                    v-if="form.generateTask !== '已生成'" @click="generateOutbound">生成任务
                </el-button>
                <el-dropdown style="padding: 0 6px;line-height: 0">
                    <el-button type="danger" :loading="buttonLoading" :disabled="!form.id || viewDisabled" size="small">
                        售 后<i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item @click.native="applySettlement('申请')" :disabled="isApplySettlement">申请退款
                        </el-dropdown-item>
                        <el-dropdown-item @click.native="confirmRefundBtn('确认')" :disabled="isConfirmRefundBtn">确认退款
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                <el-dropdown style="line-height: 0">
                    <el-button type="warning" :loading="buttonLoading" :disabled="!form.id || viewDisabled" size="small">
                        审 批<i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item @click.native="examineBtn('审批')" :disabled="isExamineBtn">审批
                        </el-dropdown-item>
                        <el-dropdown-item @click.native="checkScheduleDialog = true, checkId = form.id">请核进度
                        </el-dropdown-item>
                        <el-dropdown-item @click.native="revocationRequest('撤销')" :disabled="isRevocationRequest">撤销请核
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </div>
        <div style="margin-top: 50px">
            <trade-card title="基础信息">
                <avue-form :option="optionForm" v-model="form" ref="form">
                    <template slot-scope="{row,index}" slot="contacts">
                        <el-select v-model="form.contacts" placeholder="请选择" size="small" style="width:60%" filterable
                            @change="contactsChange($event)">
                            <el-option v-for="item in contactsOption" :key="item.id" :label="item.contacts"
                                :value="item.contacts" />
                        </el-select>
                    </template></avue-form>
            </trade-card>
            <trade-card title="明细信息">
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane label="销售明细" name="sale_detail">
                        <avue-crud :option="optionContacts" v-model="formContacts" ref="formContacts"
                            :data="form.orderItemsList" :key="key" @row-save="rowSave" @row-update="rowUpdate"
                            @resetColumn="resetColumnTwo('formContacts', 'optionContacts', 'optionContactsBack', 269.1)"
                            @saveColumn="saveColumnTwo('formContacts', 'optionContacts', 'optionContactsBack', 269.1)">
                            <template slot-scope="scope" slot="menuLeft">
                                <el-button type="primary" icon="el-icon-printer" size="small"
                                    @click="handlePrint">打印</el-button>
                            </template>
                            <template slot-scope="{type,size,row,index,disabled}" slot="menu">
                                <el-button :size="size" :disabled="disabled" :type="type"
                                    :icon="row.$cellEdit ? 'el-icon-plus' : 'el-icon-edit'"
                                    @click="$refs.formContacts.rowEdit(row, index)">编辑
                                </el-button>
                                <el-button icon="el-icon-delete" :size="size" :disabled="disabled || isDisabled"
                                    :type="type" @click="rowDelBox(row, index, 'orderItemsList')">删除
                                </el-button>
                            </template>
                        </avue-crud>
                    </el-tab-pane>
                    <el-tab-pane label="支付明细" name="payment_details">
                        <avue-crud :option="optionPaymentDetails" v-model="formContacts" ref="payment_details"
                            :data="form.paymentRecordsList" @row-save="rowSave" @row-update="rowUpdate"
                            @resetColumn="resetColumnTwo('payment_details', 'optionPaymentDetails', 'optionPaymentDetailsBack', 269.2)"
                            @saveColumn="saveColumnTwo('payment_details', 'optionPaymentDetails', 'optionPaymentDetailsBack', 269.2)">
                            <template slot-scope="{type,size,row,index,disabled}" slot="menu">
                                <el-button :size="size" :disabled="disabled" :type="type"
                                    :icon="row.$cellEdit ? 'el-icon-plus' : 'el-icon-edit'"
                                    @click="$refs.formContacts.rowCell(row, index)">{{ row.$cellEdit ? '确认' : '修改' }}
                                </el-button>
                                <el-button icon="el-icon-delete" :size="size" :disabled="disabled" :type="type"
                                    @click="rowDelBox(row, index, 'paymentRecordsList')">删除
                                </el-button>
                            </template>
                        </avue-crud>
                    </el-tab-pane>
                    <el-tab-pane label="出库记录" name="outbound_records">
                        <avue-crud :option="optionOutboundRecords" v-model="formContacts" ref="outbound_records"
                            :data="form.outboundRecordsList" @row-save="rowSave" @row-update="rowUpdate"
                            @resetColumn="resetColumnTwo('outbound_records', 'optionOutboundRecords', 'optionOutboundRecordsBack', 269.3)"
                            @saveColumn="saveColumnTwo('outbound_records', 'optionOutboundRecords', 'optionOutboundRecordsBack', 269.3)">
                            <template slot-scope="{type,size,row,index,disabled}" slot="menu">
                                <el-button :size="size" :disabled="disabled" :type="type"
                                    :icon="row.$cellEdit ? 'el-icon-plus' : 'el-icon-edit'"
                                    @click="$refs.formContacts.rowCell(row, index)">{{ row.$cellEdit ? '确认' : '修改' }}
                                </el-button>
                                <el-button icon="el-icon-delete" :size="size" :disabled="disabled" :type="type"
                                    @click="rowDelBox(row, index)">删除
                                </el-button>
                            </template>
                        </avue-crud>
                    </el-tab-pane>
                </el-tabs>
            </trade-card>
            <report-dialog :switchDialog="switchDialog" @onClose="onClose()"></report-dialog>
            <el-dialog append-to-body title="审批" class="el-dialogDeep" :visible.sync="checkDialog" width="50%"
                :close-on-click-modal="false" :destroy-on-close="true" :close-on-press-escape="false" v-dialog-drag>
                <check :checkData="checkData" :checkDetail="true" :idList="[]" @operationType="operationType"
                    @choceCheckFun="choceCheckFun">
                </check>
            </el-dialog>
            <el-dialog append-to-body title="审批进度" class="el-dialogDeep" :visible.sync="checkScheduleDialog" width="40%"
                :close-on-click-modal="false" :destroy-on-close="true" :close-on-press-escape="false" v-dialog-drag>
                <check-schedule :checkId="checkId" :batchNo="batchNo" @choceScheduleFun="choceScheduleFun"></check-schedule>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import { getDetails as getCustom } from "@/api/tirePartsMall/basicData/customerInformation"
import { getDetails, submit, generateShipTask, tradingBox, delOrderItem, checkOrder, confirmRefund, revokeCheckOrder } from "@/api/tirePartsMall/salesManagement/saleOrder";
import { dotList, goodsDetail } from "@/api/tirePartsMall/purchasingManagement/warehouseEntryOrder";
import reportDialog from "@/components/report-dialog/main";
import checkSchedule from "@/components/check/checkSchedule";
import check from "@/components/check/check";
export default {
    name: "detailsPage",
    data() {
        return {
            isDisabled: false,
            contactsOption: [],
            checkData: {},
            checkScheduleDialog: false,
            isApplySettlement: true,
            isConfirmRefundBtn: true,
            isExamineBtn: true,
            isRevocationRequest: true,
            checkDialog: false,
            checkId: '',
            batchNo: '',
            switchDialog: false,
            activeName: "sale_detail",
            disabled: false,
            key: 0,
            form: {
                orderItemsList: [],
                paymentRecordsList: [],
                outboundRecordsList: []
            },
            optionForm: {
                menuBtn: false,
                span: 8,
                column: [{
                    label: '客户',
                    prop: "customerId",
                    disabled: false,
                    type: 'select',
                    props: {
                        label: 'cname',
                        value: 'id'
                    },
                    cascader: ['recAddress'],
                    change: (data) => {
                        console.log(data.value);
                        if (data.value) {
                            getCustom({ id: data.value }).then(res => {
                                console.log(res.data.data);
                                this.form.storageId = res.data.data.deliveryWarehouseId
                                this.form.contacts = res.data.data.corpsAttnList[0].cname
                                this.form.phone = res.data.data.corpsAttnList[0].tel
                                this.contactsOption = res.data.data.corpsAddrList
                                this.form.recAddress = res.data.data.corpsAddrList[0].id
                                this.form.businessSource = '内部销售'

                            })
                        }

                        // if (this.$refs.form.DIC.customerId || data.value) {
                        //     for (let item of this.$refs.form.DIC.customerId) {
                        //         if (item.id == data.value) {
                        //             console.log(data);
                        //             console.log(this.$refs.form);
                        //             console.log(item);
                        //             //   后端返回数据暂无联系人、地址等数据，无法下拉默认
                        //             this.form.phone = item.tel
                        //         }
                        //     }
                        // }
                    },
                    dicUrl: '/api/blade-sales-part/corpsDesc/listAll?corpType=KH',
                    rules: [{
                        required: true,
                        message: " ",
                        trigger: "blur"
                    }]
                }, {
                    label: '仓库',
                    prop: "storageId",
                    type: 'select',
                    props: {
                        label: 'cname',
                        value: 'id'
                    },
                    dicUrl: '/api/blade-sales-part/storageDesc/listAll',
                    rules: [{
                        required: true,
                        message: " ",
                        trigger: "blur"
                    }]
                }, {
                    label: '单据编号',
                    prop: "ordNo",
                    disabled: true
                }, {
                    label: '来源单号',
                    prop: "srcOrdNo",
                    disabled: true
                }, {
                    label: '业务来源',
                    prop: "businessSource",
                    disabled: true
                }, {
                    label: '应收类别',
                    prop: "receivableType",
                    type: "select",
                    dicUrl: "/api/blade-system/dict-biz/dictionary?code=receivableType",
                    props: {
                        label: "dictValue",
                        value: "dictValue"
                    },
                    value: '网络支付'
                }, {
                    label: '联系人',
                    type: "select",
                    prop: "contacts",
                    props: {
                        label: 'address',
                        value: 'id'
                    },
                    dicUrl: '/api/blade-sales-part/corpsAddr/corpIdByAddr?pid={{key}}'
                }, {
                    label: '电话',
                    prop: "phone",
                }, {
                    label: '收货地址',
                    prop: "recAddress",
                    type: 'select',
                    disabled: true,
                    props: {
                        label: 'address',
                        value: 'id'
                    },
                    dicUrl: '/api/blade-sales-part/corpsAddr/corpIdByAddr?pid={{key}}'
                }, {
                    label: '配送方式',
                    type: 'select',
                    prop: "shipType",
                    dicUrl: "/api/blade-system/dict-biz/dictionary?code=deliveryMethod",
                    props: {
                        label: "dictValue",
                        value: "dictValue"
                    },
                    value: '物流'
                }, {
                    label: '物流公司',
                    prop: "logisticsCorpName"
                }, {
                    label: '成本',
                    prop: "cost",
                    disabled: true
                }, {
                    label: '毛利',
                    prop: "grossProfit",
                    disabled: true
                }, {
                    label: '销售金额',
                    prop: "salesAmount",
                    disabled: true
                }, {
                    label: '运费',
                    prop: "freight",
                    disabled: true
                }, {
                    label: '总金额',
                    prop: "totalMoney",
                    disabled: true
                }, {
                    label: '备注',
                    prop: "remarks",
                    type: 'textarea',
                    span: 16,
                    minRows: 1
                }]
            },
            formContacts: {},
            optionContacts: {},
            optionContactsBack: {
                disabled: false,
                border: true,
                align: 'center',
                index: true,
                showSummary: true,
                sumColumnList: [
                    {
                        name: 'goodsNum',
                        type: 'sum',
                    },
                    {
                        name: 'sendNum',
                        type: 'sum',
                    },
                    {
                        name: 'subTotalMoney',
                        type: 'sum',
                    },
                    {
                        name: 'costprie',
                        type: 'sum',
                    },
                    {
                        name: 'grossProfit',
                        type: 'sum',
                    }
                ],
                addBtnText: "录入明细",
                refreshBtn: false,
                dialogDrag: true,
                addBtn: true,
                span: 8,
                height: 500,
                addRowBtn: false,
                editBtn: false,
                delBtn: false,
                menuWidth: 140,
                dialogTop: 25,
                dialogWidth: "80%",
                // summaryText: "合计",
                // showSummary: true,
                // sumColumnList:[{
                //   name: "goodsNum",
                //   type: "sum",
                //   decimals: 2
                // },{
                //   name: "sendNum",
                //   type: "sum",
                //   decimals: 2
                // },{
                //   name: "profit",
                //   type: "sum",
                //   decimals: 2
                // },{
                //   name: "subTotalMoney",
                //   type: "sum",
                //   decimals: 2
                // },{
                //   name: "thisAmount",
                //   type: "sum",
                //   decimals: 2
                // },{
                //   name: "costprie",
                //   type: "sum",
                //   decimals: 2
                // },{
                //   name: "grossProfit",
                //   type: "sum",
                //   decimals: 2
                // }],
                column: [{
                    label: '商品名称',
                    prop: 'goodsId',
                    width: 200,
                    disabled: false,
                    remote: true,
                    overHidden: true,
                    type: 'select',
                    props: {
                        label: 'cname',
                        value: 'id'
                    },
                    dicUrl: '/api/blade-sales-part/goodsDesc/goodsListAll?cname={{key}}'
                }, {
                    label: '物料编码',
                    prop: 'goodsNo',
                    overHidden: true,
                    disabled: false,
                    width: 100
                }, {
                    label: '品牌',
                    prop: 'brandId',
                    disabled: false,
                    width: 100,
                    overHidden: true,
                    type: 'select',
                    props: {
                        label: 'cname',
                        value: 'id'
                    },
                    dicUrl: '/api/blade-sales-part/brandDesc/listAll'
                }, {
                    label: '规格型号',
                    prop: 'propertyName',
                    overHidden: true,
                    disabled: false,
                    width: 100
                }, {
                    label: '花纹',
                    prop: 'pattern',
                    overHidden: true,
                    disabled: false,
                    width: 100
                }, {
                    label: '商品描述',
                    prop: 'goodsDescription',
                    disabled: false,
                    overHidden: true,
                    width: 100
                },
                {
                    label: '单位',
                    prop: 'units',
                    type: "select",
                    disabled: false,
                    props: {
                        label: "dictValue",
                        value: "dictValue"
                    },
                    dicUrl: "/api/blade-system/dict-biz/dictionary?code=unit",
                    overHidden: true,
                    width: 100
                }, {
                    label: '批次号',
                    prop: 'dot',
                    type: "select",
                    disabled: true,
                    allowCreate: true,
                    filterable: true,
                    dicData: [],
                    props: {
                        label: "dot",
                        value: "dot"
                    },
                    dicUrl: "/api/blade-sales-part/stockDesc/dotList",
                    overHidden: true,
                },
                {
                    label: '数量',
                    prop: 'goodsNum',
                    overHidden: true,
                    disabled: false,
                    width: 100,
                    rules: [{
                        required: true,
                        message: " ",
                        trigger: "blur"
                    }]
                },

                {
                    label: '价格',
                    prop: 'price',
                    overHidden: true,
                    width: 100,
                    disabled: false,
                    rules: [{
                        required: true,
                        message: " ",
                        trigger: "blur"
                    }]
                },

                {
                    label: '发货数量',
                    prop: 'sendNum',
                    disabled: false,
                    overHidden: true,
                    width: 100,
                    disabled: true,
                    editDisplay: false,
                    addDisplay: false
                },
                // {
                //     label: '利润',
                //     prop: 'profit',
                //     overHidden: true,
                //     width: 100
                // }, 
                {
                    label: '小计',
                    prop: 'subTotalMoney',
                    overHidden: true,
                    width: 100,
                    disabled: true,
                    editDisplay: false,
                    addDisplay: false
                },
                // {
                //     label: '返利',
                //     prop: 'thisAmount',
                //     overHidden: true,
                //     width: 100
                // }, 
                {
                    label: '成本',
                    prop: 'costprie',
                    overHidden: true,
                    width: 100,
                    disabled: true,
                    editDisplay: false,
                    addDisplay: false

                },
                {
                    label: '毛利',
                    prop: 'grossProfit',
                    overHidden: true,
                    width: 100,
                    disabled: true,
                    editDisplay: false,
                    addDisplay: false
                },
                {
                    label: '备注',
                    prop: "remarks",
                    overHidden: true,
                    width: 100,
                    disabled: false,

                }
                ]
            },
            optionPaymentDetails: {},
            optionPaymentDetailsBack: {
                align: 'center',
                index: true,
                addBtnText: "录入明细",
                refreshBtn: false,
                dialogDrag: true,
                addBtn: false,
                span: 8,
                height: 600,
                addRowBtn: false,
                editBtn: false,
                delBtn: false,
                menuWidth: 140,
                dialogTop: 25,
                dialogWidth: "80%",
                column: [{
                    label: '支付编号',
                    prop: 'paymentNumber'
                }, {
                    label: '金额',
                    prop: 'amount'
                }, {
                    label: '类型',
                    prop: 'paymentType'
                }, {
                    label: '支付时间',
                    prop: 'paymentTime'
                }]
            },
            optionOutboundRecords: {},
            optionOutboundRecordsBack: {
                align: 'center',
                index: true,
                addBtnText: "录入明细",
                refreshBtn: false,
                dialogDrag: true,
                addBtn: false,
                span: 8,
                height: 600,
                addRowBtn: false,
                editBtn: false,
                delBtn: false,
                menuWidth: 140,
                dialogTop: 25,
                dialogWidth: "80%",
                column: [{
                    label: '出库单号',
                    prop: 'billno'
                }, {
                    label: '来源单号',
                    prop: 'ordNo'
                }, {
                    label: '数量',
                    prop: 'goodsTotalNum'
                }, {
                    label: '状态',
                    prop: 'statusName'
                }, {
                    label: '业务时间',
                    prop: 'createTime'
                }]
            }
        }
    },
    components: { reportDialog, check, checkSchedule },
    props: {
        onLoad: Object,
        detailData: Object
    },
    async created() {
        this.findObject(this.optionContactsBack.column, "goodsId").change = ({ value, column }) => {
            if (this.formContacts.goodsId !== value) {
                goodsDetail({ id: value }).then(res => {
                    this.formContacts.goodsNo = res.data.data.code
                    this.formContacts.brandId = res.data.data.brandId
                    this.formContacts.propertyName = res.data.data.specificationAndModel
                    this.formContacts.pattern = res.data.data.brandItem
                    this.formContacts.goodsDescription = res.data.data.goodsDescription
                    this.formContacts.units = res.data.data.unit
                    if (res.data.data.whether == 0) {
                        this.findObject(this.optionContactsBack.column, "dot").disabled = true
                    } else {
                        this.findObject(this.optionContactsBack.column, "dot").disabled = false
                        dotList({
                            storageId: this.form.storageId,
                            goodsId: this.formContacts.goodsId
                        }).then(res => {
                            this.findObject(this.optionContactsBack.column, "dot").dicData = res.data.data
                        })
                    }
                })
            }
        }
        this.optionContacts = await this.getColumnData(this.getColumnName(269.1), this.optionContactsBack);
        console.log('this.optionContacts.column', this.optionContacts.column);
        this.findObject(this.optionContacts.column, "goodsId").change = ({ value, column }) => {
            console.log('走i在');
            if (this.formContacts.goodsId !== value) {
                goodsDetail({ id: value }).then(res => {
                    this.formContacts.goodsNo = res.data.data.code
                    this.formContacts.brandId = res.data.data.brandId
                    this.formContacts.propertyName = res.data.data.specificationAndModel
                    this.formContacts.pattern = res.data.data.brandItem
                    this.formContacts.goodsDescription = res.data.data.goodsDescription
                    this.formContacts.units = res.data.data.unit
                    if (res.data.data.whether == 0) {
                        this.findObject(this.optionContacts.column, "dot").disabled = true
                    } else {
                        this.findObject(this.optionContacts.column, "dot").disabled = false
                        dotList({
                            storageId: this.form.storageId,
                            goodsId: this.formContacts.goodsId
                        }).then(res => {
                            this.findObject(this.optionContacts.column, "dot").dicData = res.data.data
                        })
                    }
                })
            }
        }
        this.optionPaymentDetails = await this.getColumnData(this.getColumnName(269.2), this.optionPaymentDetailsBack);
        this.optionOutboundRecords = await this.getColumnData(this.getColumnName(269.3), this.optionOutboundRecordsBack);
        this.key++
        if (this.onLoad.id && this.detailData.id) {
            console.log(1);
            this.refresh(this.onLoad.id, true)
        } else if (this.onLoad.id) {
            this.refresh(this.onLoad.id, true)
        }
        if(!this.form.id){
            this.$set(this.optionContacts, "addBtn", true)
        }
    },
    methods: {
        generateOutbound() {
            if (this.form.orderItemsList.length <= 0) {
                this.$message.error('请录入明细');

            } else {
                this.$refs["form"].validate((valid, done) => {
                    done();
                    if (valid) {
                        const loading = this.$loading({
                            lock: true,
                            text: '加载中',
                            spinner: 'el-icon-loading',
                            background: 'rgba(255,255,255,0.7)'
                        });
                        generateShipTask(this.form).then(res => {
                            this.$message.success("生成出库任务成功");
                            loading.close();
                        }).finally(() => {
                            loading.close();
                        });
                    }
                })
            }
        },
        //联系人change
        contactsChange(e) {
            console.log(e);
            console.log(this.contactsOption);

            // 假设this.contactsOption是你的数组对象
            let matchedContact = this.contactsOption.find(item => item.contacts == e);
            // 判断是否找到匹配的对象
            this.$set(this.form, 'phone', matchedContact.tel)
            this.$set(this.form, 'recAddress', matchedContact.belongtoarea + matchedContact.detailedAddress)

        },
        //修改提交触发
        editCustomer() {
            this.$refs["form"].validate((valid, done) => {
                done();
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '加载中',
                        spinner: 'el-icon-loading',
                        background: 'rgba(255,255,255,0.7)'
                    });
                    submit({
                        bsType: "XS",
                        ...this.form
                    }).then(res => {
                        this.$message.success("保存成功");
                        this.refresh(res.data.data.id)
                        loading.close();
                    }).finally(() => {
                        loading.close();
                    });
                } else {
                    return false;
                }
            });
        },
        refresh(id, type) {
            const loading = this.$loading({
                lock: true,
                text: '加载中',
                spinner: 'el-icon-loading',
                background: 'rgba(255,255,255,0.7)'
            })
            getDetails({ id: id }).then(res => {
                console.log('res', res);
                this.form = res.data.data
                if (this.form.status !== '录入' && this.form.status !== '退款中' && this.form.status !== '已取消' && this.form.status !== '退款请核') {
                    console.log(1);
                    this.isApplySettlement = false;
                }

                if (this.form.status == '退款中' ) {
                    console.log(2);
                    this.isConfirmRefundBtn = false;
                }

                if (this.form.status == '退款请核') {
                    console.log(3);
                    this.isExamineBtn = false;
                }

                console.log(this.form.status == '退款请核' || this.form.status == '退款中');

                if (this.form.status == '退款请核' || this.form.status == '退款中') {
                    console.log(4);
                    this.isRevocationRequest = false;
                }
                this.form.orderItemsList.forEach((items) => {
                    if (!items.subTotalMoney) {
                        items.subTotalMoney = items.goodsNum * items.price
                        items.grossProfit = items.subTotalMoney - items.costprie
                    }
                })
                loading.close();

                if (this.form.businessSource == "外部销售") {
                    console.log('外部销售');
                    this.optionForm.column.forEach(its => {
                        if (its.prop == 'customerId') {
                            this.$set(its, 'disabled', true)
                        }
                    })
                    //不能录入不能删除
                    this.$set(this.optionContactsBack, "addBtn", false)
                    this.isDisabled = true
                    this.$set(this.form, 'shipType', '物流')
                    this.$set(this.form, 'receivableType', '网络支付')
                    this.optionContactsBack.column.forEach(item => {
                        this.$set(item, 'disabled', true)
                        if (item.label == '批次号' || item.label == '备注') {
                            item.disabled = false
                        }
                    })
                    this['optionContacts'] = this['optionContactsBack'];
                    this.delColumnData(this.getColumnName(269.1), this['optionContactsBack']);
                    this.optionContactsBack.column.forEach(item => {
                        if (item.prop == 'dot') {
                            this.$set(item, disabled, false)
                        } else {
                            this.$set(item, disabled, true)
                        }
                    })

                } else {
                    this.$set(this.form, 'shipType', '物流')
                    this.$set(this.form, 'receivableType', '现金')
                    this.optionContactsBack.column.forEach(item => {
                        this.$set(item, 'disabled', false)
                    })
                    this.optionContactsBack.column.forEach(item => {
                        if (item.label === '规格型号' || item.label === '花纹' || item.label === '品牌' || item.label === '物料编码' || item.label === '单位' || item.label === '商品描述') {
                            item.disabled = true;
                        }
                    })
                    console.log(324324);
                    this['optionContacts'] = this['optionContactsBack'];
                    this.delColumnData(this.getColumnName(269.1), this['optionContactsBack']);
                }
                // this.$set(this.form.orderItemsList,'goodsNum',66)

            }).catch(() => {
                loading.close();
            })
        },
        //请核关闭
        choceScheduleFun() {
            this.checkScheduleDialog = false
        },
        //关闭审核
        choceCheckFun() {
            this.checkDialog = false;
        },
        //申请退款
        applySettlement(type) {
            this.$confirm("您确定申请退款吗?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                this.$refs["form"].validate((valid, done) => {
                    done()
                    if (valid) {
                        console.log(this.form);
                        console.log(this.$store.getters.domSaleStatus);
                        const data = {
                            id: this.form.id,
                            url: '/tirePartsMall/salesManagement/saleOrder/index',
                            pageStatus: "this.$store.getters.domSaleStatus",
                            pageLabel: "销售订单",
                        }
                        const loading = this.$loading({
                            lock: true,
                            text: '加载中',
                            spinner: 'el-icon-loading',
                            background: 'rgba(255,255,255,0.7)'
                        });
                        checkOrder({ ...data }).then((res) => {
                            loading.close();
                            this.$message.success('申请退款成功');
                            console.log(res);
                        }).catch(() => { loading.close(); })
                    }
                })
            })
        },
        //确认退款
        confirmRefundBtn() {
            this.$confirm("您确定退款吗?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                const loading = this.$loading({
                    lock: true,
                    text: '加载中',
                    spinner: 'el-icon-loading',
                    background: 'rgba(255,255,255,0.7)'
                });
                confirmRefund({ ...this.form }).then((res) => {
                    loading.close()
                    this.$message.success('确定退款成功');
                }).catch(() => { loading.close(); })
            })
        },
        //审批
        examineBtn() {
            console.log(this.$route.query.check);
            this.checkData = this.$route.query.check
            this.checkDialog = true;
        },
        //撤销请核
        revocationRequest() {
            this.$confirm("您确定撤回此次申请吗？", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                const loading = this.$loading({
                    lock: true,
                    text: '加载中',
                    spinner: 'el-icon-loading',
                    background: 'rgba(255,255,255,0.7)'
                });
                revokeCheckOrder({ ...this.form }).then(res => {
                    loading.close();
                    this.$message.success('撤回成功')
                    this.refresh(this.form.id)
                })
            })
        },
        rowDelBox(row, index, type) {
            this.$confirm("确定将选择数据删除?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                if (row.id) {
                    console.log(index);
                    console.log(this.form.orderItemsList);
                    delOrderItem({ ids: row.id }).then(res => {
                        this.form.orderItemsList.splice(index, 1);
                        this.$message.success("操作成功!");
                    });
                } else {
                    this.form[type].splice(index, 1);
                    this.$message.success("操作成功!");
                }
            }
            );
        },
        rowSave(form, done, loading) {
            done(form)
        },
        rowUpdate(form, index, done, loading) {
            done(form)
        },
        //打印
        handlePrint() {
            this.switchDialog = !this.switchDialog;
        },
        onClose(val) {
            this.switchDialog = val;
        },
        //自定义列保存
        async saveColumnTwo(ref, option, optionBack, code) {
            /**
             * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
             * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
             * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
             */
            const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
            if (inSave) {
                this.$message.success("保存成功");
                //关闭窗口
                this.$refs[ref].$refs.dialogColumn.columnBox = false;
            }
        },
        //自定义列重置
        async resetColumnTwo(ref, option, optionBack, code) {
            this[option] = this[optionBack];
            const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
            if (inSave) {
                this.$message.success("重置成功");
                this.$refs[ref].$refs.dialogColumn.columnBox = false;
            }
        },
        backToList(type) {
            this.$emit("backToList", type);
        }
    }
}
</script>

<style lang="scss" scoped>
::v-deep .el-form-item {
    margin-bottom: 8px !important;
}
</style>
