funMixin.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // import router from '@/router'
  2. import api from '../api'
  3. import {sendReq} from './sendReqMixin'
  4. import canvasConfig from '../config'
  5. /*
  6. * 公共方法的 mixin
  7. */
  8. export const tool = {
  9. mixins: [sendReq],
  10. props: {
  11. isNoData: {
  12. type: Boolean,
  13. default: false
  14. }
  15. },
  16. methods: {
  17. // 请求数据前 请求完再显示所有组件
  18. beforeGetData(){
  19. if(typeof(uni) !== 'undefined'){
  20. uni.getStorage({
  21. key: 'sendNum',
  22. success: function (res) {
  23. let sendNum = res.data;
  24. console.log('sendNum',parseInt(sendNum) + 1);
  25. uni.setStorage({key: 'sendNum',data: parseInt(sendNum) + 1});
  26. this.$emit('cleckLoading')
  27. }
  28. })
  29. } else {
  30. let sendNum = localStorage.getItem('sendNum')
  31. console.log('sendNum',parseInt(sendNum) + 1);
  32. localStorage.setItem('sendNum',parseInt(sendNum) + 1)
  33. this.$emit('cleckLoading')
  34. }
  35. },
  36. // 请求数据后
  37. afterGetData(){
  38. if(typeof(uni) !== 'undefined'){
  39. uni.getStorage({
  40. key: 'sendNum',
  41. success: function (res) {
  42. let sendNum = res.data;
  43. console.log('sendNum',parseInt(sendNum) - 1);
  44. uni.setStorage({key: 'sendNum',data: parseInt(sendNum) - 1});
  45. this.$emit('cleckLoading')
  46. }
  47. })
  48. } else {
  49. let sendNum = localStorage.getItem('sendNum')
  50. console.log('sendNum',parseInt(sendNum) - 1);
  51. localStorage.setItem('sendNum',parseInt(sendNum) - 1)
  52. this.$emit('cleckLoading')
  53. }
  54. },
  55. // 判断url
  56. jumpLink (linkObj) {
  57. var link = ''
  58. if(linkObj && linkObj.typeText && linkObj.data){
  59. switch (linkObj.typeText) {
  60. case '类别':
  61. router.push({name:'category',query:{classifyData:JSON.stringify(linkObj.data)}})
  62. break
  63. case '店辅':
  64. router.push({
  65. path: '/store',
  66. query: {shopId: linkObj.data.shopId}
  67. });
  68. break
  69. case '商品':
  70. this.setCurrentPro(linkObj.data)
  71. router.push("/productDetail");
  72. break
  73. case '自定义':
  74. // router.push("/category");
  75. break
  76. }
  77. } else if(linkObj.selsectValue==='/index'){
  78. router.push("/index");
  79. }
  80. return link
  81. },
  82. // 跳转到类别主页
  83. jumpCategory(item){
  84. },
  85. // 跳转到店铺主页
  86. jumpStore(item){
  87. },
  88. // 跳转到商品详情
  89. jumpProductDetail(item){
  90. },
  91. // 跳转到秒杀专区
  92. jumpSeckills(item){
  93. },
  94. // 跳转到拼团专区
  95. jumpGroupWorks(item){
  96. },
  97. // 跳转到折扣专区
  98. jumpDiscount(item){
  99. },
  100. // 跳转到会员专区
  101. jumpVip(){
  102. },
  103. // 跳转到公告详情
  104. jumpNoticeDetail(item){
  105. },
  106. // 领取优惠券
  107. receiveCoupon(item) {
  108. var key = canvasConfig.getToken()
  109. if (key) {
  110. var paramsData = {}
  111. if(this.typeId === 1){
  112. paramsData.couponId = item.couponId
  113. } else if(this.typeId === 3) {
  114. paramsData.shopCouponId = item.shopCouponId
  115. paramsData.shopId = this.shopId
  116. }
  117. let params = {
  118. url: api.takeCoupon,
  119. method: 'POST',
  120. data: paramsData
  121. }
  122. this.sendReq(params, (res) => {
  123. this.$message({
  124. message: '领取成功!',
  125. type: 'success'
  126. })
  127. this.getData()
  128. })
  129. } else {
  130. this.$message({
  131. message: '请先登录'
  132. })
  133. this.$router.push({path: '/login'})
  134. }
  135. },
  136. // 加入购物车
  137. addCart(id){
  138. console.log(id)
  139. }
  140. }
  141. }