viewPage.js 5.9 KB

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