viewPage.js 5.7 KB

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