detail.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <template>
  2. <app-layout>
  3. <view class="code-info" :style="{backgroundImage: 'url('+ exchangeImg.bg + ')',backgroundColor: getTheme.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" :style="{'color': getTheme.color}">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" :style="{'color': getTheme.color,'background-color': getTheme.background_o}">剩余{{item.card_info.number}}次</div>
  32. <div class="card-num" :style="{'color': getTheme.color}">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" :style="{'color': getTheme.color,'background-color': getTheme.background_o}">{{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" :style="{'color': getTheme.color,'background-color': getTheme.background_o}">¥{{item.coupon_info.sub_price}} 满{{item.coupon_info.min_price == 0 ? '任意金额': '¥'+item.coupon_info.min_price}}可用</div>
  45. <div class="card-num" :style="{'color': getTheme.color}">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'" :style="{'color': getTheme.color}">{{item.integral_num}}</view>
  58. <view v-if="item.type == 'balance'" :style="{'color': getTheme.color}">¥{{item.balance}}</view>
  59. <view v-if="item.type == 'svip'" :style="{'color': getTheme.color}">{{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)" :style="{'background-color': getTheme.background}" 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 && item.user_coupon_id.length > 0) || (item.user_card_id && item.user_card_id.length > 0)" @click="toDetail(item)" :style="{'color': getTheme.color, 'border-color': getTheme.border}" 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" :style="{'background-color': getTheme.background}">立即兑换</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" :style="{'background-color': getTheme.background}" 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. r_raffled_at: '',
  102. list: [],
  103. mode: 0,
  104. exchange: 0,
  105. token: ''
  106. };
  107. },
  108. components:{
  109. 'app-radio': appRadio,
  110. uMask,
  111. 'app-iphone-x': appIphoneX,
  112. },
  113. onLoad(options) { this.$commonLoad.onload(options);
  114. let that = this;
  115. that.code = options.code;
  116. that.exchange = options.exchange == 1 ? 1 : 0;
  117. that.$showLoading({
  118. type: 'global',
  119. text: '加载中...'
  120. });
  121. that.getList();
  122. },
  123. onShow() {
  124. if(this.exchange == 1 && !this.first) {
  125. this.getList()
  126. }
  127. },
  128. computed: {
  129. ...mapGetters('mallConfig', {
  130. getTheme: 'getTheme',
  131. }),
  132. ...mapState({
  133. exchangeImg: state => state.mallConfig.__wxapp_img.exchange
  134. })
  135. },
  136. methods: {
  137. toDetail(item) {
  138. if(item.type == 'goods') {
  139. uni.navigateTo({
  140. 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}`
  141. });
  142. }else if(item.type == 'coupon') {
  143. uni.navigateTo({
  144. url: `/pages/coupon/details/details-no-share?person=1&id=${item.user_coupon_id[0]}`
  145. });
  146. }else if(item.type == 'card') {
  147. uni.navigateTo({
  148. url: `/pages/card/details/details?id=${item.user_card_id[0]}`
  149. });
  150. }
  151. },
  152. goback() {
  153. this.dialog = false;
  154. uni.navigateBack();
  155. },
  156. apply(item) {
  157. let that = this;
  158. uni.showLoading({
  159. mask: true,
  160. title: '领取中...'
  161. });
  162. if(item.type != 'goods') {
  163. that.$request({
  164. url: that.$api.exchange.covert,
  165. data: {
  166. code: this.code,
  167. token: item.token
  168. },
  169. method: 'post'
  170. }).then(response=>{
  171. uni.hideLoading();
  172. if(response.code == 0) {
  173. uni.showToast({
  174. title: response.msg,
  175. duration: 1000
  176. });
  177. this.getList();
  178. }else {
  179. uni.showToast({
  180. title: response.msg,
  181. icon: 'none',
  182. duration: 1000
  183. });
  184. }
  185. }).catch(response => {
  186. uni.hideLoading();
  187. });
  188. }else {
  189. let mch_list = [{
  190. mch_id: 0,
  191. goods_list: [{
  192. id: item.goods_id,
  193. attr: item.goods_info.attr_str,
  194. num: item.goods_num,
  195. cat_id: 0,
  196. goods_attr_id: item.attr_id
  197. }],
  198. code: this.code,
  199. token: item.token,
  200. }];
  201. let url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(mch_list)}`;
  202. url += `&preview_url=${encodeURIComponent(this.$api.exchange.exchange_preview)}&submit_url=${encodeURIComponent(this.$api.exchange.exchange_submit)}&plugin=exchange`;
  203. uni.navigateTo({
  204. url: url
  205. })
  206. }
  207. },
  208. toggle(e) {
  209. for(let item of this.list) {
  210. if(item.token == e.item.token) {
  211. item.active = e.active;
  212. this.token = e.item.token
  213. }else {
  214. item.active = false;
  215. }
  216. }
  217. this.$forceUpdate();
  218. },
  219. submit() {
  220. let that = this;
  221. if(that.mode == 1 && !that.token) {
  222. uni.showToast({
  223. title: '请选择想要兑换的礼品',
  224. icon: 'none',
  225. duration: 1000
  226. });
  227. return false
  228. }
  229. if(this.loading) {
  230. return false
  231. }
  232. this.loading = true;
  233. uni.showLoading({
  234. mask: true,
  235. title: '领取中...'
  236. });
  237. that.$request({
  238. url: that.$api.exchange.unite,
  239. data: {
  240. code: this.code,
  241. token: this.token
  242. },
  243. method: 'post'
  244. }).then(response=>{
  245. this.loading = false;
  246. uni.hideLoading();
  247. if(response.code == 0) {
  248. this.exchange = 1;
  249. this.mode = 0;
  250. this.getList();
  251. }else {
  252. uni.showToast({
  253. title: response.msg,
  254. icon: 'none',
  255. duration: 1000
  256. });
  257. }
  258. }).catch(response => {
  259. uni.hideLoading();
  260. });
  261. },
  262. getList() {
  263. let that = this;
  264. that.$request({
  265. url: that.exchange == 1 ? that.$api.exchange.log_detail : that.$api.exchange.info,
  266. data: {
  267. code: that.code
  268. }
  269. }).then(response=>{
  270. that.$hideLoading();
  271. uni.hideLoading();
  272. that.first = false;
  273. if(response.code == 0) {
  274. if(that.exchange == 0) {
  275. that.list = response.list.rewards;
  276. that.mode = response.list.mode;
  277. if(that.mode == 1) {
  278. for(let item of that.list) {
  279. item.active = false;
  280. }
  281. }
  282. }else {
  283. that.r_raffled_at = response.data.codeModel.r_raffled_at
  284. that.list = response.data.rewards;
  285. }
  286. }else {
  287. if(that.exchange == 0) {
  288. that.msg = response.msg;
  289. that.other = '';
  290. if(response.msg == '该兑换码未到使用时间!') {
  291. that.other = response.data.valid_start_time + '-' + response.data.valid_end_time + ' 可用'
  292. }
  293. that.dialog = true;
  294. }else {
  295. uni.showToast({
  296. title: response.msg,
  297. icon: 'none',
  298. duration: 1000
  299. });
  300. }
  301. }
  302. }).catch(response => {
  303. that.$hideLoading();
  304. uni.hideLoading();
  305. });
  306. }
  307. }
  308. }
  309. </script>
  310. <style scoped lang="scss">
  311. .dialog {
  312. margin: 270rpx auto;
  313. background-color: #fff;
  314. border-radius: 16rpx;
  315. width: 600rpx;
  316. padding: 60rpx 0;
  317. text-align: center;
  318. .dialog-img {
  319. width: 200rpx;
  320. height: 200rpx;
  321. margin: 0 auto 20rpx;
  322. }
  323. .dialog-msg {
  324. font-size: 32rpx;
  325. color: #353535;
  326. }
  327. .dialog-other {
  328. font-size: 24rpx;
  329. color: #999999;
  330. }
  331. .dialog-button {
  332. font-size: 26rpx;
  333. width: 520rpx;
  334. height: 90rpx;
  335. border-radius: 45rpx;
  336. line-height: 90rpx;
  337. text-align: center;
  338. color: #fff;
  339. margin: 50rpx auto 0;
  340. }
  341. }
  342. .code-info {
  343. width: 702rpx;
  344. height: 240rpx;
  345. border-radius: 16rpx;
  346. background-size: 100% 100%;
  347. margin: 24rpx;
  348. text-align: center;
  349. color: #fff;
  350. font-size: 24rpx;
  351. .code {
  352. margin-top: 50rpx;
  353. display: inline-block;
  354. font-size: 38rpx;
  355. text-align: center;
  356. padding: 24rpx 95rpx;
  357. border-radius: 60rpx;
  358. color: #fff;
  359. background-color: rgba(255,255,255,.2);
  360. margin-bottom: 20rpx;
  361. }
  362. }
  363. .rewards {
  364. background-color: #fff;
  365. border-radius: 16rpx;
  366. width: 702rpx;
  367. margin: 24rpx auto 0;
  368. .rewards-top {
  369. padding: 34rpx 40rpx;
  370. &.active-item {
  371. padding-left: 0;
  372. }
  373. .active {
  374. width: 88rpx;
  375. height: 140rpx;
  376. text-align: center;
  377. flex-shrink: 0;
  378. image {
  379. width: 32rpx;
  380. height: 32rpx;
  381. margin-top: 54rpx;
  382. border-radius: 16rpx;
  383. }
  384. &.small {
  385. height: 36rpx;
  386. image {
  387. margin-top: 2rpx;
  388. }
  389. }
  390. }
  391. .goods-num {
  392. font-size: 28rpx;
  393. }
  394. .balance {
  395. width: 100%;
  396. .balance-info {
  397. width: 100%;
  398. image {
  399. width: 30rpx;
  400. height: 30rpx;
  401. margin-right: 14rpx;
  402. }
  403. .balance-name {
  404. font-size: 28rpx;
  405. color: #353535;
  406. }
  407. }
  408. }
  409. .card {
  410. width: 100%;
  411. &.goods {
  412. .card-info {
  413. .card-name {
  414. margin-top: 0;
  415. margin-bottom: 10rpx;
  416. }
  417. }
  418. }
  419. .card-img {
  420. height: 140rpx;
  421. width: 140rpx;
  422. border-radius: 8rpx;
  423. margin-right: 20rpx;
  424. flex-shrink: 0;
  425. }
  426. .card-info {
  427. width: 100%;
  428. image {
  429. width: 30rpx;
  430. height: 30rpx;
  431. margin-right: 14rpx;
  432. }
  433. .attr {
  434. font-size: 24rpx;
  435. color: #999;
  436. }
  437. .card-name {
  438. margin-top: -5rpx;
  439. font-size: 28rpx;
  440. color: #353535;
  441. margin-bottom: 30rpx;
  442. }
  443. .card-number {
  444. padding: 12rpx 20rpx;
  445. font-size: 24rpx;
  446. border-radius: 30rpx;
  447. }
  448. .card-num {
  449. font-size: 28rpx;
  450. }
  451. }
  452. }
  453. }
  454. .rewards-bottom {
  455. border-top: #{2rpx} solid #e2e2e2;
  456. height: #{118rpx};
  457. width: 100%;
  458. padding: 0 #{30rpx};
  459. .rewards-submit {
  460. height: #{68rpx};
  461. line-height: #{68rpx};
  462. text-align: center;
  463. padding: 0 #{30rpx};
  464. border-radius: #{40rpx};
  465. color: #fff;
  466. font-size: #{28rpx};
  467. &.over {
  468. background-color: #f7f7f7;
  469. color: #999999;
  470. }
  471. }
  472. .rewards-detail {
  473. height: #{68rpx};
  474. line-height: #{68rpx};
  475. text-align: center;
  476. padding: 0 #{30rpx};
  477. border-radius: #{40rpx};
  478. background-color: #fff;
  479. font-size: #{28rpx};
  480. border: #{2rpx} solid;
  481. margin-right: #{18rpx};
  482. }
  483. }
  484. }
  485. .placeholder {
  486. height: #{178rpx};
  487. width: 100%;
  488. }
  489. .apply {
  490. position: fixed;
  491. bottom: 0;
  492. left: 0;
  493. z-index: 2;
  494. height: #{154rpx};
  495. width: 100%;
  496. background-color: #fff;
  497. padding-top: #{26rpx};
  498. padding-left: #{24rpx};
  499. .apply-btn {
  500. width: #{702rpx};
  501. height: #{88rpx};
  502. line-height: #{88rpx};
  503. border-radius: #{44rpx};
  504. text-align: center;
  505. color: #fff;
  506. font-size: #{32rpx};
  507. }
  508. }
  509. </style>