index.js 4.2 KB

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