app-exclusive-coupon.vue 12 KB

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