index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. siteid: wx.getStorageSync('userMsg').siteid
  28. });
  29. this.getList();
  30. getApp().globalData.Language.getLanguagePackage(this, 'E-订单');
  31. },
  32. getList(init = false) {
  33. //init 用于初始化分页
  34. if (init.detail != undefined) init = init.detail;
  35. let params = this.data.params;
  36. if (init) params.content.pageNumber = 1;
  37. if (params.content.pageNumber > params.content.pageTotal) return;
  38. _Http.basic(params).then(res => {
  39. console.log("选择订单行列表", res)
  40. this.selectComponent('#ListBox').RefreshToComplete();
  41. if (res.code != '1') return wx.showToast({
  42. title: res.msg,
  43. icon: "none"
  44. })
  45. res.data = res.data.map(value => {
  46. if (value.attinfos.length != 0) {
  47. value.attinfos = file.fileList(value.attinfos)
  48. let image = value.attinfos.find(v => v.fileType == "image");
  49. value.cover = image ? image.cover : "";
  50. }
  51. value.gradeprice && (value.gradeprice = (value.gradeprice - 0).toFixed(2));
  52. value.price && (value.price = (value.price - 0).toFixed(2));
  53. value.oldprice && (value.oldprice = (value.oldprice - 0).toFixed(2));
  54. return value;
  55. })
  56. this.setData({
  57. 'params.content.pageNumber': res.pageNumber + 1,
  58. 'params.content.pageTotal': res.pageTotal,
  59. 'params.content.total': res.total,
  60. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  61. loading: false
  62. })
  63. })
  64. },
  65. /* 选中 */
  66. changeResult(e) {
  67. let {
  68. id
  69. } = e.currentTarget.dataset, result = this.data.result;
  70. if (this.data.radio) {
  71. result = [id];
  72. } else {
  73. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  74. }
  75. this.setData({
  76. result
  77. });
  78. if (this.data.radio) this.submit();
  79. },
  80. /* 提交 */
  81. submit() {
  82. let result = this.data.result,
  83. obj = this.data.radio ? {
  84. id: result,
  85. item: this.data.list.find(value => value[this.data.idname] == result),
  86. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  87. } : {
  88. result,
  89. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  90. value: [result.map(v => {
  91. let data = this.data.list.find(value => value[this.data.idname] == v);
  92. return data ? data[this.data.showName] : ""
  93. }), result]
  94. }
  95. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  96. },
  97. /* 开始搜索 */
  98. startSearch({
  99. detail
  100. }) {
  101. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  102. if (detail == condition) return;
  103. this.setData({
  104. 'content.where.condition': detail,
  105. 'params.content.where.condition': detail
  106. });
  107. this.getList(true);
  108. },
  109. /* 取消搜索 */
  110. onClear() {
  111. this.setData({
  112. 'content.where.condition': "",
  113. 'params.content.where.condition': ""
  114. });
  115. this.getList(true);
  116. },
  117. onReady() {
  118. this.selectComponent("#ListBox").setHeight(".total", this);
  119. },
  120. onUnload() {
  121. //回收数据
  122. getApp().globalData.handleSelect = null;
  123. }
  124. })