freight.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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-xiayibu"></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. let self = this,value
  112. uni.showActionSheet({
  113. itemList: self.optionList,
  114. success: function (res) {
  115. switch(res.tapIndex){
  116. case 0:
  117. self.freightMoney = self.infoData.postage
  118. self.postageFlag = 1
  119. if( self.userBeans > 0 ){
  120. self.isBeansShow = true
  121. self.freightBeansMoney = self.freightMoney
  122. if(self.userBeans >= self.freightBeansMoney*100){
  123. self.deductionBeans = self.freightBeansMoney*100
  124. }else{
  125. self.deductionBeans = self.userBeans
  126. }
  127. }else{
  128. self.isBeansShow = false
  129. self.freightBeansMoney = 0
  130. }
  131. break
  132. case 1:
  133. self.postageFlag = -1
  134. self.freightMoney = '到付'
  135. if( self.userBeans > 0 ){
  136. self.freightBeansMoney = 30
  137. self.isBeansShow = true
  138. if(self.userBeans >= self.freightBeansMoney*100){
  139. self.deductionBeans = self.freightBeansMoney*100
  140. }else{
  141. self.deductionBeans = self.userBeans
  142. }
  143. }else{
  144. self.freightBeansMoney = 0
  145. self.isBeansShow = false
  146. }
  147. break
  148. }
  149. let obj = {
  150. postageFlag :self.postageFlag,
  151. freightBeansMoney: self.freightBeansMoney
  152. }
  153. self.$emit('confirmFreight',obj)
  154. },
  155. fail: function (res) {
  156. console.log(res.errMsg)
  157. }
  158. })
  159. },
  160. checkedBalabce(){//勾选使用采美豆抵扣
  161. this.ischecked = !this.ischecked
  162. this.$emit('confirmFreightBeans',this.ischecked)
  163. },
  164. orderPriceToFixed (value){
  165. let price =''
  166. if(value == '到付'){
  167. price = value
  168. }else{
  169. price ='¥'+parseInt(value).toFixed(2)
  170. }
  171. return price
  172. },
  173. discard(){
  174. this.isShowOption = false
  175. this.selectClass = ''
  176. },
  177. showTip(){
  178. this.$emit('showFreightAlert')
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. .freight-template{
  185. width: 100%;
  186. height: auto;
  187. background: #FFFFFF;
  188. float: left;
  189. margin-top: 24rpx;
  190. .invoice-freight{
  191. width: 100%;
  192. box-sizing: border-box;
  193. padding: 10rpx 24rpx;
  194. .freight-main{
  195. width: 100%;
  196. height: 78rpx;
  197. line-height: 78rpx;
  198. font-size: $font-size-28;
  199. color: $text-color;
  200. background: #FFFFFF;
  201. float: left;
  202. font-weight: bold;
  203. .freight-left{
  204. float: left;
  205. .tips{
  206. font-size: $font-size-24;
  207. color: $color-system;
  208. font-weight: normal;
  209. margin-left: 20rpx;
  210. }
  211. .icon-yunfeishuoming{
  212. height: 100%;
  213. padding:15rpx;
  214. color: $color-system;
  215. font-weight: normal;
  216. }
  217. }
  218. .freight-right{
  219. float: right;
  220. color: #2A81FF;
  221. position: relative;
  222. .freight-text{
  223. float: left;
  224. }
  225. .select{
  226. float: right;
  227. height: 60rpx;
  228. padding: 0 20rpx;
  229. margin-top: 14rpx;
  230. line-height: 60rpx;
  231. color: #2A81FF;
  232. font-weight: normal;
  233. position: relative;
  234. .select-text{
  235. display: inline-block;
  236. float: left;
  237. margin-right: 30rpx;
  238. }
  239. .iconfont{
  240. width: 60rpx;
  241. height: 60rpx;
  242. line-height: 60rpx;
  243. text-align: right;
  244. position: absolute;
  245. right: 0;
  246. top: 0;
  247. font-size: $font-size-28;
  248. color: #2A81FF;
  249. }
  250. }
  251. }
  252. }
  253. .freight-bean{
  254. width: 100%;
  255. height: 58rpx;
  256. line-height: 58rpx;
  257. float: left;
  258. .bean-le{
  259. float: left;
  260. color: #666666;
  261. font-size: $font-size-26;
  262. font-weight: normal;
  263. }
  264. .bean-ri{
  265. float: right;
  266. display: flex;
  267. align-items: center;
  268. .checkbox-box{
  269. display: flex;
  270. width: 60rpx;
  271. float: left;
  272. height: 100%;
  273. font-size: $font-size-26;
  274. margin-top: 8rpx;
  275. .checkbox{
  276. width: 40rpx;
  277. text-align: right;
  278. box-sizing: border-box;
  279. text-align: center;
  280. text-decoration: none;
  281. border-radius: 0;
  282. -webkit-tap-highlight-color: transparent;
  283. overflow: hidden;
  284. color: $color-system;
  285. }
  286. }
  287. }
  288. }
  289. }
  290. }
  291. </style>