const _Http = getApp().globalData.http,
  currency = require("../../utils/currency"),
  CNY = value => currency(value, {
    symbol: "￥",
    precision: 2
  }).format();

Page({
  data: {
    detail: {},
    list: [],
    "content": {
      "where": {
        "condition": ""
      },
      "pageNumber": 1,
      "pageTotal": 1,
      "pageSize": 20
    }
  },
  onLoad(options) {
    let item = JSON.parse(options.item);
    this.setData({
      detail: item
    })
    this.getList(true);
  },
  getList(init = false) {
    if (init.detail != undefined) init = init.detail;
    let content = this.data.content;
    if (init) content.pageNumber = 1;
    if (content.pageNumber > content.pageTotal) return;
    content.sa_hrcashbillid = this.data.detail.sa_hrcashbillid;
    _Http.basic({
      "id": 20240111131304,
      content
    }).then(res => {
      console.log("凭证明细列表", res)
      this.selectComponent('#ListBox').RefreshToComplete();
      res.data = res.data.map(v => {
        v.showOrderprice = CNY(v.orderprice) //订单单价
        v.showPrice = CNY(v.price) //提成单价
        v.showAmount = CNY(v.amount) // 支出的“调整金额”；收入的“提成金额”
        v.showCashbilldetailamount = CNY(v.cashbilldetailamount) // 支出的“提成金额”
        v.showOrderExpectedamount = CNY(v.orderExpectedamount) //预计提成金额
        v.showRewardamount = CNY(v.rewardamount) //已提成金额
        v.showPayapplyamount = CNY(v.payapplyamount) //已发放金额
        v.showUnpayapplyamount = CNY(v.unpayapplyamount) //未发放金额
        v.showOrderamount = CNY(v.orderamount)
        return v
      })
      this.setData({
        list: res.pageNumber == 1 ? res.data : this.data.list.concat(this.data.list),
        "content.pageNumber": res.pageNumber + 1,
        "content.pageTotal": res.pageTotal,
        "content.sort": res.sort
      })
    })
  },
  startSearch({
    detail
  }) {
    console.log(detail)
    this.setData({
      'content.where.condition': detail
    })
    this.getList(true);
  },
  onReady() {
    this.setListHeight()
  },
  /* 设置页面高度 */
  setListHeight() {
    this.selectComponent("#ListBox").setHeight(".search", this);
  },
})