viewPage.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. _Http.basic({
  50. "classname": "system.attachment.MediaCenter",
  51. "method": this.data.fileSelected.isCollect == 0 ? "collectAttachment" : "uncollectAttachment",
  52. "content": {
  53. "collecttype": "营销物料",
  54. "attachmentid": this.data.fileSelected.attachmentid
  55. }
  56. }).then(res => {
  57. if (res.msg != '成功') return wx.showToast({
  58. title: res.data,
  59. icon: "none"
  60. })
  61. wx.showToast({
  62. title: this.data.fileSelected.isCollect == 0 ? '收藏成功' : "取消收藏",
  63. })
  64. let list = this.data.list,
  65. index = this.data.fileSelected.queryrow - 1;
  66. this.data.tabActiveTitle == '列表' ? list[index].isCollect = this.data.fileSelected.isCollect == 0 ? 1 : 0 : list.splice(index, 1);
  67. this.setData({
  68. list
  69. })
  70. this.closeShow();
  71. })
  72. },
  73. /* 获得列表 */
  74. getList(init = false) {
  75. if (init.detail != undefined) init = init.detail;
  76. if (init) this.setData({
  77. ['content.pageNumber']: 1
  78. })
  79. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  80. _Http.basic({
  81. "classname": "saletool.salematerial.salematerial",
  82. "method": (this.data.tabActiveTitle == '列表') ? "selectList" : "selectMyList",
  83. "content": this.data.content
  84. }).then(res => {
  85. this.selectComponent('#ListBox').RefreshToComplete();
  86. if (res.msg != '成功') return wx.showToast({
  87. title: res.data,
  88. icon: "none"
  89. })
  90. this.setData({
  91. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  92. ['content.pageNumber']: res.pageNumber + 1,
  93. ['content.pageTotal']: res.pageTotal,
  94. inTotal: res.total
  95. })
  96. // console.log((this.data.tabActiveTitle == '列表') ? "列表" : '营销物料', this.data.list)
  97. })
  98. },
  99. /* 搜索框输入 */
  100. searchInput({
  101. detail
  102. }) {
  103. this.setData({
  104. ['content.where.condition']: detail.trim()
  105. })
  106. this.getList(true)
  107. },
  108. /* 清除搜索输入 */
  109. searchClear() {
  110. this.setData({
  111. ['content.where.condition']: ""
  112. })
  113. },
  114. /* tab切换 */
  115. tabsChange({
  116. detail
  117. }) {
  118. this.setData({
  119. tabActiveTitle: detail.title
  120. })
  121. this.getList(true);
  122. },
  123. /* 开关切换 */
  124. changeSwitch({
  125. detail
  126. }) {
  127. this.setData({
  128. ["content.where.sorttype"]: detail == '最新' ? 2 : 1
  129. })
  130. this.getList(true);
  131. },
  132. /* 修改ID */
  133. changeParentid(id) {
  134. this.setData({
  135. ['content.parentid']: id
  136. })
  137. },
  138. /* 修改选中ID */
  139. changeId({
  140. detail
  141. }) {
  142. console.log(detail)
  143. this.setData({
  144. fileSelected: detail,
  145. show: true
  146. })
  147. },
  148. /* 关闭修改 */
  149. closeShow() {
  150. this.setData({
  151. show: false
  152. })
  153. setTimeout(() => {
  154. this.setData({
  155. fileSelected: {}
  156. })
  157. }, 150)
  158. },
  159. }
  160. })