commodityInfo.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. if(numB>numA){
  114. uni.showToast({
  115. mask: true,
  116. icon: "none",
  117. position: "center",
  118. title: "积分不足",
  119. duration: 2000
  120. });
  121. return
  122. }
  123. uni.showModal({
  124. title: '提示',
  125. content: '确认兑换?',
  126. success: function(res) {
  127. if (res.confirm) {
  128. self.exchangeGoods();
  129. }
  130. }
  131. });
  132. },
  133. async exchangeGoods() {
  134. let obj = {
  135. mid:this.mid,
  136. sid:this.sid,
  137. pid:this.pid,
  138. pri:this.pri,
  139. token: uni.getStorageSync('token'),
  140. uid:uni.getStorageSync('userId')
  141. }
  142. const {
  143. data
  144. } = await exchangeGoods(obj)
  145. if (data.code == 200) {
  146. this.$set(this, 'state', 1);
  147. this.$set(this, 'pageType', 2);
  148. }
  149. },
  150. bottomButton(){
  151. if(this.state == 1){
  152. uni.redirectTo({
  153. url: '/pages/home',
  154. });
  155. }else{
  156. this.clickButton();
  157. }
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="stylus" scoped>
  163. .commodityInfo {
  164. flex: 1;
  165. display: flex;
  166. flex-direction: column;
  167. overflow: hidden;
  168. background: url(../static/back2.png);
  169. background-size: 100% 100%;
  170. .commodityInfo-page {
  171. flex: 1;
  172. display: flex;
  173. flex-direction: column;
  174. overflow: hidden;
  175. .flex-null-1 {
  176. flex: 1;
  177. }
  178. .flex-null-2 {
  179. flex: 4;
  180. }
  181. .product-content {
  182. flex: 1;
  183. display: flex;
  184. flex-direction: column;
  185. align-items: center;
  186. justify-content: center;
  187. padding: 60rpx 0;
  188. text-align: center;
  189. .product-img{
  190. width:200rpx;
  191. height:200rpx;
  192. margin:0 auto 60rpx;
  193. }
  194. .product-name {
  195. font-size: 40rpx;
  196. font-weight: 700;
  197. color: #222;
  198. line-height: 1.4;
  199. margin-bottom: 30rpx;
  200. }
  201. .product-slotNo {
  202. margin-top:40rpx;
  203. font-size: 48rpx;
  204. font-weight: 700;
  205. color: #0183FA;
  206. text-shadow: 0 2rpx 4rpx rgba(231, 76, 60, 0.2);
  207. animation: pulse 2s infinite alternate;
  208. }
  209. .product-price {
  210. font-size: 56rpx;
  211. font-weight: 700;
  212. color: #e74c3c;
  213. text-shadow: 0 2rpx 4rpx rgba(231, 76, 60, 0.2);
  214. animation: pulse 2s infinite alternate;
  215. }
  216. @keyframes pulse {
  217. 0% {
  218. transform: scale(1);
  219. }
  220. 100% {
  221. transform: scale(1.02);
  222. }
  223. }
  224. }
  225. .clickButton {
  226. width: 400rpx;
  227. line-height: 100rpx;
  228. background: #0183FA;
  229. border-radius: 10rpx;
  230. font-size: 36rpx;
  231. color: #fff;
  232. text-align center;
  233. margin: 140rpx auto 0;
  234. }
  235. .remind-img {
  236. width: 200rpx;
  237. height: 200rpx;
  238. margin:200rpx auto 0;
  239. }
  240. .commodity-message{
  241. text-align: center;
  242. color:#333;
  243. font-size:40rpx;
  244. margin-top:60rpx;
  245. }
  246. }
  247. }
  248. </style>