index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. const _Http = getApp().globalData.http;
  2. import currency from "../../utils/currency";
  3. let CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. loading: true,
  10. params: {}, //请求体
  11. result: [], //返回结果
  12. radio: false, //是否为单选
  13. idname: "sa_accountclassid", //idkey
  14. showName: "accountname"
  15. },
  16. onLoad(options) {
  17. if (options.params) {
  18. let params = JSON.parse(options.params);
  19. if (!params.content.pageNumber || !params.content.pageTotal) {
  20. params.content.pageNumber = 1;
  21. params.content.pageTotal = 1;
  22. }
  23. this.setData({
  24. params
  25. });
  26. }
  27. this.setData({
  28. radio: options.radio ? true : false,
  29. idname: options.idname || this.data.idname,
  30. showName: options.showName || this.data.showName,
  31. });
  32. this.getList()
  33. },
  34. getList(init = false) {
  35. //init 用于初始化分页
  36. if (init.detail != undefined) init = init.detail;
  37. let params = this.data.params;
  38. if (init) params.content.pageNumber = 1
  39. if (params.content.pageNumber > params.content.pageTotal) return;
  40. _Http.basic(params).then(res => {
  41. console.log("选择账户列表", res)
  42. this.selectComponent('#ListBox').RefreshToComplete();
  43. if (res.msg != '成功') return wx.showToast({
  44. title: res.msg,
  45. icon: "none"
  46. })
  47. res.data = res.data.map(v => {
  48. v.balance = CNY(v.balance)
  49. v.creditquota = CNY(v.creditquota)
  50. return v
  51. })
  52. this.setData({
  53. 'params.content.pageNumber': res.pageNumber + 1,
  54. 'params.content.pageTotal': res.pageTotal,
  55. 'params.content.total': res.total,
  56. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  57. loading: false
  58. })
  59. })
  60. },
  61. /* 选中 */
  62. changeResult(e) {
  63. let {
  64. id
  65. } = e.currentTarget.dataset, result = this.data.result;
  66. if (this.data.radio) {
  67. result = [id];
  68. } else {
  69. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  70. }
  71. this.setData({
  72. result
  73. });
  74. if (this.data.radio) this.submit();
  75. },
  76. /* 提交 */
  77. submit() {
  78. let result = this.data.result,
  79. obj = this.data.radio ? {
  80. id: result,
  81. item: this.data.list.find(value => value[this.data.idname] == result),
  82. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  83. } : {
  84. result,
  85. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  86. value: [result.map(v => {
  87. let data = this.data.list.find(value => value[this.data.idname] == v);
  88. return data ? data[this.data.showName] : ""
  89. }), result]
  90. }
  91. console.log(obj);
  92. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  93. },
  94. /* 开始搜索 */
  95. startSearch({
  96. detail
  97. }) {
  98. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  99. if (detail == condition) return;
  100. this.setData({
  101. 'content.where.condition': detail,
  102. 'params.content.where.condition': detail
  103. });
  104. this.getList(true);
  105. },
  106. /* 取消搜索 */
  107. onClear() {
  108. this.setData({
  109. 'content.where.condition': "",
  110. 'params.content.where.condition': ""
  111. });
  112. this.getList(true);
  113. },
  114. onReady() {
  115. this.selectComponent("#ListBox").setHeight(".total", this);
  116. },
  117. onUnload() {
  118. //回收数据
  119. getApp().globalData.handleSelect = null;
  120. }
  121. })