material.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. radio: false, //是否为单选
  5. result: [], //返回结果
  6. id: 2026051510000002,
  7. content: {
  8. where: {
  9. condition: ""
  10. },
  11. pageNumber: 1,
  12. pageSize: 20
  13. },
  14. },
  15. onLoad(options) {
  16. this.getList()
  17. getApp().globalData.Language.getLanguagePackage(this, '添加物料');
  18. },
  19. getList(init = false) {
  20. if (init) this.selectComponent('#ListBox').goTop();
  21. _Http.init(this.data.content, init).then(content => {
  22. _Http.basic({
  23. id: this.data.id,
  24. content
  25. }).then(res => {
  26. this.selectComponent('#ListBox').RefreshToComplete();
  27. if (res.code != '1') return wx.showToast({
  28. title: res.msg,
  29. icon: "none"
  30. })
  31. const arr = res.data.map(item => {
  32. item.showBrand = Array.isArray(item.brand) ?
  33. item.brand.map(v => v.brandname).join(',') :
  34. '--'
  35. item.showClass = Array.isArray(item.itemClassList) ?
  36. item.itemClassList.map(v => v.className).join(',') :
  37. '--'
  38. // 图片:优先缩略图
  39. let imgSrc = ''
  40. if (Array.isArray(item.attinfos) && item.attinfos.length > 0) {
  41. const info = item.attinfos[0]
  42. if (Array.isArray(info.subfiles)) {
  43. const thumb = info.subfiles.find(s => s.type === 'thumbnail')
  44. if (thumb?.url) {
  45. imgSrc = thumb.url
  46. } else if (info.url) {
  47. imgSrc = info.url
  48. }
  49. } else if (info.url) {
  50. imgSrc = info.url
  51. }
  52. }
  53. item.imgUrl = imgSrc
  54. return item
  55. })
  56. this.setData({
  57. content: _Http.paging(content, res),
  58. list: res.pageNumber == 1 ? arr : this.data.list.concat(arr)
  59. })
  60. })
  61. })
  62. },
  63. startSearch({
  64. detail
  65. }) {
  66. const condition = this.data.content.where.condition;
  67. if (detail == condition) return;
  68. this.setData({
  69. 'content.where.condition': detail
  70. });
  71. this.getList(true);
  72. },
  73. onClear() {
  74. this.setData({
  75. 'content.where.condition': ""
  76. });
  77. this.getList(true);
  78. },
  79. changeResult(e) {
  80. let {
  81. id
  82. } = e.currentTarget.dataset, result = this.data.result;
  83. if (this.data.radio) {
  84. result = [id];
  85. } else {
  86. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  87. }
  88. this.setData({
  89. result
  90. });
  91. if (this.data.radio) this.submit();
  92. },
  93. submit() {
  94. const selectedItems = this.data.list.filter(item =>
  95. this.data.result.includes(item.sc_item_localid)
  96. ).map(item => ({
  97. sc_item_localid: item.sc_item_localid,
  98. }));
  99. if (getApp().globalData.handleMaterialSelect) {
  100. getApp().globalData.handleMaterialSelect({
  101. list: selectedItems
  102. });
  103. }
  104. },
  105. cancel() {
  106. this.setData({
  107. result: []
  108. });
  109. },
  110. })