index.js 7.3 KB

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