material.js 2.9 KB

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