index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. const util = require('../../../utils/util.js');
  2. const config = require('../../../utils/config')
  3. Page({
  4. data: {
  5. imgPath:config.imgPath,
  6. BB_coin:config.coin_level,
  7. stat:{},
  8. initialSwipe:0,
  9. levelName:'普通',//会员等级
  10. avatar:wx.getStorageSync("WXuserInfo").avatar,
  11. defaultLevel:1,
  12. percent:'25%',
  13. levelList:{
  14. activite:[],
  15. goods:[]
  16. },
  17. taskList:{
  18. recommend_task:[],
  19. newUser_task:[]
  20. }
  21. },
  22. onLoad: function (options) {
  23. this.stat();
  24. this.getActList('goods')
  25. },
  26. onShow: function () {
  27. this.getTaskList()
  28. },
  29. jumpToDetail(e){
  30. let type=e.currentTarget.dataset.type,aid=e.currentTarget.dataset.aid;
  31. wx.navigateTo({
  32. url: (type=='act'?'/pages/product/activity/index?aid=':'/pages/product/goods/detail?aid=')+aid,
  33. })
  34. },
  35. // 等级特权选项
  36. checkOptions(e){
  37. let index= e.currentTarget.dataset.index,percent='';
  38. switch (index) {
  39. case '1':
  40. percent='25%';
  41. if (this.data.levelList.goods.length<=0) {
  42. this.getActList('goods');
  43. }
  44. break;
  45. case '2':
  46. percent='50%';
  47. if (this.data.levelList.activite.length<=0) {
  48. this.getActList('act');
  49. }
  50. break;
  51. case '3':
  52. percent='75%';
  53. break;
  54. case '4':
  55. percent='100%';
  56. break;
  57. }
  58. this.setData({defaultLevel:index,percent})
  59. },
  60. // 获取活动抵扣/商品抵扣
  61. getActList(type){
  62. let that=this;
  63. util.ajax({
  64. func:type=='act'?"v2/article/recom_list":'ebusiness/list',
  65. data:{
  66. useUserCoin:1,
  67. pageIndex: 1,
  68. pageSize:type=='act'?3:4
  69. },
  70. load:false
  71. }, function(res) {
  72. if(res.code == 0){
  73. let data=type=='act'?res.data.list:res.data.goods;
  74. data.forEach(el => {
  75. el.finalPrice=parseInt((Number(el.price)*100-el.maxUserCoin*10)/100) ;
  76. });
  77. if (type=='act') {
  78. that.setData({'levelList.activite':data})
  79. } else {
  80. that.setData({'levelList.goods':data})
  81. }
  82. }else
  83. util.showTips(res.reason);
  84. })
  85. },
  86. // 获取宝贝币任务列表
  87. getTaskList(){
  88. let that=this;
  89. util.ajax({
  90. func:'v2/user_coin/task/list',
  91. load:false
  92. }, function(res) {
  93. if(res.code == 0){
  94. let arr=[],arr1=[];
  95. res.data.forEach(el => {
  96. if (el.type==0) {
  97. arr.push(el)
  98. }else{
  99. arr1.push(el)
  100. }
  101. });
  102. that.setData({'taskList.recommend_task':arr,'taskList.newUser_task':arr1})
  103. console.log(that.data.taskList)
  104. }
  105. })
  106. },
  107. // 获取购买信息
  108. getBuyInfo(){
  109. let that=this;
  110. return new Promise(function(resolve, reject) {
  111. util.ajax({
  112. func:'v2/user/buy/info',
  113. load:false
  114. }, function(res) {
  115. if(res.code == 0){
  116. let haveEmpty=true,info=res.data;
  117. for (const key in info) {
  118. if (Object.hasOwnProperty.call(info, key) && util.isEmpty(info[key])) {
  119. haveEmpty=false;
  120. }
  121. }
  122. resolve(haveEmpty)
  123. }else{
  124. resolve(false)
  125. }
  126. })
  127. })
  128. },
  129. // 获取出行人信息列表
  130. getChildList(){
  131. let that=this;
  132. return new Promise(function(resolve, reject) {
  133. util.ajax({
  134. func:'user/idcardinfo_list',
  135. data:{type:0},
  136. load:false
  137. }, function(res) {
  138. if(res.code == 0 && res.data.length > 0){
  139. resolve(true)
  140. }else{
  141. resolve(false)
  142. }
  143. })
  144. })
  145. },
  146. // 任务选择
  147. checkTask(e){
  148. console.log(e)
  149. let code = e.currentTarget.dataset.code,url='',
  150. taskId= e.currentTarget.dataset.id,
  151. type=false,that=this;
  152. switch (code) {
  153. // 新人任务
  154. case "saveCardInfo": //出行人信息
  155. this.getChildList().then(res=>{
  156. console.log(res)
  157. if (res) {
  158. util.finishCoinTask(taskId).then(res=>{
  159. util.showTips(res);
  160. that.getTaskList()
  161. })
  162. } else {
  163. url="/pages/account/cards/index?taskId="+taskId+"&defaultType=0&makeTask=true";
  164. that.urlToPage(type,url)
  165. }
  166. })
  167. break;
  168. case "saveUserInfo": //购买信息
  169. this.getBuyInfo().then(res=>{
  170. console.log(res)
  171. if (res) {
  172. util.finishCoinTask(taskId).then(res=>{
  173. util.showTips(res);
  174. that.getTaskList()
  175. })
  176. } else {
  177. url="/pages/account/cards/index?taskId="+taskId+"&defaultType=1&makeTask=true";
  178. that.urlToPage(type,url)
  179. }
  180. })
  181. break;
  182. case "companyVideo": //品牌视频
  183. url='/pages/public/swiper/web?url=https://mp.weixin.qq.com/s/E3QNVDwO8PongUk0Rr5w1w&title=微电影';
  184. that.urlToPage(type,url)
  185. util.finishCoinTask(taskId).then(res=>{
  186. // util.showTips(res);
  187. })
  188. break;
  189. case "companyDesc": //品牌介绍
  190. url='/pages/public/swiper/web?url=https://mp.weixin.qq.com/s/7TqtMO62AtHrLaWM93OhRA&title=公司资质';
  191. that.urlToPage(type,url)
  192. util.finishCoinTask(taskId).then(res=>{
  193. // util.showTips(res);
  194. })
  195. break;
  196. // 推荐任务
  197. case "buyArticle": //消费活动
  198. url="/pages/home/index";
  199. type=true;
  200. that.urlToPage(type,url)
  201. break;
  202. case "share"://海报发圈
  203. url="/pages/account/monetaryCenter/posterTask"
  204. that.urlToPage(type,url)
  205. break;
  206. case "comment"://评论
  207. url="/pages/order/index/order?otype=3"
  208. that.urlToPage(type,url)
  209. break;
  210. case "browseArticle"://浏览活动
  211. url="/pages/home/index";
  212. type=true;
  213. let data={};
  214. data.date=util.getNowFormatDate();
  215. data.view_act=1;
  216. console.log(data)
  217. wx.setStorageSync("task_viewAct", data);
  218. that.urlToPage(type,url)
  219. break;
  220. }
  221. },
  222. urlToPage(type,url){
  223. if (type && !util.isEmpty(url)) {
  224. wx.switchTab({
  225. url: url,
  226. })
  227. } else {
  228. wx.navigateTo({
  229. url: url,
  230. })
  231. }
  232. },
  233. jumpPage(e){
  234. let url=e.currentTarget.dataset.url;
  235. if (url=='/pages/home/index') {
  236. wx.switchTab({
  237. url: url,
  238. })
  239. }else{
  240. wx.navigateTo({
  241. url: url,
  242. })
  243. }
  244. },
  245. // 获取宝贝币相关参数
  246. stat(){
  247. let that = this;
  248. util.stat().then(res=>{
  249. that.setData({ stat: res });
  250. let data=util.getCoinLevel(res.allCoin)
  251. that.setData({initialSwipe:data.index,levelName:data.levelName})
  252. })
  253. },
  254. onShareAppMessage: function () {
  255. }
  256. })