index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. loading: true,
  5. filterShow: false,
  6. navList: [{
  7. label: "我负责的",
  8. icon: "icon-webxialaxuanxiangjiantou",
  9. color: "",
  10. width: "",
  11. id: "1"
  12. }, {
  13. label: "排序",
  14. icon: "icon-jiangxu1",
  15. color: "",
  16. width: "",
  17. id: "sort"
  18. }, {
  19. label: "筛选",
  20. icon: "icon-shaixuan",
  21. color: "",
  22. width: "",
  23. id: "2"
  24. }],
  25. classShow: false,
  26. content: {
  27. "isAll": 0,
  28. "nocache": true,
  29. "version": 1,
  30. "pageNumber": 1,
  31. "pageSize": 20,
  32. type: 1,
  33. "where": {
  34. "condition": ""
  35. },
  36. "sort": []
  37. }
  38. },
  39. async onLoad(options) {
  40. getApp().globalData.Language.getLanguagePackage(this, '市场活动');
  41. this.setData({
  42. insert: wx.getStorageSync('auth').wmarketing_activity.options.some(v => v == 'insert'), //查询新增权限
  43. classActions: wx.getStorageSync('templetList').map((v, i) => {
  44. return {
  45. name: v.templetname,
  46. index: v.templetid,
  47. color: i == 0 ? '#3874F6' : '',
  48. i: i,
  49. }
  50. }),
  51. 'navList[0].label': wx.getStorageSync('templetList')[0].templetname,
  52. "content.type": wx.getStorageSync('templetList')[0].templetid,
  53. });
  54. this.getList();
  55. const filtratelist = [{
  56. label: "活动类型",
  57. index: null,
  58. showName: "value", //显示字段
  59. valueKey: "type", //返回Key
  60. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  61. value: "", //选中值
  62. list: await this.getTypeList()
  63. }, {
  64. label: "活动状态",
  65. index: null,
  66. showName: "value", //显示字段
  67. valueKey: "status", //返回Key
  68. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  69. value: "", //选中值
  70. list: [{
  71. value: '新建'
  72. }, {
  73. value: '发布'
  74. }, {
  75. value: '结束'
  76. }]
  77. }];
  78. this.setData({
  79. filtratelist
  80. })
  81. },
  82. /* 获取活动类型 */
  83. getTypeList() {
  84. return new Promise((resolve) => {
  85. _Http.basic({
  86. "id": 20220901092501,
  87. "content": {
  88. "typename": 'campaigntype'
  89. }
  90. }).then(res => {
  91. resolve(res.code == '1' ? res.data : [])
  92. })
  93. })
  94. },
  95. /* 获取列表 */
  96. getList(init = false) {
  97. _Http.init(this.data.content, init).then(content => {
  98. _Http.basic({
  99. "id": 20221101095102,
  100. content
  101. }).then(res => {
  102. console.log("市场活动", res)
  103. this.selectComponent('#ListBox').RefreshToComplete();
  104. if (res.code != '1') return wx.showToast({
  105. title: res.data,
  106. icon: "none"
  107. })
  108. res.data = res.data.map(v => {
  109. v.progress = v.stage / v.totalstage * 100;
  110. return v
  111. })
  112. this.setData({
  113. content: _Http.paging(content, res),
  114. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  115. loading: false,
  116. })
  117. this.getTags();
  118. })
  119. })
  120. },
  121. /* 处理搜索 */
  122. onSearch({
  123. detail
  124. }) {
  125. this.setData({
  126. "content.where.condition": detail
  127. });
  128. this.getList(true);
  129. },
  130. /* 获取列表标签 */
  131. getTags() {
  132. if (!wx.getStorageSync('auth').wmarketing_activity.isdatatag) return;
  133. let list = this.data.list,
  134. ownerids = list.map(v => v.sat_campaignid);
  135. _Http.basic({
  136. "id": 20221018102001,
  137. "content": {
  138. nocache: true,
  139. "ownertable": "sat_campaign",
  140. ownerids
  141. }
  142. }).then(res => {
  143. console.log("标签", res)
  144. for (let key in res.data) {
  145. let index = list.findIndex(v => v.sat_campaignid == key);
  146. list[index].tags = res.data[key]
  147. };
  148. this.setData({
  149. list
  150. })
  151. })
  152. },
  153. /* 去添加 */
  154. openType() {
  155. wx.navigateTo({
  156. url: '/packageA/activity/addActivity',
  157. })
  158. },
  159. /* 顶部条件导航回调 */
  160. navClick({
  161. detail
  162. }) {
  163. switch (detail.id) {
  164. case '1':
  165. this.setData({
  166. classShow: true
  167. })
  168. break;
  169. case '2':
  170. this.setData({
  171. filterShow: true
  172. })
  173. break;
  174. }
  175. },
  176. classClose() {
  177. this.setData({
  178. classShow: false
  179. })
  180. },
  181. classSelect({
  182. detail
  183. }) {
  184. if (this.data.content.type == detail.index) return this.classClose();
  185. this.setData({
  186. "content.type": detail.index,
  187. 'navList[0].label': detail.name,
  188. classActions: this.data.classActions.map(v => {
  189. v.color = detail.i == v.i ? '#3874F6' : ''
  190. return v
  191. })
  192. })
  193. this.classClose();
  194. this.getList(true)
  195. },
  196. /* 处理筛选 */
  197. handleFilter({
  198. detail
  199. }) {
  200. this.data.content.where = Object.assign(this.data.content.where, detail)
  201. this.getList(true)
  202. }
  203. })