freight-popup.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <view class="freight">
  3. <view class="freight-switch">
  4. <view class="freight-switch-title">运费</view>
  5. <view class="freight-switch-fee" v-if="postAgeFlag(0)"><text>包邮</text></view>
  6. <view class="freight-switch-fee" v-if="postAgeFlag(1)">
  7. <text>{{ freightText }}</text>
  8. <text
  9. class="cell-more iconfont icon-xiangyou"
  10. v-if="infoData.designatedFlag !== 1"
  11. @click="showPopup"
  12. ></text>
  13. </view>
  14. <view class="freight-switch-fee" v-if="postAgeFlag(2)"><text>到付</text></view>
  15. </view>
  16. <tui-bottom-popup :radius="true" :show="popupShow">
  17. <view class="freight-title">运费设置</view>
  18. <view class="freight-content">
  19. <radio-group @change="radioChange">
  20. <label v-for="(item, index) in radioItems" :key="index">
  21. <radio
  22. style="transform:scale(0.7)"
  23. color="#F3B574"
  24. :id="item.name"
  25. :value="item.name"
  26. :checked="item.checked"
  27. ></radio>
  28. <label :for="item.name" class="label">
  29. <text>{{ item.value }}</text>
  30. </label>
  31. </label>
  32. </radio-group>
  33. <view class="freight-form">
  34. <view class="freight-form-item" v-if="infoData.designatedFlag !== 2">
  35. <view>冷链运输费</view>
  36. <view style="position: relative;">
  37. ¥{{ this.infoData.coldChain.toFixed(2) }}
  38. <radio
  39. class="freight-pay"
  40. color="#F3B574"
  41. @click="coldChainChange"
  42. :checked="isCheck"
  43. ></radio>
  44. </view>
  45. </view>
  46. <block>
  47. <view class="freight-form-item" v-if="isCPay">
  48. <view>其他运费</view>
  49. <view>{{ '¥' + postAge().toFixed(2) }}</view>
  50. </view>
  51. <view class="freight-form-item" v-else>
  52. <view>其他运费</view>
  53. <view>到付</view>
  54. </view>
  55. </block>
  56. <view class="freight-form-item">
  57. <view>总运费</view>
  58. <view style="color: #F94B4B;display: flex;">
  59. <view class="" v-if="allPostage === 0">
  60. 到付
  61. </view>
  62. <view style="display: flex;" v-else>
  63. <count-up
  64. :num="allPostage.toFixed(2)"
  65. :width="16"
  66. :height="40"
  67. :fontSize="28"
  68. color="#F94B4B"
  69. ></count-up>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="freight-btn" @click="fetchPostAge">确定</view>
  75. </view>
  76. </tui-bottom-popup>
  77. </view>
  78. </template>
  79. <script>
  80. import CountUp from './countUp.vue'
  81. export default {
  82. props: {
  83. ispopupShow: {
  84. type: Boolean,
  85. default: () => false
  86. },
  87. goodsData: {
  88. type: Array,
  89. default: () => []
  90. },
  91. goodIndex: {
  92. type: Number
  93. }
  94. },
  95. components: {
  96. CountUp
  97. },
  98. data() {
  99. return {
  100. radioItems: [
  101. {
  102. value: '不包邮',
  103. name: '0',
  104. checked: true
  105. },
  106. {
  107. value: '到付',
  108. name: '1'
  109. }
  110. ],
  111. isCPay: true,
  112. isCheck: false,
  113. infoData: {},
  114. freightText: '',
  115. popupShow: false
  116. }
  117. },
  118. watch: {
  119. goodsData: {
  120. handler(val) {
  121. this.initData(val[0])
  122. },
  123. deep: true,
  124. immediate: true
  125. }
  126. },
  127. computed: {
  128. // 总运费
  129. allPostage() {
  130. console.log(111)
  131. this.freightText =
  132. this.postAge() + (this.isCheck ? this.infoData.coldChain : 0) === 0
  133. ? '到付'
  134. : '¥' + (this.postAge() + (this.isCheck ? this.infoData.coldChain : 0)).toFixed(2)
  135. return this.postAge() + (this.infoData.isColdChina ? this.infoData.coldChain : 0)
  136. },
  137. // 合计
  138. allPrice() {
  139. return Number(this.infoData.originalPrice) + Number(!this.isCPay ? 0 : this.allPostage)
  140. }
  141. },
  142. mounted() {
  143. },
  144. methods: {
  145. // 开启弹窗
  146. showPopup() {
  147. this.popupShow = true
  148. this.$emit('showFreight', true)
  149. },
  150. postAgeFlag(e) {
  151. return JSON.parse(uni.getStorageSync('goodsData'))[this.goodIndex].postageFlag === e
  152. },
  153. postAge() {
  154. if (this.isCPay) return JSON.parse(uni.getStorageSync('goodsData'))[this.goodIndex].postage
  155. else return 0
  156. },
  157. radioChange($event) {
  158. console.log('切换运费')
  159. this.isCPay = !this.isCPay
  160. this.infoData.isColdChina = this.isCheck
  161. this.infoData.postageFlag = this.isCPay ? 1 : 2
  162. },
  163. // 初始化运费组件
  164. initData(data) {
  165. this.infoData = JSON.parse(JSON.stringify(data))
  166. this.isCheck = this.infoData.isColdChina
  167. this.infoFreightText(data)
  168. },
  169. // 设置运费
  170. infoFreightText(data) {
  171. switch (data.postageFlag) {
  172. case 0:
  173. this.freightText = '包邮'
  174. this.infoData.postage = 0
  175. this.infoData.postageFlag = data.postageFlag
  176. break
  177. case 1:
  178. this.freightText = '¥' + (this.infoData.postage + this.infoData.coldChain)
  179. // this.infoData.postage = this.freightText
  180. this.infoData.postageFlag = data.postageFlag
  181. break
  182. case 2:
  183. this.freightText = '到付'
  184. this.infoData.postage = 0
  185. this.infoData.postageFlag = data.postageFlag
  186. break
  187. }
  188. },
  189. // 是否选择冷链费
  190. coldChainChange() {
  191. this.isCheck = !this.isCheck
  192. this.freightText = this.isCheck ? this.allPostage : this.infoData.postage
  193. this.infoData.isColdChina = this.isCheck
  194. },
  195. // 运费参数
  196. fetchPostAge() {
  197. this.$emit('changeFreight', [this.goodIndex, this.infoData, this.allPostage])
  198. this.popupShow = false
  199. this.$emit('showFreight', false)
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .freight {
  206. position: relative;
  207. }
  208. .freight-switch {
  209. display: flex;
  210. justify-content: space-between;
  211. align-items: center;
  212. width: 100%;
  213. box-sizing: border-box;
  214. background-color: white;
  215. padding: 24rpx 0;
  216. .freight-switch-title {
  217. color: #333333;
  218. font-size: 28rpx;
  219. font-weight: bold;
  220. }
  221. .freight-switch-fee {
  222. color: #333333;
  223. font-size: 28rpx;
  224. }
  225. }
  226. .all-price {
  227. display: flex;
  228. justify-content: space-between;
  229. align-items: center;
  230. flex-direction: row-reverse;
  231. width: 100%;
  232. padding-bottom: 24rpx;
  233. font-size: 28rpx;
  234. background-color: #ffffff;
  235. box-sizing: border-box;
  236. .all-price-content {
  237. display: flex;
  238. }
  239. .price {
  240. color: #f94b4b;
  241. }
  242. }
  243. .iconfont {
  244. font-size: 32rpx !important;
  245. margin-left: 15rpx;
  246. }
  247. .freight-title {
  248. color: #333333;
  249. font-size: 32rpx;
  250. text-align: center;
  251. margin: 50rpx 0 80rpx 0;
  252. }
  253. .freight-content {
  254. box-sizing: border-box;
  255. padding: 0 50rpx;
  256. radio {
  257. margin-right: 8rpx;
  258. }
  259. .label {
  260. color: #666666;
  261. font-size: 28rpx;
  262. margin-right: 102rpx;
  263. }
  264. .freight-btn {
  265. height: 90rpx;
  266. background: #f3b574;
  267. border-radius: 45rpx 45rpx 45rpx 45rpx;
  268. display: flex;
  269. justify-content: center;
  270. align-items: center;
  271. color: #ffffff;
  272. width: 100%;
  273. margin: 100rpx 0 0 0;
  274. }
  275. }
  276. .freight-form {
  277. margin-top: 50rpx;
  278. width: 100%;
  279. .freight-form-item {
  280. width: 95%;
  281. display: flex;
  282. justify-content: space-between;
  283. align-items: center;
  284. margin-bottom: 24rpx;
  285. color: #666666;
  286. font-size: 28rpx;
  287. }
  288. }
  289. .freight-pay {
  290. position: absolute;
  291. right: -60%;
  292. transform: scale(0.7);
  293. }
  294. </style>