captain-ui
Version:
有赞vue wap业务组件库
123 lines (111 loc) • 3.15 kB
JavaScript
import "vant/es/cell/style";
import _Cell from "vant/es/cell";
import "vant/es/icon/style";
import _Icon from "vant/es/icon";
var _components;
var addressKeys = ['country', 'province', 'city', 'county', 'community', 'address_detail'];
export default {
render: function render() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('div', {
staticClass: "cap-logistics",
class: {
'cap-logistics--clickable': _vm.editable
},
on: {
"click": _vm.handleClick
}
}, [_vm.hasAddress ? _c('div', {
staticClass: "cap-logistics__address"
}, [_c('van-icon', {
attrs: {
"name": "location"
}
}), _c('div', {
staticClass: "cap-logistics__address-content"
}, [_c('div', [_c('p', {
staticClass: "cap-logistics__address-name"
}, [_vm._v("收货人:" + _vm._s(_vm.userName))]), _c('p', {
staticClass: "cap-logistics__address-tel"
}, [_vm._v(_vm._s(_vm.tel))])]), _c('p', {
staticClass: "cap-logistics__address-detail"
}, [_vm._v("收货地址:" + _vm._s(_vm.addressDetail))])])], 1) : _c('div', {
staticClass: "cap-logistics__empty-address"
}, [_vm._v("\n 新建收货地址\n ")]), _c('van-icon', {
directives: [{
name: "show",
rawName: "v-show",
value: _vm.editable,
expression: "editable"
}],
attrs: {
"name": "arrow"
}
})], 1);
},
name: 'cap-logistics',
components: (_components = {}, _components[_Icon.name] = _Icon, _components[_Cell.name] = _Cell, _components),
props: {
// 地址展示对象
address: {
type: Object,
default: function _default() {
return {};
}
},
// 地址能否修改
editable: {
type: Boolean,
default: true
},
// 隐藏完整手机号
hideRealTel: {
type: Boolean,
default: false
}
},
computed: {
hasAddress: function hasAddress() {
return Object.keys(this.address).length > 0;
},
userName: function userName() {
return this.address.name || this.address.user_name || '';
},
addressDetail: function addressDetail() {
if (this.hasAddress) {
var address = this.address;
var keys = addressKeys.slice(0); // 判断省市是否相同
if (address[keys[1]] && address[keys[1]] === address[keys[2]]) {
keys.splice(1, 1);
} // 中国不需要展示
if (address[keys[0]] === '中国') {
keys.shift(0);
}
return keys.filter(function (key) {
return address[key];
}).map(function (key) {
return address[key];
}).join('');
}
return '';
},
tel: function tel() {
if (this.hasAddress) {
if (this.hideRealTel) {
return String(this.address.tel).replace(/\d{4}(\d{4})$/, '****$1');
}
return this.address.tel;
}
return '';
}
},
methods: {
handleClick: function handleClick(e) {
if (this.editable) {
this.$emit('click', e);
}
}
}
};