freight-cell.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="freight">
  3. <van-cell title="运费信息" :value="text" @click="showFreight = true" is-link/>
  4. <van-popup
  5. v-model="showFreight"
  6. round
  7. position="bottom"
  8. :close="onClose"
  9. >
  10. <div class="content">
  11. <div class="title">运费设置</div>
  12. <div class="check">
  13. <van-radio-group v-model="radio">
  14. <van-radio :name="item.id" v-for="item in checkList" :key="item.id">{{ item.name }}</van-radio>
  15. </van-radio-group>
  16. </div>
  17. <van-field class="setFreight" v-if="radio === 1" v-model="number" type="number" placeholder="设置运费" />
  18. <van-button @click="confirm" color="#FF5B00">确定</van-button>
  19. </div>
  20. </van-popup>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. props: {
  26. goodInfo: {
  27. type: Object,
  28. default: () => ({})
  29. }
  30. },
  31. data () {
  32. return {
  33. showFreight: false,
  34. radio: 0,
  35. number: 0,
  36. productInfo: JSON.parse(sessionStorage.getItem('productInfo'))
  37. }
  38. },
  39. watch: {
  40. goodInfo: {
  41. handler (val) {
  42. this.radio = val.postageFlag
  43. },
  44. deep: true
  45. }
  46. },
  47. computed: {
  48. checkList () {
  49. return [
  50. {
  51. id: 0,
  52. name: '包邮'
  53. }, {
  54. id: 1,
  55. name: '不包邮'
  56. }, {
  57. id: 2,
  58. name: '到付'
  59. }
  60. ]
  61. },
  62. postageFlag () {
  63. return this.radio
  64. },
  65. postage () {
  66. if (this.radio === 1) return Number(this.number).toFixed(2)
  67. else return Number(this.productInfo.postage) + Number(this.productInfo.coldChain)
  68. },
  69. text () {
  70. if (this.radio === 0) {
  71. return '包邮'
  72. } else if (this.radio === 1) {
  73. return '¥' + this.postage
  74. } else return '到付'
  75. }
  76. },
  77. methods: {
  78. onClose () {
  79. this.showFreight = false
  80. },
  81. confirm () {
  82. const info = JSON.parse(sessionStorage.getItem('productInfo'))
  83. info.postage = this.postage
  84. info.postageFlag = this.postageFlag
  85. info.totalPrice = Number(info.totalPrice) + Number(this.postage)
  86. this.$emit('handlerFreight', info)
  87. this.showFreight = false
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .content {
  94. display: flex;
  95. flex-direction: column;
  96. align-items: center;
  97. }
  98. .title {
  99. width: 100%;
  100. text-align: center;
  101. height: 10vw;
  102. line-height: 10vw;
  103. font-size: 4vw;
  104. font-weight: 600;
  105. }
  106. .check {
  107. display: flex;
  108. justify-content: center;
  109. align-items: center;
  110. margin: 4vw 0;
  111. ::v-deep .van-radio-group {
  112. display: flex;
  113. width: 90vw;
  114. justify-content: space-between;
  115. font-size: 3.6vw;
  116. .van-radio {
  117. overflow: initial !important;
  118. }
  119. .van-icon {
  120. position: relative;
  121. width: 5vw;
  122. height: 5vw;
  123. }
  124. .van-radio__icon--checked .van-icon {
  125. background: #fff;
  126. border-color: #FF5B00;
  127. &::before {
  128. content: '';
  129. display: absolute;
  130. left: 0;
  131. top: 0;
  132. background: #FF5B00;
  133. width: 2vw;
  134. height: 2vw;
  135. transform: translate(5%, -40%);
  136. border-radius: 50%;
  137. }
  138. }
  139. }
  140. }
  141. .setFreight {
  142. box-sizing: border-box;
  143. border: 1px solid #ccc;
  144. width: 90vw;
  145. padding: 0 10px;
  146. margin-bottom: 4vw;
  147. }
  148. .van-button {
  149. width: 80vw;
  150. height: 12vw;
  151. font-size: 4vw;
  152. margin-bottom: 4vw;
  153. border-radius: 1.2vw;
  154. }
  155. </style>