index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const _Http = getApp().globalData.http,
  2. file = require("../../utils/FormatTheAttachment");
  3. Page({
  4. data: {
  5. loading: true,
  6. params: {}, //请求体
  7. result: [], //返回结果
  8. radio: false, //是否为单选
  9. idname: "sa_orderitemsid", //idkey
  10. showName: "itemname"
  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. this.getList();
  29. getApp().globalData.Language.getLanguagePackage(this, 'E-订单');
  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.msg != '成功') return wx.showToast({
  41. title: res.msg,
  42. icon: "none"
  43. })
  44. res.data = res.data.map(value => {
  45. if (value.attinfos.length != 0) {
  46. value.attinfos = file.fileList(value.attinfos)
  47. let image = value.attinfos.find(v => v.fileType == "image");
  48. value.cover = image ? image.cover : "";
  49. }
  50. value.gradeprice && (value.gradeprice = (value.gradeprice - 0).toFixed(2));
  51. value.price && (value.price = (value.price - 0).toFixed(2));
  52. value.oldprice && (value.oldprice = (value.oldprice - 0).toFixed(2));
  53. return value;
  54. })
  55. this.setData({
  56. 'params.content.pageNumber': res.pageNumber + 1,
  57. 'params.content.pageTotal': res.pageTotal,
  58. 'params.content.total': res.total,
  59. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  60. loading: false
  61. })
  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. })