app-exclusive-coupon.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <view class="app-exclusive-coupon" :style="{'background-color': `${noneColor ? '' : background}`}">
  3. <view class="app-top main-between" v-if="showTop" @click="route()">
  4. <view class="app-left main-between cross-center">
  5. <icon class="app-icon"></icon>
  6. <text class="app-title">专享优惠券</text>
  7. </view>
  8. <view class="app-right main-between cross-center">
  9. <text class="app-text">更多</text>
  10. <icon class="app-icon"></icon>
  11. </view>
  12. </view>
  13. <view class="app-bottom">
  14. <scroll-view scroll-x class="app-scroll dir-left-nowrap">
  15. <view v-for="(item, index) in coupon_list"
  16. :key="index"
  17. class="app-item"
  18. :style="{backgroundImage: `url(${item.is_receive == 0 ? unclaimedBg : item.is_receive == 1 ? receiveBg : ''})`}"
  19. >
  20. <view class="main-left" @click="receive(index)">
  21. <view class="app-text-left">
  22. <view class="app-text-top">
  23. <template v-if="item.type === '1'">
  24. <text class="app-number discount" :style="{color: textColor}">{{item.discount}}</text>
  25. </template>
  26. <template v-else>
  27. <text class="app-symbol" :style="{color: textColor}">¥</text>
  28. <text class="app-number" :style="{color: textColor}">{{item.sub_price}}</text>
  29. </template>
  30. </view>
  31. <text class="app-text-bottom" :style="{color: textColor}">满{{item.min_price}}元可用</text>
  32. </view>
  33. <view class="app-text-right">
  34. <text :style="{color: textColor}">{{item.is_receive == 0 ? receiveTip : item.is_receive > 0 ? '已领取' : ''}}</text>
  35. </view>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. name: 'app-exclusive-coupon',
  45. props: {
  46. receiveBg: {
  47. type: String,
  48. default: function() {
  49. return '';
  50. }
  51. },
  52. list: {
  53. type: Array,
  54. default: function() {
  55. return [];
  56. }
  57. },
  58. textColor: {
  59. type: String,
  60. default: function() {
  61. return "#ffffff";
  62. }
  63. },
  64. unclaimedBg: {
  65. type: String,
  66. default: function() {
  67. return ''
  68. }
  69. },
  70. index: {
  71. type: Number,
  72. },
  73. sign: {
  74. type: String,
  75. },
  76. showTop: {
  77. type: Boolean,
  78. default() {
  79. return true;
  80. }
  81. },
  82. noneColor: {
  83. type: Boolean,
  84. default() {
  85. return false;
  86. }
  87. },
  88. background: String,
  89. page_id: Number,
  90. is_required: Boolean,
  91. coupon_req: Boolean
  92. },
  93. data() {
  94. return {
  95. coupon_list: [],
  96. tempList: []
  97. };
  98. },
  99. computed: {
  100. receiveTip() {
  101. let receiveTip = '立即领取';
  102. if (this.sign === 'integral-mall') {
  103. receiveTip = '立即兑换';
  104. }
  105. return receiveTip;
  106. }
  107. },
  108. methods: {
  109. receive(index) {
  110. let list = this.coupon_list;
  111. if (this.sign === 'integral-mall') {
  112. this.$jump({
  113. url: list[index].page_url,
  114. open_type: 'navigate'
  115. });
  116. return ;
  117. }
  118. if (list[index].is_receive == 1) {
  119. uni.showToast({
  120. mask: true,
  121. title: '已领取',
  122. icon: 'none'
  123. });
  124. return true;
  125. }
  126. uni.showLoading({
  127. mask: true,
  128. title: '领取中'
  129. });
  130. this.$request({
  131. url: this.$api.coupon.receive,
  132. data: {
  133. coupon_id: list[index].id
  134. }
  135. }).then(e => {
  136. uni.hideLoading();
  137. if (e.code === 0) {
  138. if (e.data.rest == 0) {
  139. e.data.is_receive = 1;
  140. }
  141. this.coupon_list[index] = Object.assign(list[index], e.data);
  142. let storage = this.$storage.getStorageSync('INDEX_MALL');
  143. storage.home_pages[this.index].list = this.coupon_list;
  144. this.$storage.setStorageSync('INDEX_MALL', storage);
  145. this.$store.dispatch('page/actionSetCoupon', {
  146. list: [this.coupon_list[index]],
  147. type: 'receive'
  148. });
  149. } else {
  150. uni.showModal({
  151. title: '提示',
  152. content: e.msg,
  153. showCancel: false,
  154. });
  155. }
  156. }).catch(() => {
  157. uni.hideLoading();
  158. });
  159. },
  160. loadData() {
  161. this.$request({
  162. url: this.$api.index.extra,
  163. data: {
  164. type: 'mall',
  165. key: 'coupon',
  166. page_id: this.page_id,
  167. index: this.index
  168. }
  169. }).then(e => {
  170. this.coupon_list = e.data;
  171. // this.tempList = this.cloneData(e.data);
  172. // this.splitData();
  173. if (this.page_id === 0) {
  174. let storage = this.$storage.getStorageSync('INDEX_MALL');
  175. storage.home_pages[this.index].list = e.data;
  176. this.$storage.setStorageSync('INDEX_MALL', storage);
  177. }
  178. })
  179. },
  180. cloneData(data) {
  181. return JSON.parse(JSON.stringify(data));
  182. },
  183. splitData() {
  184. if (!this.tempList.length) return;
  185. let item = this.tempList[0];
  186. this.coupon_list.push(item);
  187. this.tempList.splice(0, 1);
  188. if (this.tempList.length) {
  189. setTimeout(() => {
  190. this.splitData();
  191. }, 300);
  192. }
  193. },
  194. route() {
  195. uni.navigateTo({
  196. url: '/pages/coupon/list/list'
  197. })
  198. }
  199. },
  200. mounted() {
  201. if (!this.coupon_req) {
  202. if (this.is_required) {
  203. this.loadData();
  204. } else {
  205. let storage = this.$storage.getStorageSync('INDEX_MALL');
  206. this.coupon_list = storage.home_pages[this.index].list;
  207. // this.tempList = this.cloneData(storage.home_pages[this.index].list);
  208. // this.splitData();
  209. }
  210. } else {
  211. this.coupon_list = this.list;
  212. // this.tempList = this.cloneData(this.list);
  213. // this.splitData();
  214. }
  215. },
  216. }
  217. </script>
  218. <style scoped lang="scss">
  219. .app-exclusive-coupon {
  220. width: #{750rpx};
  221. .app-top {
  222. width: #{750rpx};
  223. height: #{80rpx};
  224. border-bottom: #{1rpx} solid #e2e2e2;
  225. .app-icon {
  226. background-repeat: no-repeat;
  227. background-size: 100% 100%;
  228. }
  229. .app-left {
  230. width: #{215rpx};
  231. height: #{80rpx};
  232. margin-left: #{24rpx};
  233. .app-icon {
  234. width: #{46rpx};
  235. height: #{46rpx};
  236. background-image: url("../../../static/image/icon/coupon-icon.png");
  237. }
  238. .app-title {
  239. font-size: #{28rpx};
  240. color: #ff8831;
  241. }
  242. }
  243. .app-right {
  244. height: #{80rpx};
  245. width: #{75rpx};
  246. margin-right: #{24rpx};
  247. .app-icon {
  248. width: #{12rpx};
  249. height: #{22rpx};
  250. background-image: url("../../../static/image/icon/arrow-right.png");
  251. }
  252. .app-text {
  253. font-size: #{26rpx};
  254. color: #999999;
  255. }
  256. }
  257. }
  258. .app-bottom {
  259. padding-top: #{16rpx};
  260. padding-left: #{8rpx};
  261. padding-bottom: #{16rpx};
  262. height: #{162rpx};
  263. width: #{750rpx};
  264. .app-scroll {
  265. height: #{162rpx};
  266. width: #{750-24rpx};
  267. white-space: nowrap;
  268. }
  269. .app-item {
  270. width: #{256rpx};
  271. height: #{130rpx};
  272. display: inline-block;
  273. margin-left: #{16rpx};
  274. background-repeat: no-repeat;
  275. background-size: 100% 100%;
  276. >view {
  277. width: #{256rpx};
  278. height: #{130rpx};
  279. }
  280. .app-text-left {
  281. width: #{199rpx};
  282. height: #{130rpx};
  283. .app-text-top {
  284. height: #{78rpx};
  285. padding-top: #{1rpx};
  286. overflow: hidden;
  287. text-align: center;
  288. .app-symbol {
  289. display: inline-block;
  290. height: #{78rpx};
  291. font-size: #{20rpx};
  292. }
  293. .app-number {
  294. display: inline-block;
  295. height: #{78rpx};
  296. padding-top: #{26rpx};
  297. font-size: #{40rpx};
  298. }
  299. .discount:after {
  300. content: '折';
  301. font-size: 75%;
  302. }
  303. }
  304. .app-text-bottom {
  305. height: #{50rpx};
  306. width: #{199rpx};
  307. text-align: center;
  308. font-size: #{20rpx};
  309. display: inline-block;
  310. }
  311. }
  312. .app-text-right {
  313. width: #{50rpx};
  314. height: #{130rpx};
  315. text {
  316. height: #{130rpx};
  317. width: #{50rpx};
  318. display: inline-block;
  319. text-align: center;
  320. line-height: #{50rpx};
  321. font-size: #{20rpx};
  322. margin-left: #{2rpx};
  323. writing-mode: vertical-rl;
  324. letter-spacing: #{5rpx};
  325. }
  326. }
  327. }
  328. }
  329. }
  330. </style>