index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. const getHeight = require("../../utils/getRheRemainingHeight");
  2. const _Http = getApp().globalData.http;
  3. const MFT = require("../../utils/matchingFeilType");
  4. let dowmCount = null;
  5. Page({
  6. data: {
  7. isInsert: false, //是否具有新增权限
  8. isTabs: true,
  9. tabsActiveIndex: 0,
  10. scrollHeight: 0, //滚动区域高度
  11. searchContent: "", //搜索内容
  12. mainActiveIndex: 0, //分类选择器打开分类的下标
  13. activeId: null, //分类选择器选择id
  14. activeName: null,
  15. items: [], //分类列表
  16. total: 0,
  17. sort: [],
  18. content: {
  19. nocache: true,
  20. pageNumber: 1,
  21. pageSize: 20,
  22. pageTotal: 1,
  23. where: {
  24. condition: "",
  25. sat_sharematerial_classid: ""
  26. }
  27. },
  28. sheetShow: false,
  29. actions: [{
  30. name: '上传图片',
  31. },
  32. {
  33. name: '上传视频',
  34. },
  35. {
  36. name: '上传图文',
  37. },
  38. ],
  39. },
  40. onLoad(options) {
  41. let auth = wx.getStorageSync('authList').wpopularize.optionnames,
  42. myList = auth.some(v => v == '我的素材');
  43. console.log(auth)
  44. this.setData({
  45. isInsert: auth.some(v => v == '新增'),
  46. tabsActiveIndex: myList ? 1 : 0,
  47. isTabs: myList
  48. })
  49. this.selectMenu();
  50. this.getList();
  51. },
  52. tabChange({
  53. detail
  54. }) {
  55. this.setData({
  56. tabsActiveIndex: detail.index
  57. });
  58. this.getList(true);
  59. },
  60. /* 查询列表 */
  61. getList(init = false) {
  62. if (init.detail != undefined) init = init.detail;
  63. if (init) this.setData({
  64. ['content.pageNumber']: 1
  65. })
  66. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  67. let content = this.data.content;
  68. (this.data.activeId != null) ? content.where.sat_sharematerial_classid = this.data.activeId: delete(content.where.sat_sharematerial_classid);
  69. if (this.data.sort[0]) content.sort = this.data.sort;
  70. _Http.basic({
  71. "classname": "saletool.sharematerial.sharematerial",
  72. "method": this.data.tabsActiveIndex == 0 ? "selectList" : "selectMyList",
  73. content
  74. }).then(res => {
  75. let deleteList = [],
  76. initID = '9999' + wx.getStorageSync('userMsg').userid;
  77. res.data.forEach(v => (initID == v.sat_sharematerial_classid && v.title == '') ? deleteList.push(v.sat_sharematerialid) : '');
  78. if (deleteList.length != 0) return this.handleDelete(deleteList);
  79. this.selectComponent('#ListBox').RefreshToComplete();
  80. if (res.msg != '成功') return wx.showToast({
  81. title: res.msg,
  82. icon: "none"
  83. });
  84. for (let i = 0; i < res.data.length; i++) {
  85. let list = MFT.fileList(res.data[i].attinfos);
  86. if (!list.length) continue;
  87. let obj = list.find(value => value.fileType == "image");
  88. if (!obj) continue;
  89. res.data[i].cover = MFT.getSpecifiedImage(obj);
  90. res.data[i].attinfos = list;
  91. }
  92. this.setData({
  93. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  94. ['content.pageNumber']: res.pageNumber + 1,
  95. ['content.pageTotal']: res.pageTotal,
  96. total: res.total,
  97. sort: res.sort
  98. })
  99. })
  100. },
  101. /* 处理批量删除 */
  102. handleDelete(list) {
  103. _Http.basic({
  104. "classname": "webmanage.saletool.sharematerial.sharematerial",
  105. "method": "delete",
  106. "content": {
  107. "sat_sharematerialid": list
  108. }
  109. }).then(res => {
  110. console.log("处理删除", res);
  111. if (res.msg == '成功') this.getList();
  112. })
  113. },
  114. /* 清除搜索输入 */
  115. searchClear() {
  116. this.setData({
  117. ['content.where.condition']: ""
  118. })
  119. this.getList(true);
  120. },
  121. /* 搜索框输入 */
  122. searchInput({
  123. detail
  124. }) {
  125. if (this.data.content.where.condition == detail.trim()) return;
  126. clearTimeout(dowmCount);
  127. this.setData({
  128. ['content.where.condition']: detail.trim()
  129. })
  130. dowmCount = setTimeout(() => {
  131. this.getList(true)
  132. }, 1000);
  133. },
  134. /* 开关切换 */
  135. changeSwitch({
  136. detail
  137. }) {
  138. this.setData({
  139. sort: detail
  140. })
  141. this.getList(true);
  142. },
  143. /* 查询分类 */
  144. selectMenu(index = 0, res) {
  145. if (index == 5) return wx.showToast({
  146. title: res.msg,
  147. icon: "none"
  148. });
  149. _Http.basic({
  150. "classname": "saletool.sharematerial.sharematerial",
  151. "method": "select",
  152. "content": {
  153. "nocache": true,
  154. "parentid": 0
  155. }
  156. }).then(res => {
  157. if (res.msg != '成功') return this.selectMenu(index + 1, res);
  158. let str = JSON.stringify(res.data).replace(/classname/g, 'text').replace(/sat_sharematerial_classid/g, 'id');
  159. this.setData({
  160. items: JSON.parse(str)
  161. });
  162. });
  163. },
  164. /* 切换分类 */
  165. onClickItem({
  166. detail = {}
  167. }) {
  168. this.setData({
  169. activeId: this.data.activeId === detail.id ? null : detail.id,
  170. activeName: this.data.activeName === detail.text ? null : detail.text
  171. });
  172. this.selectComponent('#item').toggle(false);
  173. this.getList(true);
  174. },
  175. onClickNav({
  176. detail = {}
  177. }) {
  178. this.setData({
  179. mainActiveIndex: detail.index || 0,
  180. });
  181. },
  182. onReady() {
  183. //滚动区域高度
  184. getHeight.getHeight('.menu', this).then(res => {
  185. this.setData({
  186. scrollHeight: res
  187. })
  188. })
  189. },
  190. addData() {
  191. this.setData({
  192. sheetShow: true
  193. });
  194. },
  195. sheetClose() {
  196. this.setData({
  197. sheetShow: false
  198. });
  199. },
  200. sheetSelect({
  201. detail
  202. }) {
  203. let type = '';
  204. switch (detail.name) {
  205. case "上传图片":
  206. type = 'image'
  207. break;
  208. case "上传视频":
  209. type = 'video'
  210. break;
  211. case "上传图文":
  212. type = 'richtext'
  213. break;
  214. }
  215. /* items是分类 */
  216. wx.navigateTo({
  217. url: `./upload?item=${JSON.stringify(this.data.items)}&type=${type}`
  218. })
  219. },
  220. onShareAppMessage() {
  221. const promise = new Promise(resolve => {
  222. setTimeout(() => {
  223. let data = this.selectComponent("#list").data.shareData;
  224. _Http.basic({
  225. "classname": "saletool.sharematerial.sharematerial",
  226. "method": "updateShareLog",
  227. "content": {
  228. "sat_sharematerialid": data.sat_sharematerialid,
  229. "channel": "wechat"
  230. }
  231. })
  232. resolve({
  233. title: data.title,
  234. path: `/pages/promotional/details?id=${data.sat_sharematerialid}&type=${data.type}&userid=${wx.getStorageSync('userMsg').userid}`,
  235. imageUrl: data.cover
  236. })
  237. }, 50)
  238. })
  239. return {
  240. promise
  241. }
  242. },
  243. })