viewPage.js 5.7 KB

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