// pages/consumptionDetails.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo

wxService.page({
  /**
   * 页面的初始数据
   */
  data: {
    no: '112222',
    time: '2019-01-01',
    store: '1231',
    totalNum: 0,
    orderTotal: 50,
    paymentTotal: 48,
    pointsTotal: 2,
    status: '交易成功',
    themeArr: { count: '数量', name: '商品名称', price: '价格' },
    itemArr: [],
    orderDetail: {},
    isShowDetail: false
  },

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

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
    const { orderNo } = this.options
    if(orderNo){
      this.initOrderDetail(orderNo)
    }
    // this.initOrderDetail('71101890016405620191224163858')
  },

  initOrderDetail(orderNo){
    wx.showLoading({
      title: '加载中'
    })
    wxService.get(`/sale/order/findByOrderNo?orderNo=${orderNo}&brandId=${app.globalData.brandId}`).then(res => {
      const {result,data} = res.data
      if(result == 0){
         wx.hideLoading()
        // 数量
        let countArr = []
        data.productInfo.forEach(item=>{
          countArr.push(item.productCount)
        })
        let countTotal = countArr.reduce((prev,cur)=>{
          return prev + cur ;
        })
        this.setData({
          orderDetail: data,
          totalNum: countTotal,
          isShowDetail: Reflect.ownKeys(data).length? true : false
        })
      }
    }).finally(() => {
     
    })
  }

})