index.js 4.8 KB

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