viewPage.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. const getHeight = require("../../../../utils/getRheRemainingHeight");
  2. const _Http = getApp().globalData.http;
  3. const MFT = require("../../../../utils/matchingFeilType");
  4. let dowmCount = null;
  5. Component({
  6. properties: {
  7. padBot: {
  8. type: Boolean,
  9. value: true
  10. }
  11. },
  12. options: {
  13. addGlobalClass: true
  14. },
  15. lifetimes: {
  16. ready() {
  17. this.getList();
  18. getHeight.getHeight('.tabs', this).then(res => {
  19. this.setData({
  20. listHeight: res
  21. })
  22. });
  23. }
  24. },
  25. data: {
  26. listHeight: 0, //列表高度
  27. tabActiveTitle: "列表", //列表类型
  28. show: false, //显示底部弹出
  29. fileSelected: {}, //选中文件详情
  30. content: { //请求搜索条件
  31. "nocache": true,
  32. "pageNumber": 1,
  33. "pageSize": 20,
  34. "parentid": "默认",
  35. "pageTotal": 1,
  36. "where": {
  37. "condition": ""
  38. }
  39. },
  40. list: [], //文件列表
  41. inTotal: 0, //总计
  42. sort: [], //排序规则
  43. },
  44. methods: {
  45. /* 是否收藏 */
  46. changeCollect() {
  47. const {
  48. isCollect,
  49. attachmentid,
  50. rowindex
  51. } = this.data.fileSelected;
  52. _Http.basic({
  53. "classname": "system.attachment.MediaCenter",
  54. "method": isCollect == 0 ? "collectAttachment" : "uncollectAttachment",
  55. "content": {
  56. "collecttype": "营销物料",
  57. "attachmentid": attachmentid
  58. }
  59. }).then(res => {
  60. if (res.msg != '成功') return wx.showToast({
  61. title: res.msg,
  62. icon: "none"
  63. })
  64. wx.showToast({
  65. title: isCollect == 0 ? '收藏成功' : "已取消收藏",
  66. icon: "none"
  67. })
  68. let list = this.data.list,
  69. index = rowindex - 1;
  70. this.data.tabActiveTitle == '列表' ? list[index].isCollect = isCollect == 0 ? 1 : 0 : list.splice(index, 1);
  71. this.setData({
  72. list
  73. })
  74. this.closeShow();
  75. })
  76. },
  77. /* 文件下载 */
  78. dowmLoad() {
  79. const that = this;
  80. wx.setClipboardData({
  81. data: this.data.fileSelected.url,
  82. success: function () {
  83. wx.showToast({
  84. title: '复制成功,将链接放置到浏览器中便可下载文件',
  85. icon: "none",
  86. duration: 3000
  87. });
  88. that.closeShow();
  89. }
  90. })
  91. },
  92. /* 获得列表 */
  93. getList(init = false) {
  94. if (init.detail != undefined) init = init.detail;
  95. if (init) this.setData({
  96. ['content.pageNumber']: 1
  97. })
  98. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  99. let content = this.data.content;
  100. if (content.parentid == '默认') content.parentid = wx.getStorageSync('siteP').salematerialfolderid;
  101. if (this.data.sort[0]) content.sort = this.data.sort;
  102. _Http.basic({
  103. "classname": "saletool.salematerial.salematerial",
  104. "method": (this.data.tabActiveTitle == '列表') ? "selectList" : "selectMyList",
  105. content
  106. }).then(res => {
  107. this.selectComponent('#ListBox').RefreshToComplete();
  108. if (res.msg != '成功') return wx.showToast({
  109. title: res.msg,
  110. icon: "none"
  111. })
  112. this.setData({
  113. list: (res.pageNumber == 1) ? MFT.fileList(res.data) : this.data.list.concat(MFT.fileList(res.data)),
  114. ['content.pageNumber']: res.pageNumber + 1,
  115. ['content.pageTotal']: res.pageTotal,
  116. inTotal: res.total,
  117. sort: res.sort
  118. })
  119. })
  120. },
  121. /* 搜索框输入 */
  122. searchInput({
  123. detail
  124. }) {
  125. clearTimeout(dowmCount);
  126. this.setData({
  127. ['content.where.condition']: detail.trim()
  128. })
  129. dowmCount = setTimeout(() => {
  130. this.getList(true)
  131. }, 1000);
  132. },
  133. /* 清除搜索输入 */
  134. searchClear() {
  135. this.setData({
  136. ['content.where.condition']: ""
  137. })
  138. },
  139. /* tab切换 */
  140. tabsChange({
  141. detail
  142. }) {
  143. this.setData({
  144. tabActiveTitle: detail.title
  145. })
  146. this.getList(true);
  147. },
  148. /* 开关切换 */
  149. changeSwitch({
  150. detail
  151. }) {
  152. this.setData({
  153. sort: detail
  154. })
  155. this.getList(true);
  156. },
  157. /* 修改ID */
  158. changeParentid(id) {
  159. this.setData({
  160. ['content.parentid']: id
  161. })
  162. },
  163. /* 修改选中ID */
  164. changeId({
  165. detail
  166. }) {
  167. this.setData({
  168. fileSelected: detail,
  169. show: true
  170. })
  171. },
  172. /* 关闭修改 */
  173. closeShow() {
  174. this.setData({
  175. show: false
  176. })
  177. setTimeout(() => {
  178. this.setData({
  179. fileSelected: {}
  180. })
  181. }, 150)
  182. },
  183. }
  184. })