import Dialog from '../../../../dist/dialog/dialog.js';
const util = require('../../../../utils/util.js')
const api = require('../../../../utils/api.js')
const Constants = require('../../../../utils/Constants.js')
const config = require('../../../../config/config.js')
const common = require('../../../../utils/common.js')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        ORDER_CONTRACT_NO: false,
        activeNames: [
            "1",
            "2"
        ],
        annexPaths: [],
        balanceAmountField: 0,
        deliveryTimeDefaultSearch: 1706237493682,
        fileList: [],
        form: {
            addressArea: {
                city: "沈阳市",
                district: "浑南区",
                province: "辽宁省"
            },
            addressFull: "辽宁省沈阳市浑南区沈阳市浑南区人民政府(新聪街西)1",
            addressGcj02: {
                latitude: 41.71482,
                longitude: 123.44972
            },
            addressName: "沈阳市浑南区人民政府(新聪街西)",
            addressNo: "1",
            ageComposition: 98,
            ageCompositionName: "60后",
            ascpId: 29195,
            categoryQuantity: 1,
            channelName: "零售",
            contactName: "131",
            deliveryPhone: "312",
            contractNo: "",
            cpId: 20760,
            customerCode: "13512341234-1002RE",
            customerForm: {
                customerPhone: "13512341234",
                customerId: 3578,
                addressName: "沈阳市浑南区人民政府(新聪街西)",
                addressNo: "1",
                addressFull: "辽宁省沈阳市浑南区沈阳市浑南区人民政府(新聪街西)1",
                customerCode: "13512341234-1002RE",
                customerName: "ZHANGZAHNG",
                addressGcj02: {
                    latitude: 41.71482,
                    longitude: 123.44972
                }
            }
        },
        customcustomerPhoneerForm: {
            addressArea: {
                city: "沈阳市",
                district: "浑南区",
                province: "辽宁省"
            },
            addressFull: "辽宁省沈阳市浑南区沈阳市浑南区人民政府(新聪街西)1",
            addressGcj02: {
                latitude: 41.71482,
                longitude: 123.44972
            },
            addressName: "沈阳市浑南区人民政府(新聪街西)",
            addressNo: "1",
            ageComposition: 98,
            ageCompositionName: "60后",
            customerCode: "13512341234-1002RE",
            customerFrom: -1,
            customerFromName: "自然客流",
            customerId: 3578,
            customerName: "ZHANGZAHNG",
            customerPhone: "13512341234",
            decisionMaker: 103,
            decisionMakerName: "驻店设计师",
            fitupStyle: 93,
            fitupStyleName: "欧美简约",
            fitupType: 88,
            fitupTypeName: "精装升级",
            houseType: 86,
            houseTypeName: "自建房",
            toiletCount: 9,
            toiletCountName: "别墅"
        },
        customerFrom: -1,
        customerFromName: "自然客流",
        customerId: 3578,
        customerName: "ZHANGZAHNG",
        customerPhone: "13512341234",
        decisionMaker: 103,
        decisionMakerName: "驻店设计师",
        deliveryTime: "2024/01/26 10:51:33",
        deliveryType: 70,
        deliveryTypeName: "仓库送货",
        designStatus: "设计状态-无需",
        discountPromotion: "100.00",
        discountStandard: "79.55",
        docCode: "销售订单",
        editTime: "",
        erpOrgCode: "",
        erpPushStatus: null,
        erpStaffCode: null,
        erpUserCode: null,
        estateId: null,
        fitupStyle: 93,
        fitupStyleName: "欧美简约",
        fitupType: 88,
        fitupTypeName: "精装升级",
        goodsList: [{
            activityId: 84,
            activityName: "零售活动方案",
            categoryQuantity: 1,
            desc: "零售活动方案",
            iscountPromotion: 100,
            discountStandard: "79.55",
            flgBomCombined: false,
            flgGift: false,
            flgInstalled: true,
            grossProfit: -39989,
            hasChild: 1,
            id: "af590eaf-7e92-450d-a1b6-d77dbcf7b69d",
            itemAmount: "70000.00",
            itemIndex: 0,
            itemQuantity: 1,
            orderItemQuantity: 1,
            packageDetailsFlag: false,
            parentId: null,
            pathType: 1,
            pricePromotion: 70000,
            priceSale: 70000,
            priceStandard: 88000,
            promotionId: 283,
            promotionName: "套餐相同商品",
            promotionPriceType: -2,
            promotionPriceTypeName: "正价产品",
            promotionType: 2,
            promotionTypeName: "组合促销",
            refCostAmt: 109989,
            refCostPrice: 109989,
            seq: 1,
            skuVolume: 0.454,
            skuWeight: 0,
            spuModel: "套餐相同商品",
            standardId: 308,
            tGrossProfit: -39989,
            tItemAmount: "70000.00",
            tItemQuantity: 1,
            tRefCostAmt: 109989,
            tRefCostPrice: 109989,
            title: "套餐相同商品",
            titleTag: "组合促销",
            warehouseId: 552,
            warehouseName: "钦州运营仓",
            whId: 552,
            whId_Name: "钦州运营仓"
        }]



    },



    /**
     * @desc : 商品明细更多
     * @author : 于继渤
     * @date : 2022/5/26 12:16
     */
    onChangeOpenGoodsList(e) {
        let goodsList = this.data.goodsList
        let index = e.currentTarget.dataset.index
        goodsList[index].packageDetailsFlag = !goodsList[index].packageDetailsFlag
        this.setData({
            goodsList
        })
    },


    /**
     * @desc : 抵扣预存离焦
     * @author : 于继渤
     * @date : 2022/5/26 12:16
     */
    balanceAmountBulr(e) {

        let form = this.data.form
        if (form.sumUsePrestore > form.usablePrestore) {
            form.sumUsePrestore = Number(form.usablePrestore)
            this.setData({
                form
            })
        }
        this.calculateReceivables()
    },
    /**
     * @desc : 抵扣预存输入事件
     * @author : 于继渤
     * @date : 2022/5/26 12:16
     */
    sumUsePrestoreBindinput(e) {


        let form = this.data.form
        if (e.detail.value) {
            form.sumUsePrestore = e.detail.value
        } else {
            form.sumUsePrestore = 0
        }
        this.setData({
            form: form
        })
    },
    /**
     * @desc : 服务费用离焦
     * @author : 于继渤
     * @date : 2022/5/26 12:16
     */
    sumFeeAmountBulr(e) {
        this.calculateReceivables()
    },

    /**
     * @desc : 服务费用输入事件
     * @author : 于继渤
     * @date : 2022/6/21 12:16
     */
    sumFeeAmountBindinput(e) {
        let form = this.data.form
        if (e.detail.value) {
            form.sumFeeAmount = e.detail.value
        } else {
            form.sumFeeAmount = 0
        }
        this.setData({
            form: form
        })

    },
    /**
     * @desc : 手风琴展开事件
     * @author : 于继渤
     * @date : 2022/5/26 12:16
     */
    onChange(event) {
        this.setData({
            activeNames: event.detail,
        });
    },


    /**
     * @desc : 打开客户基本信息
     * @author : 于继渤
     * @date : 2022/5/26 12:16
     */
    openCustomer() {
        this.setData({
            showEditCustomer: true
        })
    },
    /**
     * @desc : 关闭客户基本信息
     * @author : 于继渤
     * @date : 2022/5/26 12:16
     */
    closeChoosedItemInfo() {
        this.setData({
            showEditCustomer: false
        })
    },
    /**
     * @desc : 组件单选下拉打开事件
     * @author : 于继渤
     * @date : 2022/5/26 17:16
     */
    openSingle(e) {
        let type = e.currentTarget.dataset.type
        if (type === 'customerFrom') {

            this.setData({
                customerSourceFlag: true
            })
        }
        if (type === 'toiletCount') {
            this.setData({
                numberToiletsFlag: true
            })
        }

        if (type === 'fitupType') {
            this.setData({
                decorationTypeFlag: true
            })
        }

        if (type === 'houseType') {
            this.setData({
                houseTypeFlag: true
            })
        }

        if (type === 'fitupStyle') {
            this.setData({
                decorationStyleFlag: true
            })
        }
        if (type === 'ageComposition') {
            this.setData({
                ageCompositionFlag: true
            })
        }
        if (type === 'decisionMaker') {
            this.setData({
                decisionMakerFlag: true
            })
        }
        if (type === 'deliveryType') {
            this.setData({
                deliveryTypeFlag: true
            })
        }
    },

    /**
     * @desc : 组件单选确定
     * @author : 于继渤
     * @date : 2022/5/26 17:16
     */
    mutiSearch(e) {
        let id = e.target.id
        let customerForm = this.data.customerForm
        let form = this.data.form
        if (id === 'customerFrom') {
            form.customerForm.customerFromName = e.detail.name
            form.customerForm.customerFrom = e.detail.id
        }
        if (id === 'toiletCount') {
            form.customerForm.toiletCountName = e.detail.name
            form.customerForm.toiletCount = e.detail.id
        }
        if (id === 'fitupType') {
            form.customerForm.fitupTypeName = e.detail.name
            form.customerForm.fitupType = e.detail.id
        }
        if (id === 'houseType') {
            form.customerForm.houseTypeName = e.detail.name
            form.customerForm.houseType = e.detail.id
        }

        if (id === 'fitupStyle') {
            form.customerForm.fitupStyleName = e.detail.name
            form.customerForm.fitupStyle = e.detail.id
        }
        if (id === 'ageComposition') {
            form.customerForm.ageCompositionName = e.detail.name
            form.customerForm.ageComposition = e.detail.id
        }
        if (id === 'decisionMaker') {
            form.customerForm.decisionMakerName = e.detail.name
            form.customerForm.decisionMaker = e.detail.id
        }
        if (id === 'deliveryType') {
            form.deliveryTypeName = e.detail.name
            form.deliveryType = e.detail.id
        }

        this.setData({
            form: form,
            customerForm: customerForm
        })
    },


    /**
     * @desc : 计算需收款
     * @author : 于继渤
     * @date : 2022/6/16 17:16
     */
    calculateReceivables(item) {
        let form = util.copyObj(this.data.form)
        // 处理小数位数
        form.tSumGoodsAmount = form.tSumGoodsAmount ? Number(form.tSumGoodsAmount).toFixed(2) : 0
        form.sumFeeAmount = form.sumFeeAmount ? Number(form.sumFeeAmount).toFixed(2) : 0
        // 合计金额=货物总额+服务费用
        form.tSumAmount = util.AddNumber(Number(form.tSumGoodsAmount), Number(form.sumFeeAmount))
        form.sumAmount = util.AddNumber(Number(form.tSumGoodsAmount), Number(form.sumFeeAmount))
        // 需收款金额=合计金额-实收金额
        let numNeed = util.SubNumber(Number(form.tSumAmount), Number(form.sumUsePrestore))
        form.needReceiptAmount = util.SubNumber(numNeed, Number(form.sumReceiptAmount))
        let sumCollectedAmountTemp = form.sumCollectedAmount
        form.sumCollectedAmount = util.AddNumber(Number(form.sumUsePrestore), Number(form.sumReceiptAmount)) //合计收款
        form.receivable = util.SubNumber(numNeed, Number(form.sumReceiptAmount)) //剩余应收
        // if (form.apvResult == '审-异常') {
        //   form.needReceiptAmount = Number(  form.needReceiptAmount - sumCollectedAmountTemp)
        //   form.sumCollectedAmount = util.AddNumber(Number(form.sumUsePrestore), Number(form.sumReceiptAmount)) //合计收款
        //   form.receivable = Number(util.SubNumber(numNeed, Number(form.sumReceiptAmount)) - sumCollectedAmountTemp) //剩余应收
        // }


        this.setData({
            form: form,
            totallength: form.receivable
        })


    },
    /**
     * @desc : 安装送货标识触发事件
     * @author : 于继渤
     * @date : 2022/5/26 12:16
     */
    changeCheckBox(e) {
        let key = e.currentTarget.dataset.key
        let item = e.currentTarget.dataset.item
        let form = this.data.form

        if (key === 'DeliveryFlag') {
            form.DeliveryFlag = !item
            if (!item) {
                form.deliveryTime = util.formatDataTime(new Date(new Date().getTime() + 100))
                this.setData({
                    DeliveryFlag_time_flag: true,
                    deliveryTimeDefaultSearch: new Date().getTime() + 100

                })
            } else {
                form.deliveryTime = ''
            }

            this.setData({
                form: form
            })
        }

    },
    /**
     * @desc : 标识日期打开事件
     * @author : 于继渤
     * @date : 2022/5/26 17:16
     */
    openData(e) {
        this.setData({
            DeliveryFlag_time_flag: true
        })
    },



    /**
     * @desc : 标识日期关闭事件
     * @author : 于继渤
     * @date : 2022/5/26 17:16
     */
    onCloseChooseDate(e) {
        let key = e.currentTarget.dataset.key
        //送货标识
        if (key === 'delivery') {
            this.setData({
                DeliveryFlag_time_flag: false
            })
        }
    },


    /**
     * @desc : 标识日期变化事件
     * @author : 于继渤
     * @date : 2022/5/26 17:16
     */
    changeDate(e) {
        let key = e.currentTarget.dataset.key
        //送货标识
        if (key === 'deliveryTime') {
            this.setData({
                deliveryTimeDefaultSearch: e.detail
            })
        }
    },


    /**
     * @desc : 标识时间确认事件
     * @author : 于继渤
     * @date : 2022/5/26 17:16
     */
    onConfirmChooseDate(e) {
        let key = e.currentTarget.dataset.key
        let form = this.data.form
        console.log(key)
        //送货标识
        if (key === 'deliveryTime') {
            form.deliveryTime = util.formatDataTime(new Date(this.data.deliveryTimeDefaultSearch)).replaceAll('-', '/')
            console.log('form.deliveryTime', form.deliveryTime)
            this.setData({
                DeliveryFlag_time_flag: false,
                form: form
            })
        }
    },

    /**
     * @desc : 编辑格式化数据
     * @date : 2022/5/13 16:49
     * @author : 于继渤
     */
    editOrderItemListFormat(orderItemVOList) {
        let goodsList = []
        orderItemVOList.forEach(item => {
            goodsList.push({
                itemId: item.itemId,
                skuName: item.skuName,
                skuCode: item.skuCode,
                spuCode: item.spuCode,
                spuId: item.spuId,

                skuId: item.skuId,
                priceSale: item.priceSale, //售价
                itemQuantity: item.itemQuantity, //数量
                nonstandardRemarks: item.nonstandardRemarks, //非标备注
                useLocation: item.usedLocation, //使用位置
                remarks: item.remarks, //使用位置

                goodsSkuList: this.editgGoodsSkuListFormat(item.goodsSkuList)
            })
        })
        return goodsList
    },

    /**
     * @desc : 编辑商品子信息
     * @author : 于继渤
     * @date : 2022/5/31 18:16
     */
    editgGoodsSkuListFormat(goodsSkuList) {
        let goodsSkuListTemp = []
        goodsSkuList.forEach(item => {
            goodsSkuListTemp.push({
                itemId: item.itemId,
                orderId: item.orderId,
                skuCode: item.skuCode,
                skuId: item.skuId,
                skuType: item.skuType,
                usedLocation: item.usedLocation,
                priceSale: item.priceSale,
                orderItemQuantity: item.orderItemQuantity

            })
        })
        return goodsSkuListTemp
    },
    /**
     * @desc : 输入事件
     * @date : 2022/6/25 16:49
     * @author : 于继渤
     */
    changeField(e) {
        let form = this.data.form
        let key = e.currentTarget.dataset.key
        if (key === 'remarks') {
            form.remarks = e.detail
        }
        if (key === 'contractNo') {
            form.contractNo = e.detail
        }
        if (key === 'remarksInside') {
            form.remarksInside = e.detail
        }
        this.setData({
            form
        })
    },
    // //输入离焦事件
    changeFieldblur(e) {
        // if (e.detail.value) {
        //   this.getOrderContractNoCount(e.detail.value)
        // }

    },
    //查询合同号
    getOrderContractNoCount(contractNo) {
        api.request(Constants.SALE_ORDER_API + 'get_order_contract_no_count', 'POST', {
            orderId: this.data.form.orderId ? this.data.form.orderId : null,
            contractNo: contractNo,
            cpId: app.globalData.user.cpId,
            orderStatusList: [
                "订单状态-报价", "订单状态-待审", "订单状态-通过", "订单状态-审中", "订单状态-拒绝"
            ]

        }).then(res => {
            if (res.data.code == 200) {
                let contractNoFlag = false
                if (res.data.data > 0) {
                    wx.showToast({
                        title: '合同号重复!',
                        icon: 'none'
                    })
                    contractNoFlag = true
                }
                this.setData({
                    contractNoFlag: contractNoFlag
                })

            }
        })
    },
    /**
     * @desc : 校验合同号是否存在
     * @author : 周兴
     * @date : 2022/11/14 12:16
     */
    checkOrderContractNoCount() {
        let contractNo = this.data.form ? this.data.form.contractNo : '';
        return new Promise(resolve => {
            // 空不校验
            if (!contractNo) {
                resolve(true)
            }
            api.request(Constants.SALE_ORDER_API + 'get_order_contract_no_count', 'POST', {
                contractNo: contractNo,
                orderId: this.data.form.orderId ? this.data.form.orderId : null,
                cpId: app.globalData.user.cpId,
                orderStatusList: [
                    "订单状态-报价", "订单状态-待审", "订单状态-通过", "订单状态-审中", "订单状态-拒绝"
                ]
            }).then(res => {
                if (res.data.code == 200) {
                    if (res.data.data > 0) {
                        resolve(false)
                    } else {
                        resolve(true)
                    }
                }
                resolve(true)
            })
        })
    },
    deal(){
        wx.navigateTo({
            url: '../collection-confirm/collection-confirm' 
          })
    },
    /**
     * @desc : 提交
     * @date : 2022/6/25 16:49
     * @author : 于继渤
     */
    submit(e) {
        wx.navigateBack({
            delta: 3
        })
        return

    },
    // submit 接口 成功回调跳转的内容封装成 方法
    submitSuccess() {
        let _that = this
        //首页购物车跳转列表页
        if (this.data.pageIndex == 'shopping') {
            setTimeout(function () {
                wx.reLaunch({
                    url: '/pages/home-page/home-page?pageType=1',
                })
            }, 1000)
            return
        }
        if (this.data.pageIndex == 'receiveCustomers') {
            wx.navigateBack({
                delta: 3
            })
            return
        }
        var pages = getCurrentPages();
        //列表报价右上角成交订单返回列表页
        if (_that.data.page === 'orderBillingDeal') {

            var prevPage = pages[pages.length - 2];
            if (prevPage) {
                prevPage.setData({
                    orderAddFlag: true
                })
            }

            setTimeout(function () {
                wx.navigateBack({
                    delta: 1
                })
            }, 1200)
        } else if (_that.data.page === 'orderBillingAdd' && _that.data.form.orderId) {

            //返回列表页面
            var prevPage = pages[pages.length - 4];
            //  prevPage.clearFormData()
            if (prevPage) {
                prevPage.setData({
                    orderAddFlag: true
                })
            }
            setTimeout(function () {
                wx.navigateBack({
                    delta: 3
                })
            }, 1200)
        } else if (_that.data.page === 'orderBillingAdd' && !_that.data.form.orderId) {

            //返回列表页面
            var prevPage = pages[pages.length - 5];
            //  prevPage.clearFormData()
            if (prevPage) {
                prevPage.setData({
                    orderAddFlag: true
                })
            }

            setTimeout(function () {
                wx.navigateBack({
                    delta: 4
                })
            }, 1200)

        } else {

            //返回列表页面
            var prevPage = pages[pages.length - 4];
            //  prevPage.clearFormData()
            if (prevPage) {
                prevPage.setData({
                    orderAddFlag: true
                })
            }
            setTimeout(function () {
                wx.navigateBack({
                    delta: 3
                })
            }, 1200)
        }
    },

    /**
     * @desc : 查询单据多业务归属
     * @author : 于继渤
     * @date : 2022/7/07 16:16
     */
    getOrderMultiOwner(id) {
        api.request(Constants.ORDER_MULTI_OWNER_API + 'select_order_multi_owner', 'POST', {
            orderId: id
        }).then(res => {
            if (res.data.code === 200) {
                let item = res.data.data
                let form = this.data.form
                item.orgList.forEach(it => {
                    it.ownerFlag = it.ownerType == 1 ? true : false
                })
                item.staffList.forEach(it => {
                    it.ownerFlag = it.ownerType == 3 ? true : false
                })
                form.staffList = item.staffList
                form.orgList = item.orgList
                this.setData({
                    form: form
                })

            }

        })
    },


    /**
     * @desc : 获取单据数据
     * @date : 2022/5/13 16:49
     * @author : 于继渤
     */
    getData(orderId) {
        this.setData({
            loading: true
        })
        api.request(Constants.COMMON_METHOD + 'get_order_for_edit', 'POST', {
            orderId: Number(orderId)
        }).then(res => {

            this.setData({
                loading: false
            })
            if (res.data.code === 200) {
                let form = res.data.data.list[0]
                delete form['apvResultTime']
                let customerForm = {}
                customerForm.customerId = form.customerId
                customerForm.customerName = form.customerName
                customerForm.customerPhone = form.customerPhone
                customerForm.addressName = form.addressName
                customerForm.addressNo = form.addressNo
                customerForm.addressFull = form.addressFull
                customerForm.customerCode = form.customerCode
                customerForm.customerName = form.customerName
                customerForm.addressGcj02 = form.addressGcj02
                customerForm.addressArea = form.addressArea
                customerForm.customerFrom = form.customerFrom
                customerForm.decisionMaker = form.decisionMaker
                customerForm.fitupStyle = form.fitupStyle
                customerForm.fitupType = form.fitupType
                customerForm.houseType = form.houseType
                customerForm.toiletCount = form.toiletCount
                customerForm.ageComposition = form.ageComposition
                customerForm.customerFromName = form.customerFromName
                customerForm.decisionMakerName = form.decisionMakerName
                customerForm.fitupStyleName = form.fitupStyleName
                customerForm.fitupTypeName = form.fitupTypeName
                customerForm.houseTypeName = form.houseTypeName
                customerForm.toiletCountName = form.toiletCountName
                customerForm.ageCompositionName = form.ageCompositionName
                form.deliveryTime = util.formatDataTime(new Date(new Date().getTime() + 100)).replaceAll('-', '/') //送货时间
                // form.makingTime = util.formatDataTime(new Date(form.makingTime)).replaceAll('-', '/')//
                form.customerForm = customerForm
                form.orgCode = form.erpOrgCode
                form.staffCode = form.erpStaffCode
                form.erpStaffCode = form.erpStaffCode
                form.erpOrgCode = form.erpOrgCode
                form.sumReceipt = form.sumReceiptAmount + form.sumUsePrestore
                //业务归属
                this.getOrderMultiOwner(orderId)
                this.getOrderGoodsList(orderId)
                this.getCustomerAmount(form.customerId, form.orgId)
                this.setData({
                    form: form,
                    deliveryTimeDefaultSearch: new Date().getTime() + 100,
                    goodsList: this.setOrderItem(form.orderItemVOList) //显示用
                })
                this.getDeliveryType()

            }
        })
    },


    /**
     * @desc : 给明细数据赋值
     * @date : 2022/6/30 16:49
     * @author : 周兴
     */
    setOrderItem(orderItemList) {
        let goodsList = []
        orderItemList.forEach(item => {
            item.goodsSkuList = item.bomItems
            goodsList.push(item);
        })
        // 处理图标
        common.setSkuIcon(goodsList);
        return goodsList
    },


    /**
     * @desc : 查询客户款项信息
     * @author : 于继渤
     * @date : 2022/6/20 15:33
     */
    getCustomerAmount(customerId, orgId) {
        this.setData({
            loading: true
        })
        let param = {
            customerId: customerId,
            orgId: orgId
        }
        api.request(Constants.SALE_ORDER_API + 'select_customer_amount', 'POST', param).then(res => {
            this.setData({
                loading: false
            })
            if (res.data.code === 200) {
                let form = this.data.form
                if (res.data.data) {
                    form.usablePrestore = res.data.data.usablePrestore ? res.data.data.usablePrestore : 0
                    if (form.sumAmount <= res.data.data.usablePrestore && res.data.data.usablePrestore != 0) {
                        form.sumUsePrestore = Number(form.sumAmount)
                    } else {
                        form.sumUsePrestore = Number(res.data.data.usablePrestore)
                    }

                    this.setData({
                        form: form
                    })

                } else {
                    form.usablePrestore = 0
                }
                //计算
                this.calculateReceivables()
            }

        })
    },
    /**
     * @desc : 获取单据信息
     * @author : 于继渤
     * @date : 2022/5/31 18:16
     */
    getOrderGoodsList(orderId) {
        let param = {
            orderId: orderId
        }
        api.request(Constants.SALE_ORDER_API + 'select_by_order_id', 'POST', param).then(res => {
            this.setData({
                loading: false
            })
            if (res.data.code === 200) {
                let data = res.data.data
                delete data['apvResultTime']
                let form = this.data.form
                form.estateName = data.estateName
                form.channelName = data.channelName
                form.salesChannelName = data.salesChannelName
                form.customerFromName = data.customerFromName
                form.customerCode = data.customerCode
                form.customerForm.addressArea = data.addressArea
                form.sumCollectedAmount = data.sumCollectedAmount
                form.customerForm.decisionMakerName = data.decisionMakerName
                form.customerForm.fitupStyleName = data.fitupStyleName
                form.customerForm.fitupTypeName = data.fitupTypeName
                form.customerForm.houseTypeName = data.houseTypeName
                form.customerForm.toiletCountName = data.toiletCountName
                form.customerForm.ageCompositionName = data.ageCompositionName

                form.customerForm.customerFromName = data.customerFromName //客户来源
                this.setData({
                    form,
                    orderItemVOList: data.orderItemVOList
                })
            }

        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {





    },
    /**
     * @desc : 送货状态
     * @author : 于继渤
     * @date : 2022/5/31 18:16
     */
    getDeliveryType() {
        let param = {}
        param.cpId = app.globalData.user.cpId
        param.dataSourceCode = 'deliveryType'
        param.sysId = app.globalData.user.sysId
        api.request(Constants.BASIC_COMMON_API + 'get_wx_init_data', 'POST', param).then(res => {
            if (res.data.code === 200) {
                let list = res.data.data
                let form = this.data.form
                if (list.length > 0) {
                    list.forEach(it => {
                        if (it.name === '仓库送货') {
                            form.deliveryTypeName = it.name
                            form.deliveryType = it.id
                        }
                    })
                    this.setData({
                        form: form
                    })
                }
            }
        })
    },

    /**
     * @desc : 订单上传附件方法
     * @author : 于继渤
     * @date : 2022/6/02 16:16
     */
    afterRead(event) {
        this.setData({
            uploadFileFlag: true
        })
        const _this = this;
        const {
            file
        } = event.detail;
        let annexPaths = _this.data.annexPaths
        let arr = _this.data.fileList;
        file.forEach(res => {
            // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
            wx.uploadFile({
                url: `${config.server_add}:${config.server_port}` + '/basic-server/file/upload',
                filePath: res.path,
                name: 'file',
                formData: {
                    'folder': 't_order/annex_paths'
                },
                header: {
                    'Authorization': 'Bearer ' + app.globalData.token
                },
                success(res) {
                    let data = JSON.parse(res.data)
                    if (data.code === 200) {
                        _this.setData({
                            uploadFileFlag: false
                        })
                        arr.push({
                            url: data.data.absolutelyPath,
                            FilePath: data.data.relativePath,
                            deletable: true
                        })
                        let file = data.data.relativePath.split('/')
                        annexPaths.push({
                            url: data.data.relativePath,
                            type: 'image',
                            docType: '销售订单',
                            name: file[file.length - 1],
                            createTime: util.formatDataTime(new Date())
                        })

                        _this.setData({
                            fileList: arr,
                            annexPaths: annexPaths
                        })
                    }
                },
            })
        })

    },

    /**
     * @desc : 删除图片
     * @author : 于继渤
     * @date : 2022/5/31 18:16
     */
    deleteImg(e) {
        let index = e.detail.index;
        let arr = this.data.fileList;
        arr.splice(index, 1);
        this.setData({
            fileList: arr
        })
    },

})