freight.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template name="freight">
  2. <view class="freight-template" @click.stop="discard">
  3. <!-- 运费信息 -->
  4. <view class="invoice-freight">
  5. <view class="freight-main">
  6. <view class="freight-left">运费<text class="tips" v-if="freightData.postageFlag == 1 && vipFlag!=1">运费可选择到付哟~</text></view>
  7. <view class="freight-right" >
  8. <view class="freight-text">{{freightText}}</view>
  9. <view class="select" v-if="freightData.postageFlag == 1" @click.stop="selectFreight">
  10. <text class="select-text">{{orderPriceToFixed(freightMoney)}}</text>
  11. <text class="iconfont icon-xiangyou"></text>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default{
  20. name:'freight',
  21. props:{
  22. freightData:{
  23. type:Object
  24. }
  25. },
  26. data() {
  27. return{
  28. infoData:{},
  29. freightText:'',
  30. freightMoney:'',
  31. isShowOption:false,
  32. optionList:['到付'],
  33. postageFlag:0,
  34. ischecked:false,
  35. isBeansShow:false,
  36. userBeans:0,
  37. deductionBeans:0,
  38. freightBeansMoney:0,
  39. vipFlag:0
  40. }
  41. },
  42. created(){
  43. this.initData(this.freightData)
  44. },
  45. computed: {
  46. },
  47. methods:{
  48. async initData(res) {
  49. const userInfo = await this.$api.getStorage()
  50. this.vipFlag = userInfo.vipFlag ? userInfo.vipFlag : 0
  51. this.infoData = res
  52. switch(res.postageFlag){
  53. case 0:
  54. this.freightText = '包邮'
  55. this.freightData.freight = 0
  56. this.postageFlag = res.postageFlag
  57. this.isBeansShow = false
  58. break
  59. case 1:
  60. this.freightText = ''
  61. this.freightMoney = this.freightBeansMoney = res.postage
  62. this.userBeans = res.userBeans
  63. this.postageFlag = res.postageFlag
  64. this.optionList.unshift(this.orderPriceToFixed(this.freightMoney))
  65. if( res.userBeans > 0 ){
  66. this.isBeansShow = true
  67. }else{
  68. this.isBeansShow = false
  69. }
  70. if(res.userBeans >= this.freightBeansMoney*100){
  71. this.deductionBeans = this.freightBeansMoney*100
  72. }else{
  73. this.deductionBeans = res.userBeans
  74. }
  75. break
  76. case -1:
  77. this.freightText = '到付'
  78. this.freightMoney = '到付'
  79. this.userBeans = res.userBeans
  80. this.postageFlag = res.postageFlag
  81. this.freightData.freight = 0
  82. this.freightBeansMoney = 30
  83. if( res.userBeans >0 ){
  84. this.isBeansShow = true
  85. }else{
  86. this.isBeansShow = false
  87. }
  88. if(res.userBeans >= this.freightBeansMoney*100){
  89. this.deductionBeans = this.freightBeansMoney*100
  90. }else{
  91. this.deductionBeans = res.userBeans
  92. }
  93. break
  94. }
  95. },
  96. selectFreight (){//切换运费
  97. if(this.vipFlag==1){ return }
  98. let self = this
  99. uni.showActionSheet({
  100. itemList: self.optionList,
  101. success: function (res) {
  102. switch(res.tapIndex){
  103. case 0:
  104. self.freightMoney = self.infoData.postage
  105. self.postageFlag = 1
  106. if( self.userBeans > 0 ){
  107. self.isBeansShow = true
  108. self.freightBeansMoney = self.freightMoney
  109. if(self.userBeans >= self.freightBeansMoney*100){
  110. self.deductionBeans = self.freightBeansMoney*100
  111. }else{
  112. self.deductionBeans = self.userBeans
  113. }
  114. }else{
  115. self.isBeansShow = false
  116. self.freightBeansMoney = 0
  117. }
  118. break
  119. case 1:
  120. self.postageFlag = -1
  121. self.freightMoney = '到付'
  122. if( self.userBeans > 0 ){
  123. self.freightBeansMoney = 30
  124. self.isBeansShow = true
  125. if(self.userBeans >= self.freightBeansMoney*100){
  126. self.deductionBeans = self.freightBeansMoney*100
  127. }else{
  128. self.deductionBeans = self.userBeans
  129. }
  130. }else{
  131. self.freightBeansMoney = 0
  132. self.isBeansShow = false
  133. }
  134. break
  135. }
  136. let obj = {
  137. postageFlag :self.postageFlag,
  138. freightBeansMoney: self.freightBeansMoney
  139. }
  140. self.$emit('confirmFreight',obj)
  141. },
  142. fail: function (res) {
  143. console.log(res.errMsg)
  144. }
  145. })
  146. },
  147. orderPriceToFixed (value){
  148. let price =''
  149. if(value == '到付'){
  150. price = value
  151. }else{
  152. price ='¥'+parseInt(value).toFixed(2)
  153. }
  154. return price
  155. },
  156. discard(){
  157. this.isShowOption = false
  158. this.selectClass = ''
  159. },
  160. showTip(){
  161. this.$emit('showFreightAlert')
  162. },
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. .freight-template{
  168. width: 100%;
  169. height: auto;
  170. background: #FFFFFF;
  171. float: left;
  172. margin-top: 24rpx;
  173. .invoice-freight{
  174. width: 100%;
  175. box-sizing: border-box;
  176. padding: 10rpx 24rpx;
  177. .freight-main{
  178. width: 100%;
  179. height: 78rpx;
  180. line-height: 78rpx;
  181. font-size: $font-size-28;
  182. color: $text-color;
  183. background: #FFFFFF;
  184. float: left;
  185. font-weight: bold;
  186. .freight-left{
  187. float: left;
  188. .tips{
  189. font-size: $font-size-24;
  190. color: $color-system;
  191. font-weight: normal;
  192. margin-left: 20rpx;
  193. }
  194. .icon-yunfeishuoming{
  195. height: 100%;
  196. padding:15rpx;
  197. color: $color-system;
  198. font-weight: normal;
  199. }
  200. }
  201. .freight-right{
  202. float: right;
  203. color: #2A81FF;
  204. position: relative;
  205. .freight-text{
  206. float: left;
  207. }
  208. .select{
  209. float: right;
  210. height: 60rpx;
  211. padding: 0 20rpx;
  212. margin-top: 14rpx;
  213. line-height: 60rpx;
  214. color: #2A81FF;
  215. font-weight: normal;
  216. position: relative;
  217. .select-text{
  218. display: inline-block;
  219. float: left;
  220. margin-right: 30rpx;
  221. }
  222. .iconfont{
  223. width: 60rpx;
  224. height: 60rpx;
  225. line-height: 60rpx;
  226. text-align: right;
  227. position: absolute;
  228. right: 0;
  229. top: 0;
  230. font-size: $font-size-28;
  231. color: #2A81FF;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. </style>