viewPage.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. },
  10. options: {
  11. addGlobalClass: true
  12. },
  13. lifetimes: {
  14. ready() {
  15. this.getList();
  16. getHeight.getHeight('.tabs', this).then(res => {
  17. this.setData({
  18. listHeight: res
  19. })
  20. });
  21. }
  22. },
  23. /**
  24. * 组件的初始数据
  25. */
  26. data: {
  27. listHeight: 0, //列表高度
  28. tabActiveTitle: "列表", //列表类型
  29. show: false, //显示底部弹出
  30. fileSelected: {}, //选中文件详情
  31. content: { //请求搜索条件
  32. "pageNumber": 1,
  33. "pageSize": 20,
  34. "parentid": 1,
  35. "pageTotal": 1,
  36. "where": {
  37. "condition": "", //搜索内容
  38. "sorttype": 2 //1:热门,2:最新,不传默认最新
  39. }
  40. },
  41. list: [], //文件列表
  42. inTotal: 0, //总计
  43. },
  44. /**
  45. * 组件的方法列表
  46. */
  47. methods: {
  48. /* 是否收藏 */
  49. isCollect() {
  50. const isCollect = this.data.fileSelected.isCollect;
  51. _Http.basic({
  52. "classname": "system.attachment.MediaCenter",
  53. "method": isCollect == 0 ? "collectAttachment" : "uncollectAttachment",
  54. "content": {
  55. "collecttype": "营销物料",
  56. "attachmentid": this.data.fileSelected.attachmentid
  57. }
  58. }).then(res => {
  59. if (res.msg != '成功') return wx.showToast({
  60. title: res.data,
  61. icon: "none"
  62. })
  63. wx.showToast({
  64. title: isCollect == 0 ? '收藏成功' : "取消收藏",
  65. })
  66. let list = this.data.list,
  67. index = this.data.fileSelected.queryrow - 1;
  68. this.data.tabActiveTitle == '列表' ? list[index].isCollect = isCollect == 0 ? 1 : 0 : list.splice(index, 1);
  69. this.setData({
  70. list
  71. })
  72. this.closeShow();
  73. })
  74. },
  75. /* 获得列表 */
  76. getList(init = false) {
  77. if (init.detail != undefined) init = init.detail;
  78. if (init) this.setData({
  79. ['content.pageNumber']: 1
  80. })
  81. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  82. _Http.basic({
  83. "classname": "saletool.salematerial.salematerial",
  84. "method": (this.data.tabActiveTitle == '列表') ? "selectList" : "selectMyList",
  85. "content": this.data.content
  86. }).then(res => {
  87. console.log("营销", res)
  88. this.selectComponent('#ListBox').RefreshToComplete();
  89. if (res.msg != '成功') return wx.showToast({
  90. title: res.data,
  91. icon: "none"
  92. })
  93. this.setData({
  94. list: (res.pageNumber == 1) ? MFT.fileList(res.data) : this.data.list.concat(MFT.fileList(res.data)),
  95. ['content.pageNumber']: res.pageNumber + 1,
  96. ['content.pageTotal']: res.pageTotal,
  97. inTotal: res.total
  98. })
  99. })
  100. },
  101. /* 搜索框输入 */
  102. searchInput({
  103. detail
  104. }) {
  105. this.setData({
  106. ['content.where.condition']: detail.trim()
  107. })
  108. this.getList(true)
  109. },
  110. /* 清除搜索输入 */
  111. searchClear() {
  112. this.setData({
  113. ['content.where.condition']: ""
  114. })
  115. },
  116. /* tab切换 */
  117. tabsChange({
  118. detail
  119. }) {
  120. this.setData({
  121. tabActiveTitle: detail.title
  122. })
  123. this.getList(true);
  124. },
  125. /* 开关切换 */
  126. changeSwitch({
  127. detail
  128. }) {
  129. this.setData({
  130. ["content.where.sorttype"]: detail == '最新' ? 2 : 1
  131. })
  132. this.getList(true);
  133. },
  134. /* 修改ID */
  135. changeParentid(id) {
  136. this.setData({
  137. ['content.parentid']: id
  138. })
  139. },
  140. /* 修改选中ID */
  141. changeId({
  142. detail
  143. }) {
  144. console.log(detail)
  145. this.setData({
  146. fileSelected: detail,
  147. show: true
  148. })
  149. },
  150. /* 关闭修改 */
  151. closeShow() {
  152. this.setData({
  153. show: false
  154. })
  155. setTimeout(() => {
  156. this.setData({
  157. fileSelected: {}
  158. })
  159. }, 150)
  160. },
  161. }
  162. })