freight-popup.vue 9.5 KB

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