cm-freight-popup.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template name="freight">
  2. <!-- 运费信息 -->
  3. <view>
  4. <view class="goods-pros-m">
  5. <template v-if="supplier.postageFlag === 0">
  6. <view class="freight-main">
  7. <view class="freight-left">运费</view>
  8. <view class="freight-right"> <view class="freight-text">包邮</view> </view>
  9. </view>
  10. </template>
  11. <template v-if="supplier.postageFlag === 1">
  12. <view class="freight-main">
  13. <view class="freight-left">运费</view>
  14. <view class="freight-right" @click.stop="handlePupShow">
  15. <view class="freight-text" v-if="handlePostageFlag === 1">¥{{ handleTotalPostage | NumFormat }}</view>
  16. <view class="freight-text" v-if="handlePostageFlag === 2">到付</view>
  17. <view class="select"><text class="iconfont icon-xiayibu"></text></view>
  18. </view>
  19. </view>
  20. </template>
  21. <template v-if="supplier.postageFlag === 2">
  22. <view class="freight-main">
  23. <view class="freight-left">运费</view>
  24. <view class="freight-right"> <view class="freight-text">到付</view> </view>
  25. </view>
  26. </template>
  27. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  28. <view class="freight-title">运费设置</view>
  29. <view class="freight-content">
  30. <radio-group @change="radioChange">
  31. <label v-for="(item, index) in radioItems" :key="index">
  32. <radio
  33. style="transform:scale(0.7)"
  34. color="#FF5B00"
  35. :id="item.value"
  36. :value="item.value"
  37. :checked="item.checked"
  38. ></radio>
  39. <label :for="item.value" class="label">
  40. <text>{{ item.name }}</text>
  41. </label>
  42. </label>
  43. </radio-group>
  44. <template v-if="handlePostageFlag === 1">
  45. <view class="freight-form">
  46. <view class="freight-form-item" v-if="handleSupplier.coldChain > 0">
  47. <view class="label">冷链运输费</view>
  48. <view class="texts">
  49. <text>¥{{ handleSupplier.coldChain | NumFormat }}</text>
  50. <text
  51. class="iconfont"
  52. :class="[isColdChina ? 'icon-yixuanze' : 'icon-weixuanze']"
  53. @click.stop="handleChangeColdChina"
  54. >
  55. </text>
  56. </view>
  57. </view>
  58. <view class="freight-form-item">
  59. <view class="label">其他运费 </view>
  60. <view class="texts">¥{{ handleSupplier.postage | NumFormat }} </view>
  61. </view>
  62. <view class="freight-form-item">
  63. <view class="label">总运费 </view>
  64. <view class="texts red">¥{{ handleTotalPostage | NumFormat }} </view>
  65. </view>
  66. </view>
  67. </template>
  68. <template v-if="handlePostageFlag === 2">
  69. <view class="freight-form">
  70. <view class="freight-form-item">
  71. <view class="label">总运费</view>
  72. <view class="texts red">到付</view>
  73. </view>
  74. </view>
  75. </template>
  76. <view class="freight-btn" @click="popupShow = false"> 确定 </view>
  77. </view>
  78. </tui-bottom-popup>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. export default {
  84. name: 'freight',
  85. props: {
  86. supplier: {
  87. type: Object
  88. },
  89. index:{
  90. type:Number
  91. }
  92. },
  93. data() {
  94. return {
  95. popupShow: false,
  96. isColdChina:false,
  97. handlePostageFlag:1,
  98. radioItems: [
  99. {
  100. name: '不包邮',
  101. value: 1,
  102. checked: true
  103. },
  104. {
  105. name: '到付',
  106. value: 2,
  107. }
  108. ],
  109. handleSupplier:{}
  110. }
  111. },
  112. filters: {
  113. NumFormat(value) {
  114. //处理金额
  115. return Number(value).toFixed(2)
  116. }
  117. },
  118. created() {
  119. this.infoSupplier(this.supplier)
  120. },
  121. computed: {
  122. // 计算总运费
  123. handleTotalPostage(){
  124. if(this.handleSupplier.isColdChina){
  125. return (this.handleSupplier.postage*100 + this.handleSupplier.coldChain*100)/100
  126. }else{
  127. return this.handleSupplier.postage
  128. }
  129. }
  130. },
  131. watch: {
  132. supplier: {
  133. handler: function(el) {
  134. //监听对象的变换使用 function,箭头函数容易出现this指向不正确
  135. this.supplier = el
  136. },
  137. deep: true
  138. }
  139. },
  140. methods: {
  141. // 初始化
  142. infoSupplier(data){
  143. this.handleSupplier = data
  144. this.isColdChina = data.isColdChina
  145. this.handlePostageFlag = data.handlePostageFlag
  146. },
  147. // 勾选冷链费
  148. handleChangeColdChina(){
  149. this.isColdChina = !this.isColdChina
  150. this.handleSupplier.isColdChina = this.isColdChina
  151. if(this.isColdChina){
  152. this.handleSupplier.totalPrice = Number((this.handleSupplier.totalPrice*100 + this.handleSupplier.coldChain*100)/100)
  153. this.$emit('changeColdChina', this.handleSupplier,this.index)
  154. }else{
  155. this.handleSupplier.totalPrice = Number(this.repiceNumSub(this.handleSupplier.totalPrice,this.handleSupplier.coldChain))
  156. this.$emit('changeColdChina', this.handleSupplier,this.index)
  157. }
  158. },
  159. // 切换运费类型 1 不包邮 2 到付
  160. radioChange($event) {
  161. const postage = this.isColdChina ? ( this.handleSupplier.postage + this.handleSupplier.coldChain ) : this.handleSupplier.postage
  162. this.handlePostageFlag = this.handleSupplier.handlePostageFlag = $event.detail.value*1
  163. if(this.handlePostageFlag === 1){
  164. this.handleSupplier.totalPrice = Number((this.handleSupplier.totalPrice*100 + postage*100)/100)
  165. this.$emit('changePostage', this.handleSupplier,this.index)
  166. }else{
  167. this.handleSupplier.totalPrice = Number(this.repiceNumSub(this.handleSupplier.totalPrice,postage))
  168. this.$emit('changePostage', this.handleSupplier,this.index)
  169. }
  170. },
  171. repiceNumSub(arg1, arg2) {//减法精确,arg2:被减数,arg1:减数
  172. var r1,r2,m,n;
  173. try{
  174. r1=arg1.toString().split(".")[1].length
  175. }catch(e){
  176. r1=0
  177. }
  178. try{
  179. r2=arg2.toString().split(".")[1].length
  180. }catch(e){
  181. r2=0
  182. }
  183. m=Math.pow(10,Math.max(r1,r2));
  184. // last modify by deeka
  185. // 动态控制精度长度
  186. n=(r1>=r2)?r1:r2;
  187. return ((arg1*m-arg2*m)/m).toFixed(n);
  188. },
  189. handlePupShow(){
  190. this.popupShow = true
  191. },
  192. hidePopup() {
  193. this.popupShow = false
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="scss">
  199. .goods-pros-m {
  200. width: 100%;
  201. box-sizing: border-box;
  202. padding: 10rpx 0;
  203. .freight-main {
  204. width: 100%;
  205. height: 78rpx;
  206. line-height: 78rpx;
  207. font-size: $font-size-28;
  208. color: $text-color;
  209. background: #ffffff;
  210. float: left;
  211. .freight-left {
  212. float: left;
  213. font-weight: bold;
  214. }
  215. .freight-right {
  216. float: right;
  217. color: #333333;
  218. position: relative;
  219. .freight-text {
  220. float: left;
  221. }
  222. .select {
  223. float: right;
  224. height: 60rpx;
  225. padding: 0 20rpx;
  226. margin-top: 14rpx;
  227. line-height: 60rpx;
  228. color: #333333;
  229. font-weight: normal;
  230. position: relative;
  231. .select-text {
  232. display: inline-block;
  233. float: left;
  234. margin-right: 30rpx;
  235. }
  236. .iconfont {
  237. width: 60rpx;
  238. height: 60rpx;
  239. line-height: 60rpx;
  240. text-align: right;
  241. position: absolute;
  242. right: 0;
  243. top: 0;
  244. font-size: $font-size-28;
  245. color: #B2B2B2;
  246. }
  247. }
  248. }
  249. }
  250. .freight-bean {
  251. width: 100%;
  252. height: 58rpx;
  253. line-height: 58rpx;
  254. float: left;
  255. .bean-le {
  256. float: left;
  257. color: #666666;
  258. font-size: $font-size-26;
  259. font-weight: normal;
  260. }
  261. .bean-ri {
  262. float: right;
  263. display: flex;
  264. align-items: center;
  265. .checkbox-box {
  266. display: flex;
  267. width: 60rpx;
  268. float: left;
  269. height: 100%;
  270. font-size: $font-size-26;
  271. margin-top: 8rpx;
  272. .checkbox {
  273. width: 40rpx;
  274. text-align: right;
  275. box-sizing: border-box;
  276. text-align: center;
  277. text-decoration: none;
  278. border-radius: 0;
  279. -webkit-tap-highlight-color: transparent;
  280. overflow: hidden;
  281. color: $color-system;
  282. }
  283. }
  284. }
  285. }
  286. }
  287. .freight-title {
  288. color: #333333;
  289. font-size: 32rpx;
  290. text-align: center;
  291. margin: 40rpx 0;
  292. }
  293. .freight-content {
  294. box-sizing: border-box;
  295. padding: 0 24rpx;
  296. font-weight: normal;
  297. radio{
  298. margin-right: 8rpx;
  299. }
  300. .label {
  301. color: #666666;
  302. font-size: 28rpx;
  303. margin-right: 102rpx;
  304. }
  305. .freight-btn {
  306. height: 90rpx;
  307. background: $btn-confirm;
  308. border-radius: 45rpx;
  309. display: flex;
  310. justify-content: center;
  311. align-items: center;
  312. color: #FFFFFF;
  313. width: 100%;
  314. margin: 100rpx 0 0 0;
  315. }
  316. }
  317. .freight-form {
  318. margin-top: 50rpx;
  319. width: 100%;
  320. .freight-form-item {
  321. width: 100%;
  322. height: 48rpx;
  323. line-height: 48rpx;
  324. margin-bottom: 24rpx;
  325. color: #666666;
  326. font-size: 28rpx;
  327. .label{
  328. width: 50%;
  329. float: left;
  330. margin-right: 0;
  331. }
  332. .texts{
  333. width: 50%;
  334. float: right;
  335. text-align: right;
  336. &.red{
  337. color: #F94B4B;
  338. }
  339. .iconfont{
  340. margin-left: 20rpx;
  341. color: $color-system;
  342. }
  343. }
  344. }
  345. }
  346. .freight-pay {
  347. position: absolute;
  348. right: -60%;
  349. transform:scale(0.7);
  350. }
  351. </style>