index.js 7.5 KB

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