details.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // CRM/customer/modules/order/details.js
  2. const _Http = getApp().globalData.http,
  3. currency = require("../../../../utils/currency"),
  4. CNY = value => currency(value, {
  5. symbol: "¥",
  6. precision: 2
  7. }).format();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. list: [],
  14. loading: false,
  15. sa_custorderid: '',
  16. content: {
  17. nocache: true,
  18. pageNumber: 1,
  19. pageSize: 20,
  20. pageTotal: 1,
  21. total: null
  22. }
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad(options) {
  28. if (options.id) {
  29. this.setData({ sa_custorderid: options.id });
  30. this.getList(options.id, true);
  31. }
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady() {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow() {
  42. },
  43. /**
  44. * 生命周期函数--监听页面隐藏
  45. */
  46. onHide() {
  47. },
  48. /**
  49. * 生命周期函数--监听页面卸载
  50. */
  51. onUnload() {
  52. },
  53. /**
  54. * 页面相关事件处理函数--监听用户下拉动作
  55. */
  56. onPullDownRefresh() {
  57. this.getList(this.data.sa_custorderid, true);
  58. wx.stopPullDownRefresh();
  59. },
  60. /**
  61. * 页面上拉触底事件的处理函数
  62. */
  63. onReachBottom() {
  64. if (this.data.content.pageNumber <= this.data.content.pageTotal) {
  65. this.getList(this.data.sa_custorderid, false);
  66. }
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage() {
  72. },
  73. /**
  74. * 获取订单明细列表
  75. */
  76. getList(id, init) {
  77. let content = this.data.content;
  78. content.sa_custorderid = id || this.data.sa_custorderid;
  79. if (init) {
  80. content.pageNumber = 1;
  81. this.setData({ loading: true });
  82. }
  83. _Http.basic({
  84. "id": "2026031414243401",
  85. content
  86. }).then(res => {
  87. this.setData({ loading: false });
  88. console.log("订单明细列表", res)
  89. if (res.code != 1) return wx.showToast({
  90. title: res.msg,
  91. icon: "none"
  92. })
  93. // 格式化金额数据
  94. const formattedData = res.data.map(item => {
  95. const amount = (item.price || 0) * (item.qty || 0);
  96. return {
  97. ...item,
  98. showPrice: CNY(item.price || 0),
  99. showAmount: CNY(amount)
  100. };
  101. })
  102. this.setData({
  103. list: res.pageNumber == 1 ? formattedData : this.data.list.concat(formattedData),
  104. "content.pageNumber": res.pageNumber + 1,
  105. "content.pageSize": res.pageSize,
  106. "content.pageTotal": res.pageTotal,
  107. "content.total": res.total
  108. })
  109. })
  110. }
  111. })