123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <template>
- <view>
- <view class="address-box">
- <template v-if="addrs.length > 0 && type == 0">
- <view v-for="(item,index) in addrs" :key="index" class="address-box-list">
- <view class="address-box-left">
- <text class="address-box-title">{{item.name}} {{item.phone}}</text>
- <text class="address-box-desc">{{item.content}}</text>
- </view>
- <view class="address-box-right" @click="handleEdit(item)">
- <image src="../../images/edit.png"></image>
- </view>
- </view>
- </template>
-
- <template v-if="addrs.length > 0 && type == 1">
- <radio-group @change="radioChange">
- <view class="address-box-list" v-for="(item, index) in addrs" :key="index">
- <label>
- <view class="address-box-select">
- <radio :value="item.id" :checked="item.id === current" />
- </view>
- <view class="address-box-left2">
- <text class="address-box-title">{{item.name}} {{item.phone}}</text>
- <text class="address-box-desc">{{item.address1}} {{item.address2}} {{item.room}}</text>
- </view>
- </label>
- <view class="address-box-right" @click="handleEdit(item)">
- <image src="../../images/edit.png"></image>
- </view>
- </view>
- </radio-group>
- </template>
-
-
-
-
-
- <view v-if="addrs.length == 0" class="no-data">
- <image src="../../images/no_data.png" mode=""></image>
- <view class="no-data-text">
- 空空如也~
- </view>
- </view>
- </view>
-
- <view class="bottom-btn" @click="handleAdd">
- 新增收货地址
- </view>
- </view>
- </template>
- <script>
- var app = getApp();
- export default {
- data() {
- return {
- addrs: [],
- page: 1,
- size: 20,
- flag: 0,
- type: 0,
- current: 0
- }
- },
- onLoad(option) {
- var that = this;
- this.type = option.type?option.type:0;
- if(this.type == 1){
- uni.setNavigationBarTitle({
- title: '选择地址'
- });
-
- const eventChannel = this.getOpenerEventChannel()
- // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
- eventChannel.on('acceptDataFromOpenerPage', function(data) {
- that.current = data.addressId;
- })
- }
-
- },
- onShow(){
- var that = this;
- this.flag = 0;
- this.page = 1;
- this.getAddress();
-
- app.ajaxReadyCallback = res => { //各个接口统一回调方法
- var apiname = res.data.apiname;
- console.log(res);
- if(apiname == 'addr'){
- that.addrs = res.data.data;
- if (that.addrs.length < that.size) {
- that.flag = 1;
- } else {
- that.page++;
- }
- }
- }
- },
- onPullDownRefresh() {
- this.flag = 0;
- this.page = 1;
- this.getAddress();
- },
- onReachBottom() { //上拉加载
- console.log('11111111');
- this.getAddress();
- },
- methods: {
- handleAdd(){
- uni.navigateTo({
- url: '/pages/address/add'
- });
- },
- handleEdit(obj){
- uni.navigateTo({
- url: '/pages/address/add?id='+obj.id
- });
- },
- getAddress(){
- if(this.flag == 1){
- return;
- }
- app.ajax({
- url: app.globalData.serverUrl + 'shopAddress/list',
- type: 'POST',
- apiname: 'addr',
- data: {
- page: this.page,
- size: this.size
- }
- });
- },
- radioChange(evt) {
- this.addrs.forEach((item,index) => {
- if (item.id === evt.detail.value) {
- this.current = item.id;
- const eventChannel = this.getOpenerEventChannel()
- eventChannel.emit('acceptDataFromOpenedPage', item);
- uni.navigateBack({
- delta: 1
- });
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .address-box{
- padding-bottom: 100rpx;
- }
- .address-nodata{
- margin-top: 150rpx;
- text-align: center;
- font-size: 32rpx;
- color: #666666;
- }
- .address-box-list{
- background-color: #FFFFFF;
- margin: 10rpx 0;
- padding: 10rpx 20rpx;
- overflow: hidden;
- }
- .address-box-left{
- display: inline-block;
- width: 630rpx;
- height: auto;
- float: left;
- }
- .address-box-left .address-box-title{
- display: inline-block;
- width: 100%;
- height: 30rpx;
- line-height: 30rpx;
- color: #3E3E3E;
- font-size: 32rpx;
- }
- .address-box-left .address-box-desc{
- display: inline-block;
- width: 100%;
- height: 30rpx;
- line-height: 30rpx;
- color: #949494;
- font-size: 28rpx;
- }
- .address-box-right{
- display: inline-block;
- width: 60rpx;
- height: auto;
- float: right;
- text-align: center;
- }
- .address-box-right image{
- width: 40rpx;
- height: 40rpx;
- vertical-align: middle;
- margin-top: 20rpx;
- }
-
- .address-box-left2{
- display: inline-block;
- width: 570rpx;
- height: auto;
- float: left;
- }
- .address-box-left2 .address-box-title{
- display: inline-block;
- width: 100%;
- height: 30rpx;
- line-height: 30rpx;
- color: #3E3E3E;
- font-size: 32rpx;
- }
- .address-box-left2 .address-box-desc{
- display: inline-block;
- width: 100%;
- height: 30rpx;
- line-height: 30rpx;
- color: #949494;
- font-size: 28rpx;
- }
-
- .bottom-btn{
- width: 100%;
- height: 98rpx;
- line-height: 98rpx;
- background-color: $theme-color;
- color: #FFFFFF;
- text-align: center;
- position: fixed;
- z-index: 100;
- left: 0;
- bottom: 0;
- }
-
- .address-box-select{
- display: inline-block;
- width: 60rpx;
- height: auto;
- float: left;
- }
- .address-box-select radio{
- width: 40rpx;
- height: 40rpx;
- // vertical-align: middle;
- margin-top: 20rpx;
- }
- </style>
|