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

  /**
   * 页面的初始数据
   */
  data: {
    goodsList: [
        {
        bomSkuId: null,
        brandName: "恒洁卫浴",
        cpId: 20760,
        differenceAmount: 0,
        differencePrice: 0,
        entryAmount: 999,
        entryGoingAmount: 999,
        entryGoingQuantity: 1,
        entryGoingTime: "2024-01-12 14:48:03",
        entryId: null,
        entryItemId: null,
        entryNo: null,
        entryQuantity: 1,
        entryStatus: "入库状态-完成",
        entryTime: "2024-01-12 14:48:03",
        entryWhId: 552,
        entryWhName: null,
        erpOutItemId: 1435645,
        erpOutNo: null,
        erpPushStatusString: null,
        flgValid: true,
        itemId: 2859,
        itemIndex: 1,
        nonStandardCode: "-",
        orderAmount: 5994,
        orderId: 11751,
        orderItemId: 35495,
        orderItemRejectAmount: -999,
        orderItemRejectQuantity: -1,
        orderNo: null,
        orderOutItemRejectAmount: -999,
        orderOutItemRejectQuantity: -1,
        orderOutReject: null,
        orderOutRejectResponse: {
        addressArea: null,
        addressFull: null,
        addressGcj02: null,
        addressName: null,
        addressNo: null,
        apvResult: null,
        apvResultName: null,
        apvResultTime: null,
        apvSubmitId: null,
        apvUserIds: null,
        ascpId: null,
        categoryQuantity: null,
        contactName: null,
        deliveryPhone: null,
        contractNo: null,
        cpCode: null,
        cpId: 20760,
        cpName: null,
        customerFrom: null,
        customerId: null,
        customerName: null,
        customerPhone: null,
        deliveryDate: null,
        docCode: null,
        doneUserName: null,
        editTime: null,
        entryId: null,
        entryNo: null,
        entryStatus: null,
        entryStatusString: null,
        erpApvResult: null,
        erpApvResultMsg: null,
        erpApvResultTime: null,
        erpDocNo: null,
        erpOutNo: null,
        erpPushResult: null,
        erpPushStatus: null,
        erpPushStatusName: null,
        erpPushStatusString: null,
        flgAllowReverse: null,
        flgAllowTodone: null,
        flgAutoIvt: null,
        flgToErp: null,
        flgValid: true,
        makingTime: null,
        makingUser: null,
        makingUserName: null,
        makingUserPur: null,
        makingUserPurName: null,
        opCreateTime: null,
        orderId: 11751,
        orderNo: "SA-QZHJ-BFJ-202401120RXJ",
        orderOutRejectItemList: null,
        orgCode: null,
        orgId: null,
        orgName: null,
        outDate: null,
        outId: null,
        outNo: null,
        outStatus: null,
        outStatusString: null,
        outTime: null,
        refundAccount: null,
        refundMethod: null,
        rejectId: null,
        rejectNo: "SR-QZHJ-BFJ-202401120RXO",
        rejectOrderStatus: null,
        rejectReason: null,
        rejectReasonType: null,
        rejectReasonTypeName: null,
        rejectStatus: null,
        rejectStatusName: null,
        rejectStatusString: null,
        rejectType: null,
        rejectTypeName: null,
        remarks: null,
        sale1Id: null,
        sale1OrderRejectEntryId: null,
        sale1OrderRejectEntryNo: null,
        sale2Id: null,
        sale2OpeMode: null,
        sale2OrderRejectId: null,
        sale2OrderRejectNo: null,
        salesChannel: null,
        salesChannelCode: null,
        salesChannelName: null,
        srejectId: null,
        srejectNo: null,
        staffCode: null,
        staffId: null,
        staffName: null,
        sumEntryAmount: null,
        sumEntryQuantity: null,
        sumOutAmount: null,
        sumOutQuantity: null,
        sumRejectAmount: null,
        sumRejectFeeAmount: null,
        sumRejectGoodsAmount: null,
        sumRejectQuantity: null,
        supplierCode: null,
        supplierId: null,
        supplierName: null
        },
        orderPriceSale: 999,
        orderQuantity: 6,
        outAmount: null,
        outGoingAmount: null,
        outGoingQuantity: null,
        outGoingTime: null,
        outId: 3375,
        outItemId: 6157,
        outNo: "WO-QZHJ-000-202401120RXK",
        outOutAmount: 5994,
        outOutQuantity: 6,
        outQuantity: null,
        outRejectAmount: 0,
        outRejectQuantity: 0,
        outStatus: "3",
        outTime: null,
        outWhId: null,
        outWhName: null,
        refCostAmt: 18468,
        refCostPrice: 3078,
        rejectAmount: -999,
        rejectId: 2475,
        rejectNo: null,
        rejectPrice: 999,
        rejectQuantity: -1,
        rejectReason: null,
        rejectReasonType: null,
        rejectReasonTypeName: null,
        remarks: null,
        s2RejectNo: null,
        sale1OrderRejectEntryId: null,
        sale1OrderRejectEntryItemId: null,
        sale2OrderRejectId: null,
        sale2OrderRejectItemId: null,
        skuCode: "EE920A00200B01",
        skuId: 9537580,
        skuModel: null,
        skuName: "【已淘汰】智能盖板HE920",
        skuType: 0,
        skuTypeName: null,
        spuCategoryLevelName: "智能马桶\智能盖板",
        spuCode: "HE920",
        spuId: 65410,
        srejectId: null,
        srejectItemId: null,
        srejectNo: null,
        unitName: null,
        whId: 552,
        whName: "钦州运营仓"
        }
        ],
        item: {
            addressArea: {
            city: "深圳市",
            district: "福田区",
            province: "广东省"
            },
            addressFull: "广东省深圳市福田区这是啥科技(赛格康乐大厦店)88888888888",
            addressGcj02: {
            latitude: 22.542325,
            longitude: 114.08747
            },
            addressName: "这是啥科技(赛格康乐大厦店)",
            addressNo: "88888888888",
            apvResult: "审-通过",
            apvResultName: "通过",
            apvResultTime: "2024-01-12 14:48:03",
            apvSubmitId: null,
            apvUserIds: [],
            ascpId: 29195,
            categoryQuantity: 1,
            contactName: "88888888888",
            deliveryPhone: "88888888888",
            contractNo: "4444",
            cpCode: null,
            cpId: 20760,
            cpName: null,
            customerFrom: 29,
            customerId: 3917,
            customerName: "88888888888",
            customerPhone: "18888888881",
            deliveryDate: null,
            docCode: "销售退货",
            doneUserName: null,
            editTime: "2024-01-12 14:48:03",
            entryId: null,
            entryNo: null,
            entryStatus: "已入库",
            entryStatusString: null,
            erpApvResult: "审-通过",
            erpApvResultMsg: "",
            erpApvResultTime: "2024-01-12 14:48:15",
            erpDocNo: null,
            erpOutNo: "ZJSA72924011200007",
            erpPushResult: "操作成功",
            erpPushStatus: 1,
            erpPushStatusName: "推送成功",
            erpPushStatusString: null,
            flgAllowReverse: false,
            flgAllowTodone: false,
            flgAutoIvt: true,
            flgToErp: false,
            flgValid: true,
            makingTime: "2024/01/12 14:48:03",
            makingUser: 1005,
            makingUserName: "无库无ERP00001",
            makingUserPur: 968,
            makingUserPurName: "分销业务富安居",
            opCreateTime: null,
            orderId: 11751,
            orderNo: "SA-QZHJ-BFJ-202401120RXJ",
            orderOutRejectItemList: null,
            orgCode: "GXBH1002",
            orgId: 32402,
            orgName: "北海富安居店",
            outDate: null,
            outId: null,
            outNo: null,
            outStatus: null,
            outStatusString: null,
            outTime: "2024-01-12 14:48:02",
            refundAccount: null,
            refundMethod: null,
            rejectId: 2475,
            rejectNo: "SR-QZHJ-BFJ-202401120RXO",
            rejectOrderStatus: null,
            rejectReason: "1",
            rejectReasonType: 184,
            rejectReasonTypeName: null,
            rejectStatus: "退货状态-通过",
            rejectStatusName: "已退货",
            rejectStatusString: null,
            rejectType: 1,
            rejectTypeName: "退货单",
            remarks: null,
            sale1Id: 20760,
            sale1OrderRejectEntryId: null,
            sale1OrderRejectEntryNo: null,
            sale2Id: 29195,
            sale2OpeMode: "分销模式-代送",
            sale2OrderRejectId: null,
            sale2OrderRejectNo: null,
            salesChannel: null,
            salesChannelCode: null,
            salesChannelName: null,
            srejectId: null,
            srejectNo: null,
            staffCode: "12222222222@QZHJ",
            staffId: 1005,
            staffName: "无库无ERP00001",
            statusName: "已入库",
            sumEntryAmount: 999,
            sumEntryQuantity: 1,
            sumOutAmount: null,
            sumOutQuantity: null,
            sumRejectAmount: -999,
            sumRejectFeeAmount: 0,
            sumRejectGoodsAmount: -999,
            sumRejectQuantity: -1,
            supplierCode: null,
            supplierId: null,
            supplierName: null,
            tSumQuantity: -1,
            tSumAmount: -999
            },
            loading: false,
            activeNames: [
            "1"
            ]
  },
  /**
   * @desc : 获取单据数据
   * @date : 2022/5/13 16:49
   * @author : 于继渤
   */
  getData(item) {
    this.setData({
      loading: true
    })
    let param = {
      rejectId :item.rejectId
    }
    api.request(Constants.CUSTOMER_ORDER_OUT_REJECT + 'get_order_out_reject_item','POST', param).then(res => {
      this.setData({
        loading: false
      })
      if (res.data.code === 200) {
        let tgoodsList = this.data.goodsList
         tgoodsList = res.data.data.list
         let numQuantity = 0
         let numAmount = 0
         console.log('tgoodsList',tgoodsList)
         tgoodsList.forEach(res =>{
            numQuantity += res.orderOutItemRejectQuantity
            numAmount += res.orderOutItemRejectAmount
         })
         console.log('numQuantity',numQuantity)
         console.log('numAmount',numAmount)
         item.tSumQuantity = numQuantity
         item.tSumAmount = numAmount
         this.setData({
          item:item,
          activeNames: ['1'],
          goodsList:tgoodsList,
        })
      }
    })
  },

    /**
    * @desc : 给明细数据赋值
    * @date : 2022/6/30 16:49
    * @author : 周兴
    */
   setOrderItem(orderItemList) {
    let goodsList = []
    orderItemList.forEach(item => {
      item.warehouseName = item.whName
      item.warehouseId = item.whId
      item.whId_Name = item.warehouseName
      //组合促销
      if (item.promotionType == Constants.PROMOTION_TYPE.COMBINED) {
        item.title = item.spuModel ? item.spuModel : item.skuModel
      }
      //单品促销
      if (item.promotionType == Constants.PROMOTION_TYPE.PRMOTION) {
        item.title = item.skuModel
        item.desc = item.skuName
      }
      item.goodsSkuList = item.bomItems
      // 组合
      if (item.promotionType == 2) {
        item.combinedList = item.bomItems
      }
      goodsList.push(item);

    })

    // 处理图标
    common.setSkuIcon(goodsList);
    return goodsList
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },
  getSumAmount() {
    let form = this.data.item
    let goodsList = this.data.goodsList
    let sumGoodsAmount = 0
    let sumGoodsAmountTemp = 0
    goodsList.forEach(res => {
      //售价*数量
      sumGoodsAmount += Number(res.tItemAmount)
    })
    //合计金额
    form.sumAmount = (sumGoodsAmount + Number(form.sumFeeAmount)).toFixed(2) ? (sumGoodsAmount + Number(form.sumFeeAmount)).toFixed(2) : 0

    this.setData({
      //保存组件合计
      totallength: form.sumAmount,
      
      item: form
    })
  },

    /**
   * @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
    })
  },


  submit(){
    wx.navigateBack({
      delta: 1
  })
  },



    //展开
    collapseFlagChange(e) {
      this.setData({
        collapseFlag: !this.data.collapseFlag
      })
    },
})