index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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: "itemid", //idkey
  10. showName: "itemname"
  11. },
  12. onLoad(options) {
  13. if (options.item) {
  14. let item = JSON.parse(options.item);
  15. this.setData({
  16. item,
  17. params: item.params
  18. });
  19. }
  20. if (options.params) this.setData({
  21. params: JSON.parse(options.params)
  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.data)
  39. this.selectComponent('#ListBox').RefreshToComplete();
  40. if (res.code != '1') 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. return value;
  51. })
  52. this.setData({
  53. 'params.content.pageNumber': res.pageNumber + 1,
  54. 'params.content.pageTotal': res.pageTotal,
  55. 'params.content.total': res.total,
  56. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  57. loading: false
  58. })
  59. })
  60. },
  61. /* 选中 */
  62. changeResult(e) {
  63. let {
  64. id
  65. } = e.currentTarget.dataset, result = this.data.result;
  66. if (this.data.radio) {
  67. result = [id];
  68. } else {
  69. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  70. }
  71. this.setData({
  72. result
  73. });
  74. if (this.data.radio) this.submit();
  75. },
  76. /* 提交 */
  77. submit() {
  78. let result = this.data.result,
  79. obj = this.data.radio ? {
  80. id: result,
  81. item: this.data.list.find(value => value[this.data.idname] == result),
  82. value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
  83. } : {
  84. result,
  85. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  86. value: [result.map(v => {
  87. let data = this.data.list.find(value => value[this.data.idname] == v);
  88. return data ? data[this.data.showName] : ""
  89. }), result]
  90. }
  91. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  92. },
  93. /* 预览图片 */
  94. viewImage(e) {
  95. const {
  96. file
  97. } = e.currentTarget.dataset;
  98. if (file.length) wx.previewMedia({
  99. sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
  100. return {
  101. url: v.url,
  102. type: v.fileType
  103. }
  104. }),
  105. current: 0,
  106. showmenu: true
  107. })
  108. },
  109. /* 开始搜索 */
  110. startSearch({
  111. detail
  112. }) {
  113. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  114. if (detail == condition) return;
  115. this.setData({
  116. 'content.where.condition': detail,
  117. 'params.content.where.condition': detail
  118. });
  119. this.getList(true);
  120. },
  121. /* 取消搜索 */
  122. onClear() {
  123. this.setData({
  124. 'content.where.condition': "",
  125. 'params.content.where.condition': ""
  126. });
  127. this.getList(true);
  128. },
  129. onReady() {
  130. this.selectComponent("#ListBox").setHeight(".total", this);
  131. },
  132. onUnload() {
  133. //回收数据
  134. getApp().globalData.handleSelect = null;
  135. }
  136. })