index.js 7.3 KB

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