index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. this.setData({
  14. siteid: wx.getStorageSync('userMsg').siteid
  15. })
  16. if (options.item) {
  17. let item = JSON.parse(options.item);
  18. this.setData({
  19. item,
  20. params: item.params
  21. });
  22. }
  23. if (options.params) this.setData({
  24. params: JSON.parse(options.params)
  25. });
  26. this.setData({
  27. radio: options.radio ? true : false,
  28. idname: options.idname || this.data.idname,
  29. showName: options.showName || this.data.showName,
  30. });
  31. this.getList()
  32. getApp().globalData.Language.getLanguagePackage(this, 'E-订单');
  33. },
  34. getList(init = false) {
  35. //init 用于初始化分页
  36. if (init.detail != undefined) init = init.detail;
  37. let params = this.data.params;
  38. if (init) params.content.pageNumber = 1
  39. if (params.content.pageNumber > params.content.pageTotal) return;
  40. _Http.basic(params).then(res => {
  41. console.log("选择产品列表", res.data)
  42. this.selectComponent('#ListBox').RefreshToComplete();
  43. if (res.code != '1') return wx.showToast({
  44. title: res.msg,
  45. icon: "none"
  46. })
  47. res.data = res.data.map(value => {
  48. if (value.attinfos.length != 0) {
  49. value.attinfos = file.fileList(value.attinfos)
  50. let image = value.attinfos.find(v => v.fileType == "image");
  51. value.cover = image ? image.cover : "";
  52. }
  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. viewImage(e) {
  98. const {
  99. file
  100. } = e.currentTarget.dataset;
  101. if (file.length) wx.previewMedia({
  102. sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
  103. return {
  104. url: v.url,
  105. type: v.fileType
  106. }
  107. }),
  108. current: 0,
  109. showmenu: true
  110. })
  111. },
  112. /* 开始搜索 */
  113. startSearch({
  114. detail
  115. }) {
  116. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  117. if (detail == condition) return;
  118. this.setData({
  119. 'content.where.condition': detail,
  120. 'params.content.where.condition': detail
  121. });
  122. this.getList(true);
  123. },
  124. /* 取消搜索 */
  125. onClear() {
  126. this.setData({
  127. 'content.where.condition': "",
  128. 'params.content.where.condition': ""
  129. });
  130. this.getList(true);
  131. },
  132. onReady() {
  133. this.selectComponent("#ListBox").setHeight(".total", this);
  134. },
  135. onUnload() {
  136. //回收数据
  137. getApp().globalData.handleSelect = null;
  138. }
  139. })