viewPage.js 5.6 KB

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