viewPage.js 4.9 KB

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