index.js 3.8 KB

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