index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. let list = res.data.filter(v => v.accountno != '02')
  53. this.setData({
  54. 'params.content.pageNumber': res.pageNumber + 1,
  55. 'params.content.pageTotal': res.pageTotal,
  56. 'params.content.total': res.total,
  57. list: res.pageNumber == 1 ? list : this.data.list.concat(list),
  58. loading: false
  59. })
  60. })
  61. },
  62. /* 选中 */
  63. changeResult(e) {
  64. let {
  65. id
  66. } = e.currentTarget.dataset, result = this.data.result;
  67. if (this.data.radio) {
  68. result = [id];
  69. } else {
  70. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  71. }
  72. this.setData({
  73. result
  74. });
  75. if (this.data.radio) this.submit();
  76. },
  77. /* 提交 */
  78. submit() {
  79. let result = this.data.result,
  80. obj = this.data.radio ? {
  81. id: result,
  82. item: this.data.list.find(value => value[this.data.idname] == result),
  83. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  84. } : {
  85. result,
  86. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  87. value: [result.map(v => {
  88. let data = this.data.list.find(value => value[this.data.idname] == v);
  89. return data ? data[this.data.showName] : ""
  90. }), result]
  91. }
  92. console.log(obj);
  93. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  94. },
  95. /* 开始搜索 */
  96. startSearch({
  97. detail
  98. }) {
  99. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  100. if (detail == condition) return;
  101. this.setData({
  102. 'content.where.condition': detail,
  103. 'params.content.where.condition': detail
  104. });
  105. this.getList(true);
  106. },
  107. /* 取消搜索 */
  108. onClear() {
  109. this.setData({
  110. 'content.where.condition': "",
  111. 'params.content.where.condition': ""
  112. });
  113. this.getList(true);
  114. },
  115. onReady() {
  116. this.selectComponent("#ListBox").setHeight(".total", this);
  117. },
  118. onUnload() {
  119. //回收数据
  120. getApp().globalData.handleSelect = null;
  121. }
  122. })