freight.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 class="freight-bean" v-if="isBeansShow">
  16. <view class="bean-le" v-if="postageFlag == 1">可用{{ deductionBeans }}采美豆抵用{{ freightMoney }}元运费</view>
  17. <view class="bean-le" v-if="postageFlag == -1">可用{{ deductionBeans }}采美豆抵用{{ freightMoney }}运费</view>
  18. <view class="bean-ri">
  19. <view class="checkbox-box">
  20. <button class="checkbox iconfont"
  21. hover-class="btn-hover"
  22. @click.stop="checkedBalabce"
  23. :class="[ischecked ?'icon-yixuanze':'icon-weixuanze']"
  24. >
  25. </button>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default{
  34. name:'freight',
  35. props:{
  36. freightData:{
  37. type:Object
  38. }
  39. },
  40. data() {
  41. return{
  42. infoData:{},
  43. freightText:'',
  44. freightMoney:'',
  45. isShowOption:false,
  46. optionList:['到付'],
  47. postageFlag:0,
  48. ischecked:false,
  49. isBeansShow:false,
  50. userBeans:0,
  51. deductionBeans:0,
  52. freightBeansMoney:0,
  53. vipFlag:0
  54. }
  55. },
  56. created(){
  57. this.initData(this.freightData)
  58. },
  59. computed: {
  60. },
  61. methods:{
  62. async initData(res) {
  63. const userInfo = await this.$api.getStorage()
  64. this.vipFlag = userInfo.vipFlag ? userInfo.vipFlag : 0
  65. this.infoData = res
  66. switch(res.postageFlag){
  67. case 0:
  68. this.freightText = '包邮'
  69. this.freightData.freight = 0
  70. this.postageFlag = res.postageFlag
  71. this.isBeansShow = false
  72. break
  73. case 1:
  74. this.freightText = ''
  75. this.freightMoney = this.freightBeansMoney = res.postage
  76. this.userBeans = res.userBeans
  77. this.postageFlag = res.postageFlag
  78. this.optionList.unshift(this.orderPriceToFixed(this.freightMoney))
  79. if( res.userBeans > 0 ){
  80. this.isBeansShow = true
  81. }else{
  82. this.isBeansShow = false
  83. }
  84. if(res.userBeans >= this.freightBeansMoney*100){
  85. this.deductionBeans = this.freightBeansMoney*100
  86. }else{
  87. this.deductionBeans = res.userBeans
  88. }
  89. break
  90. case -1:
  91. this.freightText = '到付'
  92. this.freightMoney = '到付'
  93. this.userBeans = res.userBeans
  94. this.postageFlag = res.postageFlag
  95. this.freightData.freight = 0
  96. this.freightBeansMoney = 30
  97. if( res.userBeans >0 ){
  98. this.isBeansShow = true
  99. }else{
  100. this.isBeansShow = false
  101. }
  102. if(res.userBeans >= this.freightBeansMoney*100){
  103. this.deductionBeans = this.freightBeansMoney*100
  104. }else{
  105. this.deductionBeans = res.userBeans
  106. }
  107. break
  108. }
  109. },
  110. selectFreight (){//切换运费
  111. if(this.vipFlag==1){ return }
  112. let self = this
  113. uni.showActionSheet({
  114. itemList: self.optionList,
  115. success: function (res) {
  116. switch(res.tapIndex){
  117. case 0:
  118. self.freightMoney = self.infoData.postage
  119. self.postageFlag = 1
  120. if( self.userBeans > 0 ){
  121. self.isBeansShow = true
  122. self.freightBeansMoney = self.freightMoney
  123. if(self.userBeans >= self.freightBeansMoney*100){
  124. self.deductionBeans = self.freightBeansMoney*100
  125. }else{
  126. self.deductionBeans = self.userBeans
  127. }
  128. }else{
  129. self.isBeansShow = false
  130. self.freightBeansMoney = 0
  131. }
  132. break
  133. case 1:
  134. self.postageFlag = -1
  135. self.freightMoney = '到付'
  136. if( self.userBeans > 0 ){
  137. self.freightBeansMoney = 30
  138. self.isBeansShow = true
  139. if(self.userBeans >= self.freightBeansMoney*100){
  140. self.deductionBeans = self.freightBeansMoney*100
  141. }else{
  142. self.deductionBeans = self.userBeans
  143. }
  144. }else{
  145. self.freightBeansMoney = 0
  146. self.isBeansShow = false
  147. }
  148. break
  149. }
  150. let obj = {
  151. postageFlag :self.postageFlag,
  152. freightBeansMoney: self.freightBeansMoney
  153. }
  154. self.$emit('confirmFreight',obj)
  155. },
  156. fail: function (res) {
  157. console.log(res.errMsg)
  158. }
  159. })
  160. },
  161. checkedBalabce(){//勾选使用采美豆抵扣
  162. this.ischecked = !this.ischecked
  163. this.$emit('confirmFreightBeans',this.ischecked)
  164. },
  165. orderPriceToFixed (value){
  166. let price =''
  167. if(value == '到付'){
  168. price = value
  169. }else{
  170. price ='¥'+parseInt(value).toFixed(2)
  171. }
  172. return price
  173. },
  174. discard(){
  175. this.isShowOption = false
  176. this.selectClass = ''
  177. },
  178. showTip(){
  179. this.$emit('showFreightAlert')
  180. },
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. .freight-template{
  186. width: 100%;
  187. height: auto;
  188. background: #FFFFFF;
  189. float: left;
  190. margin-top: 24rpx;
  191. .invoice-freight{
  192. width: 100%;
  193. box-sizing: border-box;
  194. padding: 10rpx 24rpx;
  195. .freight-main{
  196. width: 100%;
  197. height: 78rpx;
  198. line-height: 78rpx;
  199. font-size: $font-size-28;
  200. color: $text-color;
  201. background: #FFFFFF;
  202. float: left;
  203. font-weight: bold;
  204. .freight-left{
  205. float: left;
  206. .tips{
  207. font-size: $font-size-24;
  208. color: $color-system;
  209. font-weight: normal;
  210. margin-left: 20rpx;
  211. }
  212. .icon-yunfeishuoming{
  213. height: 100%;
  214. padding:15rpx;
  215. color: $color-system;
  216. font-weight: normal;
  217. }
  218. }
  219. .freight-right{
  220. float: right;
  221. color: #2A81FF;
  222. position: relative;
  223. .freight-text{
  224. float: left;
  225. }
  226. .select{
  227. float: right;
  228. height: 60rpx;
  229. padding: 0 20rpx;
  230. margin-top: 14rpx;
  231. line-height: 60rpx;
  232. color: #2A81FF;
  233. font-weight: normal;
  234. position: relative;
  235. .select-text{
  236. display: inline-block;
  237. float: left;
  238. margin-right: 30rpx;
  239. }
  240. .iconfont{
  241. width: 60rpx;
  242. height: 60rpx;
  243. line-height: 60rpx;
  244. text-align: right;
  245. position: absolute;
  246. right: 0;
  247. top: 0;
  248. font-size: $font-size-28;
  249. color: #2A81FF;
  250. }
  251. }
  252. }
  253. }
  254. .freight-bean{
  255. width: 100%;
  256. height: 58rpx;
  257. line-height: 58rpx;
  258. float: left;
  259. .bean-le{
  260. float: left;
  261. color: #666666;
  262. font-size: $font-size-26;
  263. font-weight: normal;
  264. }
  265. .bean-ri{
  266. float: right;
  267. display: flex;
  268. align-items: center;
  269. .checkbox-box{
  270. display: flex;
  271. width: 60rpx;
  272. float: left;
  273. height: 100%;
  274. font-size: $font-size-26;
  275. margin-top: 8rpx;
  276. .checkbox{
  277. width: 40rpx;
  278. text-align: right;
  279. box-sizing: border-box;
  280. text-align: center;
  281. text-decoration: none;
  282. border-radius: 0;
  283. -webkit-tap-highlight-color: transparent;
  284. overflow: hidden;
  285. color: $color-system;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. }
  292. </style>