commodityInfo.vue 5.7 KB

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