123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- <template name="freight">
- <!-- 运费信息 -->
- <view>
- <view class="goods-pros-m">
- <view class="freight-main">
- <view class="freight-left">运费:</view>
- <view class="freight-right" @click.stop="handlePupShow">
- <template v-if="handlePostageFlag === 0">
- <view class="freight-text" v-if="handleSupplier.isColdChina"
- >¥{{ handleSupplier.coldChain | NumFormat }}</view
- >
- <view class="freight-text" v-else>包邮</view>
- </template>
- <view class="freight-text" v-if="handlePostageFlag === 1"
- >¥{{ handleTotalPostage | NumFormat }}</view
- >
- <template v-if="handlePostageFlag === 2">
- <view class="freight-text" v-if="handleSupplier.isColdChina"
- >¥{{ handleSupplier.coldChain | NumFormat }}</view
- >
- <view class="freight-text" v-else>到付</view>
- </template>
- <view class="select"><text class="iconfont icon-xiangyou"></text></view>
- </view>
- </view>
- <tui-bottom-popup :radius="true" :show="popupShow" @close="handleComfirm">
- <view class="freight-title">运费设置</view>
- <view class="freight-content">
- <radio-group @change="radioChange">
- <label v-for="(item, index) in radioItems" :key="index">
- <radio
- style="transform:scale(0.7)"
- color="#FF5B00"
- :id="item.value"
- :value="item.value"
- :checked="item.checked"
- ></radio>
- <label :for="item.value" class="label">
- <text>{{ item.name }}</text>
- </label>
- </label>
- </radio-group>
- <template v-if="handlePostageFlag === 0">
- <view class="freight-form">
- <view class="freight-form-item" v-if="handleSupplier.coldChain > 0">
- <view class="label">冷链运输费</view>
- <view class="texts">
- <text>¥{{ handleSupplier.coldChain | NumFormat }}</text>
- <text
- class="iconfont"
- :class="[isColdChina ? 'icon-yixuanze' : 'icon-weixuanze']"
- @click.stop="handleChangeColdChina"
- >
- </text>
- </view>
- </view>
- <view class="freight-form-item">
- <view class="label">其他运费 </view> <view class="texts red">包邮</view>
- </view>
- <view class="freight-form-item">
- <view class="label">总运费</view>
- <view class="texts red" v-if="handleSupplier.isColdChina"
- >¥{{ handleSupplier.coldChain | NumFormat }}</view
- >
- <view class="texts red" v-else>包邮</view>
- </view>
- </view>
- </template>
- <template v-if="handlePostageFlag === 1">
- <view class="freight-form">
- <view class="freight-form-item">
- <input
- class="form-input"
- type="number"
- v-model="handlePostageVal"
- @input="handleInputPostage"
- placeholder="请填写运费"
- maxlength="20"
- />
- </view>
- <view class="freight-form-item" v-if="handleSupplier.coldChain > 0">
- <view class="label">冷链运输费</view>
- <view class="texts">
- <text>¥{{ handleSupplier.coldChain | NumFormat }}</text>
- <text
- class="iconfont"
- :class="[isColdChina ? 'icon-yixuanze' : 'icon-weixuanze']"
- @click.stop="handleChangeColdChina"
- >
- </text>
- </view>
- </view>
- <view class="freight-form-item">
- <view class="label">其他运费 </view>
- <view class="texts">¥{{ handleSupplier.postage | NumFormat }} </view>
- </view>
- <view class="freight-form-item">
- <view class="label">总运费 </view>
- <view class="texts red">¥{{ handleTotalPostage | NumFormat }} </view>
- </view>
- </view>
- </template>
- <template v-if="handlePostageFlag === 2">
- <view class="freight-form">
- <view class="freight-form-item" v-if="handleSupplier.coldChain > 0">
- <view class="label">冷链运输费</view>
- <view class="texts">
- <text>¥{{ handleSupplier.coldChain | NumFormat }}</text>
- <text
- class="iconfont"
- :class="[isColdChina ? 'icon-yixuanze' : 'icon-weixuanze']"
- @click.stop="handleChangeColdChina"
- >
- </text>
- </view>
- </view>
- <view class="freight-form-item">
- <view class="label">其他运费 </view><view class="texts red">到付</view>
- </view>
- <view class="freight-form-item">
- <view class="label">总运费</view>
- <view class="texts red" v-if="handleSupplier.isColdChina"
- >¥{{ handleSupplier.coldChain | NumFormat }}</view
- >
- <view class="texts red" v-else>到付</view>
- </view>
- </view>
- </template>
- <view class="freight-btn" @click="handleComfirm"> 确定 </view>
- </view>
- </tui-bottom-popup>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'freight',
- props: {
- supplier: {
- type: Object
- },
- index: {
- type: Number
- }
- },
- data() {
- return {
- popupShow: false,
- isColdChina: false,
- handleColdChain:0,// 记录冷链费
- handlePostage: 0, // 记录原始运费
- handlePostageVal: 0, // 记录修改的运费
- handlePostageFlag: 0, // 记录运费类型
- radioItems: [
- {
- name: '包邮',
- value: 0,
- checked: false
- },
- {
- name: '不包邮',
- value: 1,
- checked: false
- },
- {
- name: '到付',
- value: 2,
- checked: false
- }
- ],
- handleTotalPrice: 0, // 记录原始供应商总价
- handleSupplier: {} // 记录原始信息
- }
- },
- filters: {
- NumFormat(value) {
- //处理金额
- return Number(value).toFixed(2)
- }
- },
- created() {
- this.infoSupplier(this.supplier)
- },
- computed: {
- // 计算总运费
- handleTotalPostage() {
- if (this.handleSupplier.isColdChina) {
- return (this.handleSupplier.postage * 100 + this.handleSupplier.coldChain * 100) / 100
- } else {
- return this.handleSupplier.postage
- }
- }
- },
- watch: {
- supplier: {
- handler: function(el) {
- //监听对象的变换使用 function,箭头函数容易出现this指向不正确
- this.supplier = el
- },
- deep: true
- }
- },
- methods: {
- // 初始化
- infoSupplier(data) {
- this.handleSupplier = data
- this.isColdChina = data.isColdChina
- this.handleColdChain = data.coldChain
- this.handleTotalPrice = data.totalPrice
- this.handlePostage = this.handlePostageVal = data.postage
- this.handlePostageFlag = data.handlePostageFlag
- console.log('handlePostageFlag', this.handlePostageFlag)
- switch (this.handlePostageFlag) {
- case 0:
- this.radioItems[0].checked = true
- break
- case 1:
- this.radioItems[1].checked = true
- break
- case 2:
- this.radioItems[2].checked = true
- break
- }
- },
- handleInputPostage(e) {
- //处理邮费显示
- // if (e.detail.value == '') {
- // this.handleSupplier.postage = 0
- // }
- },
- // 勾选冷链费
- handleChangeColdChina() {
- this.isColdChina = !this.isColdChina
- this.handleSupplier.isColdChina = this.isColdChina
- if (this.isColdChina) {
- this.handleSupplier.totalPrice = Number(
- (this.handleSupplier.totalPrice * 100 + this.handleSupplier.coldChain * 100) / 100
- )
- this.$emit('changeColdChina', this.handleSupplier, this.index)
- } else {
- this.handleSupplier.totalPrice = Number(
- this.repiceNumSub(this.handleSupplier.totalPrice, this.handleSupplier.coldChain)
- )
- this.$emit('changeColdChina', this.handleSupplier, this.index)
- }
- },
- // 切换运费类型0包邮 1 不包邮 2 到付
- radioChange($event) {
- this.handlePostageFlag = this.handleSupplier.handlePostageFlag = $event.detail.value * 1
- if (this.handlePostageFlag === 1) {
- this.handleSupplier.postage = this.handlePostage
- } else {
- this.handleSupplier.postage = this.handlePostage
- }
- },
- // 确定运费
- handleComfirm() {
- if (this.handlePostageFlag === 0) {
- let handleTotalPrice = this.isColdChina ? this.handleTotalPrice : Number(this.repiceNumSub(this.handleTotalPrice, this.handleColdChain))
- this.handleSupplier.totalPrice = Number(this.repiceNumSub(handleTotalPrice, this.handleSupplier.postage))
- this.$emit('changePostage', this.handleSupplier, this.index)
- } else if (this.handlePostageFlag === 1) {
- if (this.handlePostageVal == 0 || !this.handlePostageVal) {
- this.$util.msg('请填写运费', 2000)
- return
- }
- this.handleSupplier.totalPrice = Number(
- (this.handleTotalPrice * 100 - this.handlePostage * 100 + this.handlePostageVal * 100) / 100
- )
- this.handleSupplier.postage = this.handlePostageVal
- this.$emit('changePostage', this.handleSupplier, this.index)
- } else {
- let handleTotalPrice = this.isColdChina ? this.handleTotalPrice : Number(this.repiceNumSub(this.handleTotalPrice, this.handleColdChain))
- this.handleSupplier.totalPrice = Number(this.repiceNumSub(handleTotalPrice, this.handleSupplier.postage))
- this.$emit('changePostage', this.handleSupplier, this.index)
- }
- this.popupShow = false
- },
- //减法精确,arg2:被减数,arg1:减数
- repiceNumSub(arg1, arg2) {
- var r1, r2, m, n
- try {
- r1 = arg1.toString().split('.')[1].length
- } catch (e) {
- r1 = 0
- }
- try {
- r2 = arg2.toString().split('.')[1].length
- } catch (e) {
- r2 = 0
- }
- m = Math.pow(10, Math.max(r1, r2))
- // last modify by deeka
- // 动态控制精度长度
- n = r1 >= r2 ? r1 : r2
- return ((arg1 * m - arg2 * m) / m).toFixed(n)
- },
- handlePupShow() {
- this.popupShow = true
- },
- hidePopup() {
- this.popupShow = false
- }
- }
- }
- </script>
- <style lang="scss">
- .goods-pros-m {
- width: 100%;
- box-sizing: border-box;
- padding: 10rpx 0;
- .freight-main {
- width: 100%;
- height: 78rpx;
- line-height: 78rpx;
- font-size: $font-size-28;
- color: $text-color;
- background: #ffffff;
- float: left;
- .freight-left {
- float: left;
- font-weight: bold;
- }
- .freight-right {
- float: right;
- color: #333333;
- position: relative;
- .freight-text {
- float: left;
- }
- .select {
- float: right;
- height: 78rpx;
- padding: 0 20rpx;
- line-height: 78rpx;
- color: #333333;
- font-weight: normal;
- position: relative;
- .select-text {
- display: inline-block;
- float: left;
- margin-right: 30rpx;
- }
- .iconfont {
- width: 60rpx;
- height: 78rpx;
- line-height: 78rpx;
- text-align: right;
- position: absolute;
- right: 0;
- top: 0;
- font-size: $font-size-30;
- color: #b2b2b2;
- }
- }
- }
- }
- .freight-bean {
- width: 100%;
- height: 58rpx;
- line-height: 58rpx;
- float: left;
- .bean-le {
- float: left;
- color: #666666;
- font-size: $font-size-26;
- font-weight: normal;
- }
- .bean-ri {
- float: right;
- display: flex;
- align-items: center;
- .checkbox-box {
- display: flex;
- width: 60rpx;
- float: left;
- height: 100%;
- font-size: $font-size-26;
- margin-top: 8rpx;
- .checkbox {
- width: 40rpx;
- text-align: right;
- box-sizing: border-box;
- text-align: center;
- text-decoration: none;
- border-radius: 0;
- -webkit-tap-highlight-color: transparent;
- overflow: hidden;
- color: $color-system;
- }
- }
- }
- }
- }
- .freight-title {
- color: #333333;
- font-size: 32rpx;
- text-align: center;
- margin: 40rpx 0;
- }
- .freight-content {
- box-sizing: border-box;
- padding: 0 24rpx;
- font-weight: normal;
- radio {
- margin-right: 8rpx;
- }
- .label {
- color: #666666;
- font-size: 28rpx;
- margin-right: 102rpx;
- }
- .freight-btn {
- height: 90rpx;
- background: $btn-confirm;
- border-radius: 45rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- color: #ffffff;
- width: 100%;
- margin: 100rpx 0 0 0;
- }
- }
- .freight-form {
- margin-top: 50rpx;
- width: 100%;
- .freight-form-item {
- width: 100%;
- height: 60rpx;
- line-height: 60rpx;
- margin-bottom: 24rpx;
- color: #666666;
- font-size: 28rpx;
- .label {
- width: 50%;
- float: left;
- margin-right: 0;
- }
- .texts {
- width: 50%;
- float: right;
- text-align: right;
- &.red {
- color: #f94b4b;
- }
- .iconfont {
- margin-left: 20rpx;
- color: $color-system;
- }
- }
- .form-input {
- width: 100%;
- height: 60rpx;
- line-height: 60rpx;
- flex-grow: 1;
- box-sizing: border-box;
- padding: 0 20rpx;
- border: 1px solid #e1e1e1;
- border-radius: 4rpx;
- }
- }
- }
- .freight-pay {
- position: absolute;
- right: -60%;
- transform: scale(0.7);
- }
- </style>
|