cm-freight-popup.vue 6.9 KB

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