index.js 7.7 KB

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