detail.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <template>
  2. <app-layout>
  3. <view class="code-info" :style="{backgroundImage: 'url('+ background + ')'}">
  4. <view class="code">{{code}}</view>
  5. <view v-if="exchange == 0">该兑换码包含{{list.length}}种礼品,您可以{{mode == 0 ? '全部':'任选一件'}}兑换:</view>
  6. <view v-if="exchange == 1">于{{r_raffled_at}}兑换以下礼品</view>
  7. </view>
  8. <view>
  9. <view class="rewards" v-for="(item,index) in list" :key="index">
  10. <view class="rewards-top dir-left-nowrap cross-center" :class="mode == 1 ? 'active-item':''">
  11. <app-radio width="88" :height="item.type == 'integral' || item.type == 'balance' || item.type == 'svip' ? '36':'140'" @click="toggle" :value="item.active" :item="item" :theme="getTheme" type="round" v-if="mode == 1">
  12. </app-radio>
  13. <view v-if="item.type == 'goods'" class="dir-left-nowrap card goods">
  14. <image class="card-img" mode="aspectFill" :src="item.goods_info.cover_pic"></image>
  15. <view class="card-info">
  16. <view class="t-omit-two card-name">{{item.goods_info.name}}</view>
  17. <view class="attr">{{item.goods_info.attr_str}}</view>
  18. <view class="dir-right-nowrap">
  19. <div class="goods-num" :class="getTheme + '-m-text ' + getTheme">x{{item.goods_num}}</div>
  20. </view>
  21. </view>
  22. </view>
  23. <view v-if="item.type == 'card'" class="dir-left-nowrap card">
  24. <image class="card-img" mode="aspectFill" v-if="item.card_info.pic_url" :src="item.card_info.pic_url"></image>
  25. <view class="card-info">
  26. <view class="dir-left-nowrap">
  27. <image src="./../image/card.png"></image>
  28. <view class="t-omit-two card-name">{{item.card_info.name}}</view>
  29. </view>
  30. <view class="main-between cross-center">
  31. <div class="card-number" :class="getTheme + '-m-text ' + getTheme + '-m-back-o ' + getTheme">剩余{{item.card_info.number}}次</div>
  32. <div class="card-num" :class="getTheme + '-m-text ' + getTheme">x{{item.card_num}}</div>
  33. </view>
  34. </view>
  35. </view>
  36. <view v-if="item.type == 'coupon'" class="dir-left-nowrap card">
  37. <view class="card-info">
  38. <view class="dir-left-nowrap">
  39. <image src="./../image/coupon.png"></image>
  40. <view class="t-omit-two card-name">{{item.coupon_info.name}}</view>
  41. </view>
  42. <view class="main-between cross-center">
  43. <div v-if="item.coupon_info.type == 1" class="card-number" :class="getTheme + '-m-text ' + getTheme + '-m-back-o ' + getTheme">{{item.coupon_info.discount}}折 满{{item.coupon_info.min_price == 0 ? '任意金额': '¥'+item.coupon_info.min_price}}可用 <text style="margin-left: 10rpx" v-if="item.coupon_info.discount_limit">优惠上限¥{{item.coupon_info.discount_limit}}</text></div>
  44. <div v-if="item.coupon_info.type == 2" class="card-number" :class="getTheme + '-m-text ' + getTheme + '-m-back-o ' + getTheme">¥{{item.coupon_info.sub_price}} 满{{item.coupon_info.min_price == 0 ? '任意金额': '¥'+item.coupon_info.min_price}}可用</div>
  45. <div class="card-num" :class="getTheme + '-m-text ' + getTheme">x{{item.coupon_num}}</div>
  46. </view>
  47. </view>
  48. </view>
  49. <view v-if="item.type == 'integral' || item.type == 'balance' || item.type == 'svip'" class="dir-left-nowrap balance">
  50. <view class="balance-info cross-center main-between">
  51. <view class="dir-left-nowrap cross-center">
  52. <image v-if="item.type == 'integral'" src="./../image/point.png"></image>
  53. <image v-if="item.type == 'balance'" src="./../image/balance.png"></image>
  54. <image v-if="item.type == 'svip'" src="./../image/svip.png"></image>
  55. <view class="balance-name">{{item.name}}</view>
  56. </view>
  57. <view v-if="item.type == 'integral'" :class="getTheme + '-m-text ' + getTheme">{{item.integral_num}}</view>
  58. <view v-if="item.type == 'balance'" :class="getTheme + '-m-text ' + getTheme">¥{{item.balance}}</view>
  59. <view v-if="item.type == 'svip'" :class="getTheme + '-m-text ' + getTheme">{{item.svip_info.discount}}折</view>
  60. </view>
  61. </view>
  62. </view>
  63. <view v-if="exchange == 1" class="rewards-bottom dir-right-nowrap cross-center">
  64. <view v-if="item.is_send == 0" @click="apply(item)" :class="getTheme + '-m-back ' + getTheme" class="rewards-submit">立即领取</view>
  65. <view v-if="item.is_send == 1" class="rewards-submit over">已领取</view>
  66. <view v-if="item.goods_id > 0 || item.user_coupon_id.length > 0 || item.user_card_id.length > 0" @click="toDetail(item)" :class="getTheme + '-m-text ' + getTheme + '-m-border ' + getTheme" class="rewards-detail">查看详情</view>
  67. </view>
  68. </view>
  69. </view>
  70. <view v-if="exchange == 0" class="placeholder"></view>
  71. <view v-if="exchange == 0 && list.length > 0" class="apply safe-area-inset-bottom">
  72. <view class="apply-btn" @click="submit" :class="getTheme + '-m-back ' + getTheme">立即兑换</view>
  73. </view>
  74. <u-mask :show="dialog" :maskClickAble="false" :zoom="false">
  75. <view class="dialog">
  76. <image class="dialog-img" src="./../image/error.png"></image>
  77. <view class="dialog-msg">
  78. <text>{{msg}}</text>
  79. </view>
  80. <view class="dialog-other">{{other}}</view>
  81. <view @click="goback" :class="getTheme + '-m-back ' + getTheme" class="dialog-button">我知道了</view>
  82. </view>
  83. </u-mask>
  84. </app-layout>
  85. </template>
  86. <script>
  87. import {mapGetters, mapState} from 'vuex';
  88. import uMask from '../../../components/basic-component/u-mask/u-mask.vue';
  89. import appIphoneX from '../../../components/basic-component/app-iphone-x/app-iphone-x.vue';
  90. import appRadio from '../../../components/basic-component/app-radio/app-radio.vue';
  91. export default {
  92. name: "index",
  93. data() {
  94. return {
  95. first: true,
  96. loading: false,
  97. code: '',
  98. dialog: false,
  99. msg: '',
  100. other: '',
  101. background: '',
  102. r_raffled_at: '',
  103. list: [],
  104. mode: 0,
  105. exchange: 0,
  106. token: ''
  107. };
  108. },
  109. components:{
  110. 'app-radio': appRadio,
  111. uMask,
  112. 'app-iphone-x': appIphoneX,
  113. },
  114. onLoad(options) {
  115. let that = this;
  116. that.code = options.code;
  117. that.exchange = options.exchange == 1 ? 1 : 0;
  118. that.background = that.exchangeImg.a;
  119. switch(that.getTheme) {
  120. case 'b':
  121. that.background = that.exchangeImg.b;
  122. break;
  123. case 'c':
  124. that.background = that.exchangeImg.c;
  125. break;
  126. case 'd':
  127. that.background = that.exchangeImg.d;
  128. break;
  129. case 'e':
  130. that.background = that.exchangeImg.e;
  131. break;
  132. case 'g':
  133. that.background = that.exchangeImg.g;
  134. break;
  135. case 'h':
  136. that.background = that.exchangeImg.h;
  137. break;
  138. case 'i':
  139. that.background = that.exchangeImg.i;
  140. break;
  141. }
  142. that.$showLoading({
  143. type: 'global',
  144. text: '加载中...'
  145. });
  146. that.getList();
  147. },
  148. onShow() {
  149. if(this.exchange == 1 && !this.first) {
  150. this.getList()
  151. }
  152. },
  153. computed: {
  154. ...mapGetters('mallConfig', {
  155. getTheme: 'getTheme',
  156. }),
  157. ...mapState({
  158. exchangeImg: state => state.mallConfig.__wxapp_img.exchange
  159. })
  160. },
  161. methods: {
  162. toDetail(item) {
  163. if(item.type == 'goods') {
  164. uni.navigateTo({
  165. url: `/pages/goods/goods?id=${item.goods_id}&code=${this.code}&token=${item.token}&attr=${item.goods_info.attr_str}&attr_id=${item.attr_id}&goods_num=${item.goods_num}&exchange=${item.is_send}`
  166. });
  167. }else if(item.type == 'coupon') {
  168. uni.navigateTo({
  169. url: `/pages/coupon/details/details-no-share?person=1&id=${item.user_coupon_id[0]}`
  170. });
  171. }else if(item.type == 'card') {
  172. uni.navigateTo({
  173. url: `/pages/card/details/details?id=${item.user_card_id[0]}`
  174. });
  175. }
  176. },
  177. goback() {
  178. this.dialog = false;
  179. uni.navigateBack();
  180. },
  181. apply(item) {
  182. let that = this;
  183. uni.showLoading({
  184. title: '领取中...'
  185. });
  186. if(item.type != 'goods') {
  187. that.$request({
  188. url: that.$api.exchange.covert,
  189. data: {
  190. code: this.code,
  191. token: item.token
  192. },
  193. method: 'post'
  194. }).then(response=>{
  195. uni.hideLoading();
  196. if(response.code == 0) {
  197. uni.showToast({
  198. title: response.msg,
  199. duration: 1000
  200. });
  201. this.getList();
  202. }else {
  203. uni.showToast({
  204. title: response.msg,
  205. icon: 'none',
  206. duration: 1000
  207. });
  208. }
  209. }).catch(response => {
  210. uni.hideLoading();
  211. });
  212. }else {
  213. let mch_list = [{
  214. mch_id: 0,
  215. goods_list: [{
  216. id: item.goods_id,
  217. attr: item.goods_info.attr_str,
  218. num: item.goods_num,
  219. cat_id: 0,
  220. goods_attr_id: item.attr_id
  221. }],
  222. code: this.code,
  223. token: item.token,
  224. }];
  225. let url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(mch_list)}`;
  226. url += `&preview_url=${encodeURIComponent(this.$api.exchange.exchange_preview)}&submit_url=${encodeURIComponent(this.$api.exchange.exchange_submit)}&plugin=exchange`;
  227. uni.navigateTo({
  228. url: url
  229. })
  230. }
  231. },
  232. toggle(boolean,row) {
  233. for(let item of this.list) {
  234. if(item.token == row.token) {
  235. item.active = boolean;
  236. this.token = row.token
  237. }else {
  238. item.active = false;
  239. }
  240. }
  241. this.$forceUpdate();
  242. },
  243. submit() {
  244. let that = this;
  245. if(that.mode == 1 && !that.token) {
  246. uni.showToast({
  247. title: '请选择想要兑换的礼品',
  248. icon: 'none',
  249. duration: 1000
  250. });
  251. return false
  252. }
  253. if(this.loading) {
  254. return false
  255. }
  256. this.loading = true;
  257. uni.showLoading({
  258. title: '领取中...'
  259. });
  260. that.$request({
  261. url: that.$api.exchange.unite,
  262. data: {
  263. code: this.code,
  264. token: this.token
  265. },
  266. method: 'post'
  267. }).then(response=>{
  268. this.loading = false;
  269. uni.hideLoading();
  270. if(response.code == 0) {
  271. this.exchange = 1;
  272. this.mode = 0;
  273. this.getList();
  274. }else {
  275. uni.showToast({
  276. title: response.msg,
  277. icon: 'none',
  278. duration: 1000
  279. });
  280. }
  281. }).catch(response => {
  282. uni.hideLoading();
  283. });
  284. },
  285. getList() {
  286. let that = this;
  287. that.$request({
  288. url: that.exchange == 1 ? that.$api.exchange.log_detail : that.$api.exchange.info,
  289. data: {
  290. code: that.code
  291. }
  292. }).then(response=>{
  293. that.$hideLoading();
  294. uni.hideLoading();
  295. that.first = false;
  296. if(response.code == 0) {
  297. if(that.exchange == 0) {
  298. that.list = response.list.rewards;
  299. that.mode = response.list.mode;
  300. if(that.mode == 1) {
  301. for(let item of that.list) {
  302. item.active = false;
  303. }
  304. }
  305. }else {
  306. that.r_raffled_at = response.data.codeModel.r_raffled_at
  307. that.list = response.data.rewards;
  308. }
  309. }else {
  310. if(that.exchange == 0) {
  311. that.msg = response.msg;
  312. that.other = '';
  313. if(response.msg == '该兑换码未到使用时间!') {
  314. that.other = response.data.valid_start_time + '-' + response.data.valid_end_time + ' 可用'
  315. }
  316. that.dialog = true;
  317. }else {
  318. uni.showToast({
  319. title: response.msg,
  320. icon: 'none',
  321. duration: 1000
  322. });
  323. }
  324. }
  325. }).catch(response => {
  326. that.$hideLoading();
  327. uni.hideLoading();
  328. });
  329. }
  330. }
  331. }
  332. </script>
  333. <style scoped lang="scss">
  334. .dialog {
  335. margin: 270rpx auto;
  336. background-color: #fff;
  337. border-radius: 16rpx;
  338. width: 600rpx;
  339. padding: 60rpx 0;
  340. text-align: center;
  341. .dialog-img {
  342. width: 200rpx;
  343. height: 200rpx;
  344. margin: 0 auto 20rpx;
  345. }
  346. .dialog-msg {
  347. font-size: 32rpx;
  348. color: #353535;
  349. }
  350. .dialog-other {
  351. font-size: 24rpx;
  352. color: #999999;
  353. }
  354. .dialog-button {
  355. font-size: 26rpx;
  356. width: 520rpx;
  357. height: 90rpx;
  358. border-radius: 45rpx;
  359. line-height: 90rpx;
  360. text-align: center;
  361. color: #fff;
  362. margin: 50rpx auto 0;
  363. }
  364. }
  365. .code-info {
  366. width: 702rpx;
  367. height: 240rpx;
  368. border-radius: 16rpx;
  369. background-size: 100% 100%;
  370. margin: 24rpx;
  371. text-align: center;
  372. color: #fff;
  373. font-size: 24rpx;
  374. .code {
  375. margin-top: 50rpx;
  376. display: inline-block;
  377. font-size: 38rpx;
  378. text-align: center;
  379. padding: 24rpx 95rpx;
  380. border-radius: 60rpx;
  381. color: #fff;
  382. background-color: rgba(255,255,255,.2);
  383. margin-bottom: 20rpx;
  384. }
  385. }
  386. .rewards {
  387. background-color: #fff;
  388. border-radius: 16rpx;
  389. width: 702rpx;
  390. margin: 24rpx auto 0;
  391. .rewards-top {
  392. padding: 34rpx 40rpx;
  393. &.active-item {
  394. padding-left: 0;
  395. }
  396. .active {
  397. width: 88rpx;
  398. height: 140rpx;
  399. text-align: center;
  400. flex-shrink: 0;
  401. image {
  402. width: 32rpx;
  403. height: 32rpx;
  404. margin-top: 54rpx;
  405. border-radius: 16rpx;
  406. }
  407. &.small {
  408. height: 36rpx;
  409. image {
  410. margin-top: 2rpx;
  411. }
  412. }
  413. }
  414. .goods-num {
  415. font-size: 28rpx;
  416. }
  417. .balance {
  418. width: 100%;
  419. .balance-info {
  420. width: 100%;
  421. image {
  422. width: 30rpx;
  423. height: 30rpx;
  424. margin-right: 14rpx;
  425. }
  426. .balance-name {
  427. font-size: 28rpx;
  428. color: #353535;
  429. }
  430. }
  431. }
  432. .card {
  433. width: 100%;
  434. &.goods {
  435. .card-info {
  436. .card-name {
  437. margin-top: 0;
  438. margin-bottom: 10rpx;
  439. }
  440. }
  441. }
  442. .card-img {
  443. height: 140rpx;
  444. width: 140rpx;
  445. border-radius: 8rpx;
  446. margin-right: 20rpx;
  447. flex-shrink: 0;
  448. }
  449. .card-info {
  450. width: 100%;
  451. image {
  452. width: 30rpx;
  453. height: 30rpx;
  454. margin-right: 14rpx;
  455. }
  456. .attr {
  457. font-size: 24rpx;
  458. color: #999;
  459. }
  460. .card-name {
  461. margin-top: -5rpx;
  462. font-size: 28rpx;
  463. color: #353535;
  464. margin-bottom: 30rpx;
  465. }
  466. .card-number {
  467. padding: 12rpx 20rpx;
  468. font-size: 24rpx;
  469. border-radius: 30rpx;
  470. }
  471. .card-num {
  472. font-size: 28rpx;
  473. }
  474. }
  475. }
  476. }
  477. .rewards-bottom {
  478. border-top: #{2rpx} solid #e2e2e2;
  479. height: #{118rpx};
  480. width: 100%;
  481. padding: 0 #{30rpx};
  482. .rewards-submit {
  483. height: #{68rpx};
  484. line-height: #{68rpx};
  485. text-align: center;
  486. padding: 0 #{30rpx};
  487. border-radius: #{40rpx};
  488. color: #fff;
  489. font-size: #{28rpx};
  490. &.over {
  491. background-color: #f7f7f7;
  492. color: #999999;
  493. }
  494. }
  495. .rewards-detail {
  496. height: #{68rpx};
  497. line-height: #{68rpx};
  498. text-align: center;
  499. padding: 0 #{30rpx};
  500. border-radius: #{40rpx};
  501. background-color: #fff;
  502. font-size: #{28rpx};
  503. border: #{2rpx} solid;
  504. margin-right: #{18rpx};
  505. }
  506. }
  507. }
  508. .placeholder {
  509. height: #{178rpx};
  510. width: 100%;
  511. }
  512. .apply {
  513. position: fixed;
  514. bottom: 0;
  515. left: 0;
  516. z-index: 2;
  517. height: #{154rpx};
  518. width: 100%;
  519. background-color: #fff;
  520. padding-top: #{26rpx};
  521. padding-left: #{24rpx};
  522. .apply-btn {
  523. width: #{702rpx};
  524. height: #{88rpx};
  525. line-height: #{88rpx};
  526. border-radius: #{44rpx};
  527. text-align: center;
  528. color: #fff;
  529. font-size: #{32rpx};
  530. }
  531. }
  532. </style>