index.js 5.1 KB

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