index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. const _Http = getApp().globalData.http;
  2. const MFT = require("../../utils/FormatTheAttachment");
  3. let parems = {
  4. "classname": "saletool.salematerial.salematerial",
  5. method: "selectList",
  6. content: {
  7. "nocache": true,
  8. "parentid": '',
  9. "pageNumber": 1,
  10. "pageSize": 20,
  11. "where": {
  12. "condition": ""
  13. }
  14. }
  15. }
  16. Page({
  17. data: {},
  18. onLoad(options) {
  19. if (options.item) {
  20. let item = JSON.parse(options.item);
  21. parems.content.parentid = item.attachmentid;
  22. wx.setNavigationBarTitle({
  23. title: item.document
  24. });
  25. } else {
  26. parems.content.parentid = wx.getStorageSync('siteP').salematerialfolderid;
  27. }
  28. this.getList(true)
  29. },
  30. /* 获得列表 */
  31. getList(init = false) {
  32. if (init.detail != undefined) init = init.detail;
  33. if (init) parems.content.pageNumber = 1;
  34. if (parems.content.pageNumber > parems.content.pageTotal) return;
  35. parems.content.sort = this.data.sort || [];
  36. _Http.basic(parems).then(res => {
  37. console.log('营销物料', res)
  38. this.selectComponent('#ListBox').RefreshToComplete();
  39. if (res.msg != '成功') return wx.showToast({
  40. title: res.msg,
  41. icon: "none"
  42. })
  43. parems.content.pageNumber = res.pageNumber + 1;
  44. parems.content.pageTotal = res.pageTotal;
  45. this.setData({
  46. list: (res.pageNumber == 1) ? MFT.fileList(res.data) : this.data.list.concat(MFT.fileList(res.data)),
  47. total: res.total,
  48. sort: res.sort
  49. })
  50. })
  51. },
  52. /* 是否收藏 */
  53. changeCollect() {
  54. const {
  55. isCollect,
  56. attachmentid,
  57. rowindex
  58. } = this.data.fileSelected;
  59. _Http.basic({
  60. "classname": "system.attachment.MediaCenter",
  61. "method": isCollect == 0 ? "collectAttachment" : "uncollectAttachment",
  62. "content": {
  63. "collecttype": "营销物料",
  64. "attachmentid": attachmentid
  65. }
  66. }).then(res => {
  67. if (res.msg != '成功') return wx.showToast({
  68. title: res.msg,
  69. icon: "none"
  70. })
  71. wx.showToast({
  72. title: isCollect == 0 ? '收藏成功' : "已取消收藏",
  73. icon: "none"
  74. })
  75. let list = this.data.list,
  76. index = rowindex - 1;
  77. parems.method == "selectList" ? list[index].isCollect = isCollect == 0 ? 1 : 0 : list.splice(index, 1);
  78. this.setData({
  79. list
  80. })
  81. this.closeShow();
  82. })
  83. },
  84. /* 文件下载 */
  85. dowmLoad() {
  86. const that = this;
  87. wx.setClipboardData({
  88. data: this.data.fileSelected.url,
  89. success: function () {
  90. wx.showToast({
  91. title: '复制成功,将链接放置到浏览器中便可下载文件',
  92. icon: "none",
  93. duration: 3000
  94. });
  95. that.closeShow();
  96. }
  97. })
  98. },
  99. /* 搜索框输入 */
  100. searchInput({
  101. detail
  102. }) {
  103. parems.content.where.condition = detail;
  104. console.log(detail)
  105. this.getList(true)
  106. },
  107. /* 清除搜索输入 */
  108. searchClear() {
  109. parems.content.where.condition = '';
  110. this.getList(true)
  111. },
  112. /* tab切换 */
  113. tabsChange({
  114. detail
  115. }) {
  116. parems.method = detail.title == '列表' ? "selectList" : "selectMyList";
  117. this.getList(true);
  118. },
  119. /* 开关切换 */
  120. changeSwitch({
  121. detail
  122. }) {
  123. this.setData({
  124. sort: detail
  125. })
  126. this.getList(true);
  127. },
  128. onReady() {
  129. this.selectComponent("#ListBox").setHeight(".tabs", this);
  130. },
  131. /* 修改选中ID */
  132. changeId({
  133. detail
  134. }) {
  135. this.setData({
  136. fileSelected: detail,
  137. show: true
  138. })
  139. },
  140. /* 关闭修改 */
  141. closeShow() {
  142. this.setData({
  143. show: false
  144. })
  145. this.data.fileSelected = {}
  146. },
  147. })