detail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="giftDetail">
  3. <view class="bannerContainer">
  4. <swiper class="banner" v-if="type==1">
  5. <swiper-item v-if="item"><view v-if="item.gift_info.imgurl" class="img" :style="{ backgroundImage: `url(${item.gift_info.imgurl})` }" /></swiper-item>
  6. </swiper>
  7. <swiper class="banner" v-else>
  8. <swiper-item v-if="item"><view v-if="item.img" class="img" :style="{ backgroundImage: `url(${item.img})` }" /></swiper-item>
  9. </swiper>
  10. <view class="num">
  11. <text class="spec">1</text>
  12. <text>/</text>
  13. <text>1</text>
  14. </view>
  15. </view>
  16. <view class="good">
  17. <view class="top">
  18. <view class="title" v-if="item">{{ item.name }}</view>
  19. <view class="surplus" v-if="item">限量
  20. <text v-if="type==1">{{ item.gift_info.gift_num }}份</text>
  21. <text v-else>{{ item.total }}份</text>
  22. </view>
  23. </view>
  24. <view class="bottom">
  25. <view class="num">
  26. <text class="spec">{{ totalPrice }}</text>
  27. <text>奖学金</text>
  28. </view>
  29. <!-- <view class="countNum" v-if="type == 1"><custom-counter :count-num.sync="item.num"></custom-counter></view> -->
  30. <view class="countNum"><custom-counter :count-num.sync="num"></custom-counter></view>
  31. </view>
  32. </view>
  33. <view class="desc">
  34. <view class="fixed">产品参数</view>
  35. <view class="content">本产品由大卫博士平台提供。本页面的信息以及服务由大卫博士交易平台提供,请确保账号处于正常状态。 全部使用奖学金形式兑换!</view>
  36. </view>
  37. <view class="submitBtn" @click="submit" v-if="type == 1">确认修改</view>
  38. <view class="submitBtn" :class="item.surplus === 0 ? 'disable' : ''" @click="submit" v-else>{{ item.surplus ? '立即兑换' : '已兑完' }}</view>
  39. <toast-confirm :show.sync="toastInfo.show" :title="toastInfo.title" :content="toastInfo.content" @confirm="exchangeConfirm" />
  40. </view>
  41. </template>
  42. <script>
  43. import { api_getAddress, api_submitExchange ,editGiftOrder, GetBonus } from '../../api.js';
  44. import customCounter from './components/count2';
  45. export default {
  46. components: {
  47. customCounter
  48. },
  49. data() {
  50. return {
  51. pageTitle: '礼品详情',
  52. item: {},
  53. num: 1,
  54. type:'',
  55. requesting: false,
  56. userServerInfo: {
  57. bonus: ''
  58. },
  59. toastInfo: {
  60. show: false,
  61. title: '',
  62. content: ''
  63. }
  64. };
  65. },
  66. // onLoad:function(option){
  67. // this.type=option.type
  68. // console.log('我是type值:',this.type)
  69. // if (this.type == 1) {
  70. // this.num = this.item.num
  71. // } else {
  72. // this.num = 1
  73. // }
  74. // // console.log(this.item)
  75. // },
  76. computed: {
  77. totalPrice() {
  78. if (this.item) {
  79. return this.item.price * this.num;
  80. }
  81. },
  82. // userServerInfo() {
  83. // //用户服务器信息
  84. // return this.$store.state.userServerInfo;
  85. // }
  86. },
  87. onShow() {
  88. this.getBound()
  89. },
  90. methods: {
  91. getBound(){
  92. this.$ajax.get(GetBonus).then(([, { data: res }]) => {
  93. //获取兑换礼品列表
  94. this.userServerInfo.bonus = res.data.bonus
  95. });
  96. },
  97. closeToast() {
  98. this.toastInfo.title = '';
  99. this.toastInfo.content = '';
  100. this.toastInfo.show = false;
  101. },
  102. exchangeConfirm(flag) {
  103. const _this = this;
  104. if (flag) {
  105. if (!this.requesting) {
  106. this.requesting = true;
  107. this.closeToast();
  108. uni.showLoading();
  109. this.$ajax.get(`${api_submitExchange}?gift_id=${this.item.id}&num=${this.num}&address_id=123`).then(([, { data: res }]) => {
  110. uni.hideLoading();
  111. this.requesting = false;
  112. if (res.code == 200) {
  113. uni.navigateTo({
  114. url:'./success?totalPrice='+this.totalPrice
  115. })
  116. // uni.showModal({
  117. // content: '兑换成功',
  118. // showCancel: false,
  119. // success(res) {
  120. // if (res.confirm) {
  121. // _this.$store.dispatch('onLaunch');
  122. // }
  123. // }
  124. // });
  125. } else {
  126. uni.hideLoading();
  127. this.requesting = false;
  128. uni.showModal({
  129. content: res.msg || '兑换失败:库存不足',
  130. showCancel: false
  131. });
  132. }
  133. })
  134. }
  135. } else {
  136. this.closeToast();
  137. }
  138. },
  139. submit() {
  140. if (!this.item.surplus) {
  141. uni.showModal({
  142. content: '商品已兑换完',
  143. showCancel: false
  144. });
  145. return false;
  146. }
  147. if (this.num) {
  148. if (this.userServerInfo.bonus >= this.totalPrice) {
  149. this.toastInfo.title = '温馨提醒';
  150. this.toastInfo.content = `您确定兑换${this.num}件商品吗?`;
  151. this.toastInfo.show = true;
  152. }
  153. else {
  154. uni.showModal({
  155. content: '奖学金余额不足',
  156. showCancel: false
  157. });
  158. }
  159. } else {
  160. uni.showModal({
  161. content: '数量不能为空',
  162. showCancel: false
  163. });
  164. }
  165. }
  166. },
  167. created() {
  168. //加载完成后开启监听全局 MESSAGE 事件
  169. this.item = getApp().globalData.detail; //从兑换列表页面进入当前页面后从 getApp().globalData.detail 取值
  170. }
  171. };
  172. </script>
  173. <style lang="scss" scoped>
  174. page {
  175. display: flex;
  176. flex-direction: column;
  177. .giftDetail {
  178. flex: 1;
  179. overflow: hidden;
  180. .bannerContainer {
  181. width: 100%;
  182. height: 628rpx;
  183. position: relative;
  184. .banner {
  185. height: 100%;
  186. width: 100%;
  187. .img {
  188. width: 100%;
  189. height: 100%;
  190. background-position: center;
  191. background-repeat: no-repeat;
  192. background-size: 100%;
  193. }
  194. }
  195. .num {
  196. position: absolute;
  197. width: 112rpx;
  198. height: 48rpx;
  199. border-radius: 48rpx;
  200. line-height: 48rpx;
  201. color: #ffffff;
  202. font-size: 24rpx;
  203. bottom: 54rpx;
  204. right: 44rpx;
  205. background-color: rgba(0, 0, 0, 0.24);
  206. text-align: center;
  207. .spec {
  208. font-size: 28rpx !important;
  209. }
  210. }
  211. }
  212. .good {
  213. width: 100%;
  214. height: 264rpx;
  215. background: linear-gradient(94deg, #f97c55 0%, #f44545 100%);
  216. margin-bottom: 30rpx;
  217. padding: 10rpx;
  218. box-sizing: border-box;
  219. position: relative;
  220. &::after {
  221. content: '';
  222. display: block;
  223. position: absolute;
  224. top: 10rpx;
  225. right: 10rpx;
  226. width: 174rpx;
  227. height: 218rpx;
  228. background-position: top;
  229. background-size: 100%;
  230. background-repeat: no-repeat;
  231. background-image: url(../../static/gift/5.png);
  232. }
  233. .top {
  234. margin-bottom: 20rpx;
  235. width: 100%;
  236. display: flex;
  237. align-items: center;
  238. justify-content: space-between;
  239. height: 72rpx;
  240. padding: 0 20rpx;
  241. .title {
  242. color: #ffffff;
  243. font-size: 40rpx;
  244. line-height: 56rpx;
  245. }
  246. .surplus {
  247. color: #ffffff;
  248. font-size: 28rpx;
  249. align-self: flex-end;
  250. }
  251. }
  252. .bottom {
  253. width: 100%;
  254. height: 120rpx;
  255. border-radius: 8rpx;
  256. background-color: #ffffff;
  257. display: flex;
  258. align-items: center;
  259. justify-content: space-between;
  260. padding: 0 20rpx;
  261. box-sizing: border-box;
  262. position: relative;
  263. z-index: 3;
  264. overflow: hidden;
  265. .num {
  266. color: #ea4a41;
  267. font-size: 24rpx;
  268. .spec {
  269. font-size: 40rpx;
  270. }
  271. }
  272. .countNum {
  273. width: 180rpx;
  274. }
  275. &::before {
  276. content: '';
  277. display: block;
  278. width: 114rpx;
  279. height: 144rpx;
  280. position: absolute;
  281. top: 50%;
  282. left: 16rpx;
  283. transform: translateY(-50%);
  284. background-image: url(../../static/gift/5.png);
  285. background-position: center;
  286. background-size: 100%;
  287. background-repeat: no-repeat;
  288. }
  289. }
  290. }
  291. .desc {
  292. width: 100%;
  293. padding: 30rpx;
  294. box-sizing: border-box;
  295. margin-bottom: 100rpx;
  296. .fixed {
  297. color: #333333;
  298. font-size: 32rpx;
  299. font-weight: bold;
  300. margin-bottom: 20rpx;
  301. }
  302. .content {
  303. color: #333333;
  304. font-size: 28rpx;
  305. line-height: 48rpx;
  306. }
  307. }
  308. .submitBtn {
  309. width: 530rpx;
  310. height: 88rpx;
  311. line-height: 88rpx;
  312. text-align: center;
  313. background: linear-gradient(93deg, #f97c55 0%, #f44545 100%);
  314. color: #ffffff;
  315. font-size: 32rpx;
  316. border-radius: 88rpx;
  317. margin: 0 auto 40rpx auto;
  318. &.disable {
  319. background: #999999 !important;
  320. color: #f8f8f8 !important;
  321. }
  322. }
  323. }
  324. }
  325. </style>