const _Http = getApp().globalData.http;
import currency from "../../utils/currency";
let CNY = value => currency(value, {
  symbol: "",
  precision: 2
}).format();
Page({
  data: {
    table: [{
      title: '客户名',
      width: 330,
      key: 'enterprisename',
      fun: 'toDetail'
    }, {
      title: '业务员',
      width: 200,
      key: 'name'
    }, {
      title: '订单号',
      width: 300,
      key: 'sonum'
    }, {
      title: '审核时间',
      width: 300,
      key: 'checkdate'
    }, {
      title: '订单行号',
      width: 200,
      key: 'rowno'
    }, {
      title: '商品编码',
      width: 300,
      key: 'itemno'
    }, {
      title: '商品名称',
      width: 300,
      key: 'itemname'
    }, {
      title: '型号',
      width: 200,
      key: 'model'
    }, {
      title: '规格',
      width: 200,
      key: 'spec'
    }, {
      title: '数量',
      width: 200,
      key: 'qty'
    }, {
      title: '金额',
      width: 200,
      key: 'amount'
    }, {
      title: '应收金额',
      width: 200,
      key: 'overdueamount'
    }],
    sumWidth: 0,
    "content": {
      "pageNumber": 1,
      "pageSize": 30,
      "dataid": "4222", // 按业务员时 传userid 按客户时传 sa_customersid
      "querytype": "1", //0按业务员 1按客户
      "point": "全部", //入账节点
      "where": {
        "condition": ""
      }
    }
  },
  onLoad(options) {
    let content = JSON.parse(options.content);
    content.pageNumber = 1;
    content.pageTotal = 1;
    this.data.content = content;
    this.setData({
      sumWidth: this.data.table.reduce((prev, cur) => {
        return prev.width ? prev.width + cur.width : prev + cur.width
      })
    })
    this.getList()
  },
  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;
    _Http.basic({
      "id": 202400321085104,
      content
    }).then(res => {
      this.setListHeight()
      this.selectComponent('#ListBox').RefreshToComplete();
      console.log("应收账款明细", res)
      let list = res.data.map(v => {
        v.amount = CNY(v.amount)
        v.overdueamount = CNY(v.overdueamount)
        return v
      })
      this.setData({
        list: res.pageNumber == 1 ? list : this.data.list.concat(list),
        "content.pageNumber": res.pageNumber + 1,
        "content.pageTotal": res.pageTotal,
        "content.total": res.total,
      })
    })
  },
  onReady() {
    this.setListHeight()
  },
  /* 设置页面高度 */
  setListHeight() {
    this.selectComponent("#ListBox").setHeight(".roof", this);
  },
})