commodityInfo.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <!-- 商品信息 -->
  2. <template>
  3. <view class="commodityInfo">
  4. <view class="commodityInfo-page" v-if="pageType == 1">
  5. <view class="flex-null-1"></view>
  6. <view class="product-content">
  7. <img class="product-img" src="@/static/icon_dhli.png">
  8. <view class="product-name">{{ commodityData.name }}</view>
  9. <view class="product-price">
  10. <text class="price-value">{{ commodityData.price?commodityData.price+' 积分':'' }}</text>
  11. </view>
  12. </view>
  13. <view class="flex-null-2"></view>
  14. <view class="clickButton" @click="clickButton()">立即兑换</view>
  15. <view class="flex-null-1"></view>
  16. </view>
  17. <view class="commodityInfo-page" v-if="pageType == 2">
  18. <img class="remind-img" v-if="state==1" src="@/static/icon_kcxq_cg.png">
  19. <img class="remind-img" v-if="state!=1" src="@/static/icon_kcxq_sb.png">
  20. <view class="commodity-message">{{state==1?'兑换成功':'兑换失败'}}</view>
  21. <view class="flex-null-2"></view>
  22. <view class="clickButton" @click="bottomButton()">{{state==1?'返回':'重试'}}</view>
  23. <view class="flex-null-1"></view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. getCommodityInfo,
  30. exchangeGoods
  31. } from '@/api/index';
  32. import { browserDetection,safeToNumber } from '@/utils/auth';
  33. export default {
  34. data() {
  35. return {
  36. pageType: '',
  37. mid: "",
  38. sid: "",
  39. pid: "",
  40. pri: "",
  41. commodityData: {
  42. name: '',
  43. price: '',
  44. },
  45. state: '',
  46. }
  47. },
  48. onLoad(option) {
  49. let self = this;
  50. if (option.q) {
  51. let text = decodeURIComponent(option.q)
  52. text = text.replace('"', '')
  53. text = text.replace('"', '')
  54. let list = text.split("?")[1].split("&");
  55. for (let i = 0; i < list.length; i++) {
  56. let newList = list[i].split("=");
  57. if (newList[0] == 'mid') {
  58. self.mid = newList[1];
  59. } else if (newList[0] == 'sid') {
  60. self.sid = newList[1];
  61. } else if (newList[0] == 'pid') {
  62. self.pid = newList[1];
  63. } else if (newList[0] == 'pri') {
  64. self.pri = newList[1];
  65. }
  66. }
  67. this.getCommodityInfo();
  68. } else {
  69. uni.showToast({
  70. mask: true,
  71. icon: "none",
  72. position: "center",
  73. title: "请扫描正确的二维码",
  74. duration: 2000
  75. });
  76. setTimeout(() => {
  77. uni.navigateBack();
  78. }, 2000);
  79. }
  80. },
  81. onShow() {
  82. browserDetection();
  83. },
  84. methods: {
  85. async getCommodityInfo() {
  86. let obj = {
  87. token: uni.getStorageSync('token'),
  88. phone: uni.getStorageSync('phone'),
  89. }
  90. const {
  91. data
  92. } = await getCommodityInfo(obj)
  93. if (data.code == 200) {
  94. this.$set(this, 'commodityData', data.data);
  95. this.$set(this, 'pageType', 1);
  96. }
  97. },
  98. clickButton() {
  99. let self = this;
  100. const numA = safeToNumber(uni.getStorageSync('points'))
  101. const numB = safeToNumber(this.commodityData.price);
  102. console.log('numA',numA)
  103. console.log('numB',numB)
  104. if(numB>numA){
  105. uni.showToast({
  106. mask: true,
  107. icon: "none",
  108. position: "center",
  109. title: "积分不足",
  110. duration: 2000
  111. });
  112. return
  113. }
  114. uni.showModal({
  115. title: '提示',
  116. content: '确认兑换?',
  117. success: function(res) {
  118. if (res.confirm) {
  119. self.exchangeGoods();
  120. }
  121. }
  122. });
  123. },
  124. async exchangeGoods() {
  125. let obj = {
  126. token: uni.getStorageSync('token'),
  127. phone: uni.getStorageSync('phone'),
  128. mid: this.mid,
  129. sid: this.sid,
  130. pid: this.pid,
  131. pri: this.pri,
  132. }
  133. const {
  134. data
  135. } = await exchangeGoods(obj)
  136. if (data.code == 200) {
  137. this.$set(this, 'state', data.data.state);
  138. this.$set(this, 'pageType', 2);
  139. }
  140. },
  141. bottomButton(){
  142. if(this.state == 1){
  143. uni.redirectTo({
  144. url: '/pages/home',
  145. });
  146. }else{
  147. this.clickButton();
  148. }
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="stylus" scoped>
  154. .commodityInfo {
  155. flex: 1;
  156. display: flex;
  157. flex-direction: column;
  158. overflow: hidden;
  159. background: url(../static/back2.png);
  160. background-size: 100% 100%;
  161. .commodityInfo-page {
  162. flex: 1;
  163. display: flex;
  164. flex-direction: column;
  165. overflow: hidden;
  166. .flex-null-1 {
  167. flex: 1;
  168. }
  169. .flex-null-2 {
  170. flex: 4;
  171. }
  172. .product-content {
  173. flex: 1;
  174. display: flex;
  175. flex-direction: column;
  176. align-items: center;
  177. justify-content: center;
  178. padding: 60rpx 0;
  179. text-align: center;
  180. .product-img{
  181. width:200rpx;
  182. height:200rpx;
  183. margin:0 auto 60rpx;
  184. }
  185. .product-name {
  186. font-size: 40rpx;
  187. font-weight: 700;
  188. color: #222;
  189. line-height: 1.4;
  190. margin-bottom: 30rpx;
  191. }
  192. .product-price {
  193. font-size: 56rpx;
  194. font-weight: 700;
  195. color: #e74c3c;
  196. text-shadow: 0 2rpx 4rpx rgba(231, 76, 60, 0.2);
  197. animation: pulse 2s infinite alternate;
  198. }
  199. @keyframes pulse {
  200. 0% {
  201. transform: scale(1);
  202. }
  203. 100% {
  204. transform: scale(1.02);
  205. }
  206. }
  207. }
  208. .clickButton {
  209. width: 400rpx;
  210. line-height: 100rpx;
  211. background: #0183FA;
  212. border-radius: 10rpx;
  213. font-size: 36rpx;
  214. color: #fff;
  215. text-align center;
  216. margin: 140rpx auto 0;
  217. }
  218. .remind-img {
  219. width: 200rpx;
  220. height: 200rpx;
  221. margin:200rpx auto 0;
  222. }
  223. .commodity-message{
  224. text-align: center;
  225. color:#333;
  226. font-size:40rpx;
  227. margin-top:60rpx;
  228. }
  229. }
  230. }
  231. </style>