app-coupon-sel.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <div class="coupon-sel">
  3. <block v-if="!$util.isEmpty(shopUser)">
  4. <radio-group class="radio-group" name="coupon" @change="checkChange">
  5. <!-- 会员优惠 -->
  6. <div class="sel-list flex-center-between" v-if="discountArr.indexOf('member') > -1">
  7. <div class="sel-tit">
  8. <radio value="1" :checked="memberCheck">
  9. <span class="dis-pormpt">您是{{ shopUser.userAsset.member }}级会员,享{{ shopUser.userAsset.discount }}折优惠</span>
  10. </radio>
  11. </div>
  12. <!-- <div class="app-price app-size-28">-¥{{ totalDiscountPrice }}</div> -->
  13. <div class="app-price app-size-28"></div>
  14. </div>
  15. <!-- 优惠券优惠 -->
  16. <div class="sel-list" v-if="discountArr.indexOf('coupon') > -1">
  17. <div class="sel-tit">
  18. <radio value="2" >
  19. <span class="dis-pormpt">有优惠券可用,请选择</span>
  20. </radio>
  21. </div>
  22. <div class="coupon-wrap" v-show="selIndex == 2">
  23. <div class="coupon-list" v-for="(item, index) in data.coupon" :key="index" @click="couponChange(item, index + 1)">
  24. <div class="list-img">
  25. <!-- 已过期 -->
  26. <template v-if="couponSelInx && couponSelInx == (index + 1)">
  27. <img :src="`${constant.imgUrl}/retail/coupon/is-check.png`" alt mode="widthFix" />
  28. </template>
  29. <template v-else>
  30. <img :src="`${constant.imgUrl}/retail/coupon/no-check.png`" alt mode="widthFix" />
  31. </template>
  32. </div>
  33. <!-- 列表 -->
  34. <div class="list-det">
  35. <div class="list-det-left">
  36. <div class="price-wrap">
  37. <span>¥</span>
  38. <span class="price">{{ item.amount }}</span>
  39. </div>
  40. <div class="full-reduc app-size-28">满{{ item.miniCost }}可使用</div>
  41. </div>
  42. <div class="list-det-right">
  43. <div class="coupon-message">
  44. <div class="app-color-2">优惠券</div>
  45. <div>适用:全品类</div>
  46. <div>有效至:2020-10-11</div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </radio-group>
  54. </block>
  55. </div>
  56. </template>
  57. <script>
  58. import { mapGetters } from 'vuex'
  59. // api
  60. import { userDiscount } from '@/api/member'
  61. import { getShopUser } from '@/utils/auth'
  62. export default {
  63. name: 'coupon-sel',
  64. props: {
  65. // 可使用优惠列表
  66. // discountArr: {
  67. // type: Array,
  68. // default: () => []
  69. // }
  70. // 金额
  71. price: {
  72. type: [String, Number],
  73. default: 0
  74. }
  75. },
  76. data() {
  77. return {
  78. constant: this.$constant,
  79. memberCheck: false,
  80. selIndex: null,
  81. couponSelInx: null,
  82. couponId: 0,
  83. data: {}
  84. }
  85. },
  86. computed: {
  87. ...mapGetters({ shopUser: 'getShopUser' }),
  88. // 可使用优惠列表
  89. discountArr() {
  90. let newArr = []
  91. if (this.$util.isEmpty(this.data)) return newArr
  92. if (!this.$util.isEmpty(this.data.member)) {
  93. newArr.push('member')
  94. this.selIndex = 1
  95. this.memberCheck = true
  96. }
  97. if (!this.$util.isEmpty(this.data.coupon)) {
  98. newArr.push('coupon')
  99. }
  100. return newArr
  101. },
  102. // 优惠金额
  103. totalDiscountPrice() {
  104. console.log(this.price)
  105. if (this.price) {
  106. // console.log(this.$util.floatFormat((this.price - this.price * this.shopUser.userAsset.discount / 10), 1))
  107. // return this.$util.floatFormat((this.price - this.price * this.shopUser.userAsset.discount / 10), 1)
  108. return ((this.price * 1000000) - (this.price * this.shopUser.userAsset.discount / 10) * 1000000) / 1000000
  109. } else {
  110. return 0
  111. }
  112. }
  113. },
  114. mounted() {
  115. // this.init()
  116. // getShopUser()
  117. // if (this.discountArr.indexOf('member') > -1) {
  118. // this.selIndex = 1
  119. // this.memberCheck = true
  120. // }
  121. },
  122. methods: {
  123. mInit() {
  124. // this._getUserDiscount()
  125. },
  126. async _getUserDiscount() {
  127. let arr = []
  128. await userDiscount().then(res => {
  129. this.data = res.data
  130. console.log('1111111')
  131. arr = this.discountArr
  132. })
  133. console.log('222222')
  134. return arr
  135. },
  136. checkChange(e) {
  137. this.selIndex = e.detail.value
  138. if (this.selIndex == 1) {
  139. this.couponId = 0
  140. }
  141. this.$emit('checkChange')
  142. },
  143. // 优惠券选择
  144. couponChange(item, index) {
  145. this.couponSelInx = this.couponSelInx == index ? null : index
  146. this.couponId = item.id
  147. this.$emit('couponChange')
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. .sel-list {
  154. .sel-tit {
  155. @include disFlex(center, flex-start);
  156. margin-top: 30px;
  157. .dis-pormpt {
  158. font-size: 28px;
  159. color: $fontColor2;
  160. margin-left: 6px;
  161. }
  162. }
  163. &:first-child .sel-tit {
  164. margin-top: 0;
  165. }
  166. }
  167. // 优惠券
  168. .coupon-wrap {
  169. padding-top: 20px;
  170. .coupon-list {
  171. position: relative;
  172. margin-bottom: 6px;
  173. .list-det {
  174. width: 100%;
  175. @include disFlex(center, space-between);
  176. position: absolute;
  177. top: 0;
  178. left: 0;
  179. .list-det-left {
  180. padding: 20px 0 20px 36px;
  181. width: 210px;
  182. color: $mainColor;
  183. .price-wrap {
  184. margin-bottom: 6px;
  185. font-size: 26px;
  186. .price {
  187. font-size: 60px;
  188. font-weight: bold;
  189. line-height: 1;
  190. }
  191. }
  192. }
  193. .list-det-right {
  194. width: calc(100% - 280px);
  195. margin-left: 22px;
  196. @include disFlex(center, space-between);
  197. padding: 20px 26px 20px 0;
  198. .coupon-message {
  199. color: $fontColor3;
  200. & > div {
  201. margin: 6px 0;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. // 修改uni-app组件
  209. /deep/.uni-radio-input-checked {
  210. background-color: $mainColor !important;
  211. border-color: $mainColor !important;
  212. }
  213. </style>