index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. subvalues: [],
  16. privacyFieldC: []
  17. },
  18. onLoad(options) {
  19. if (options.params) {
  20. let params = JSON.parse(options.params);
  21. if (!params.content.pageNumber || !params.content.pageTotal) {
  22. params.content.pageNumber = 1;
  23. params.content.pageTotal = 1;
  24. }
  25. this.setData({
  26. params
  27. });
  28. }
  29. try {
  30. let privacyFieldC = wx.getStorageSync('auth').worderform.forms.selectaccount.formcols.map(v => v.title);
  31. this.setData({
  32. privacyFieldC
  33. })
  34. console.log("privacyFieldC", privacyFieldC)
  35. } catch (error) {
  36. console.error(error)
  37. }
  38. this.setData({
  39. radio: options.radio ? true : false,
  40. idname: options.idname || this.data.idname,
  41. showName: options.showName || this.data.showName,
  42. });
  43. let that = this;
  44. that.getList()
  45. },
  46. getList(init = false) {
  47. //init 用于初始化分页
  48. if (init.detail != undefined) init = init.detail;
  49. let params = this.data.params;
  50. if (init) params.content.pageNumber = 1
  51. if (params.content.pageNumber > params.content.pageTotal) return;
  52. let subvalues = this.data.subvalues;
  53. if (subvalues.length) params.pageSize = 9999
  54. _Http.basic(params).then(res => {
  55. console.log("选择账户列表", res)
  56. this.selectComponent('#ListBox').RefreshToComplete();
  57. if (res.msg != '成功') return wx.showToast({
  58. title: res.msg,
  59. icon: "none"
  60. })
  61. if (subvalues.length) res.data = res.data.filter(v => subvalues.includes(v.sa_accountclassid + ""))
  62. res.data = res.data.map(v => {
  63. v.balance = CNY(v.balance)
  64. v.creditquota = CNY(v.creditquota)
  65. return v
  66. })
  67. let list = res.data.filter(v => v.isorder)
  68. this.setData({
  69. 'params.content.pageNumber': res.pageNumber + 1,
  70. 'params.content.pageTotal': res.pageTotal,
  71. 'params.content.total': res.total,
  72. list: res.pageNumber == 1 ? list : this.data.list.concat(list),
  73. loading: false
  74. })
  75. })
  76. },
  77. /* 选中 */
  78. changeResult(e) {
  79. let {
  80. id
  81. } = e.currentTarget.dataset, result = this.data.result;
  82. if (this.data.radio) {
  83. result = [id];
  84. } else {
  85. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  86. }
  87. this.setData({
  88. result
  89. });
  90. if (this.data.radio) this.submit();
  91. },
  92. /* 提交 */
  93. submit() {
  94. let result = this.data.result,
  95. obj = this.data.radio ? {
  96. id: result,
  97. item: this.data.list.find(value => value[this.data.idname] == result),
  98. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  99. } : {
  100. result,
  101. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  102. value: [result.map(v => {
  103. let data = this.data.list.find(value => value[this.data.idname] == v);
  104. return data ? data[this.data.showName] : ""
  105. }), result]
  106. }
  107. console.log(obj);
  108. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  109. },
  110. /* 开始搜索 */
  111. startSearch({
  112. detail
  113. }) {
  114. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  115. if (detail == condition) return;
  116. this.setData({
  117. 'content.where.condition': detail,
  118. 'params.content.where.condition': detail
  119. });
  120. this.getList(true);
  121. },
  122. /* 取消搜索 */
  123. onClear() {
  124. this.setData({
  125. 'content.where.condition': "",
  126. 'params.content.where.condition': ""
  127. });
  128. this.getList(true);
  129. },
  130. onReady() {
  131. this.selectComponent("#ListBox").setHeight(".total", this);
  132. },
  133. onUnload() {
  134. //回收数据
  135. getApp().globalData.handleSelect = null;
  136. }
  137. })