123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <template>
- <view class="app">
- <view class="app-items">
- <view class="item" @tap="clickView(item)" v-for="(item,index) of addList" :key="index">
- <view class="title">
- <text class="name">{{ item.name }}</text>
- <text class="tag" v-if="item.status == 1">默认地址</text>
- </view>
- <view class="editBox">
- <text class="address">{{item.province}}{{item.city}}{{item.area}}{{item.address}}</text>
- <view class="edit" @tap="editClick(item.id)">
- <image class="editTip" src="/static/img/edit.png"></image>
- </view>
- </view>
- <text class="mobile">{{mobileTap(item.tel)}}</text>
- <view class="item-foot">
- <view class="default" @tap="set_default_address(item.id,index)">
- <image class="itemDefaultTip" src="/static/img/radio_buttons_btn.png" v-if="item.status == 1"></image>
- <image class="itemDefaultTip" src="/static/img/radio_buttons.png" v-else></image>
- <text class="defaultText">
- 默认地址
- </text>
- </view>
- <text class="del" @tap="del_address(item.id,index)">删除</text>
- </view>
- </view>
- </view>
- <view style="height: 100rpx;"></view>
- <view class="foot-wiget">
- <view class="foot-btn" @tap="addClick">
- <text class="foot-btn-text">
- 新增地址
- </text>
- </view>
- </view>
- </view>
- </template>
- <style lang="scss">
- .app {
- padding: 20rpx 30rpx;
- .app-items {
- .item {
- background: #fff;
- border-radius: 10px;
- padding: 10px 15px;
- margin-bottom: 10px;
- .title{
- flex-direction: row;
- justify-content: space-between;
- .name {
- color: #333;
- font-size: 16px;
- font-weight: 600;
- }
- .tag {
- background: #aaaaaa;
- font-size: 12px;
- color: #FFF;
- padding: 2px 6px;
- margin-left: 4px;
- border-radius: 4px;
- }
- }
- .editBox{
- justify-content: space-between;
- flex-direction: row;
- align-items: center;
- .address {
- width: 580rpx;
- color: #333;
- font-size: 28rpx;
- padding: 4px 0;
- }
-
- .edit {
- .editTip {
- width: 16px;
- height: 16px;
- }
- }
- }
- .mobile {
- color: #919191;
- font-size: 14px;
- margin: 4px 0;
- }
- .item-foot{
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- .default {
- flex-direction: row;
- align-items: center;
- .itemDefaultTip {
- width: 14px;
- height: 14px;
- margin-right: 4px;
- }
- .defaultText{
- color: #727272;
- font-size: 14px;
- }
- }
-
- .del {
- color: #727272;
- font-size: 14px;
- }
- }
-
- }
- }
- .foot-wiget {
- position: fixed;
- bottom: 20rpx;
- left: 30rpx;
- width: 690rpx;
- justify-content: center;
- .foot-btn {
- height: 80rpx;
- background: #db292b;
- border-radius: 25px;
- flex-direction: row;
- align-items: center;
- justify-content: center;
- .foot-btn-text{
- color: #FFF;
- }
- .addTip {
- width: 15px;
- height: 15px;
- }
- }
- }
- }
- </style>
- <script>
- import Request from '@/library/Request';
- import utils from "@/library/utils/Comm.js"
- export default {
- data() {
- return {
- addList: [],
- type: ""
- }
- },
- onShow() {
- this.initView();
- },
- onLoad(options) {
- this.type = options.type || '';
- },
- methods: {
- /**
- * 地址栏目
- */
- initView: function() {
- Request
- .post("userAddress")
- .then(res => {
- if (res.code == 200) {
- this.addList = res.data;
- }
- })
- .catch(err => {
- utils.Tip("网络错误,请稍后尝试");
- });
- },
- // 设置默认地址
- set_default_address(id, index) {
- utils.loadIng("提交中..");
- Request
- .post("userAddressDeflault", {
- id: id
- })
- .then(res => {
- uni.hideLoading();
- if (res.code == 200) {
- this.addList.forEach((v, k) => {
- if (index == k) {
- v.status = 1;
- } else {
- v.status = 0;
- }
- })
- }
- })
- .catch(err => {
- uni.hideLoading();
- utils.Tip("网络错误,请稍后尝试");
- });
- },
- // 删除地址
- del_address(id, index) {
- uni.showModal({
- title: "提示",
- content: "确认删除该地址吗?",
- success: (res) => {
- if (res.confirm) {
- utils.loadIng("提交中...");
- Request
- .post("userAddressDel", {
- id: id
- })
- .then(res => {
- uni.hideLoading();
- if (res.code == 200) {
- this.addList.splice(index, 1);
- }
- })
- .catch(err => {
- uni.hideLoading();
- utils.Tip("网络错误,请稍后尝试");
- });
- }
- }
- })
- },
- // 编辑地址
- editClick(id) {
- uni.navigateTo({
- url: `/pages/user/address/add/add?id=${id}`
- })
- },
- mobileTap(str1) {
- let reg = /^(\d{3})\d*(\d{4})$/;
- return str1.replace(reg, '$1****$2')
- },
- addClick() {
- uni.navigateTo({
- url: `/pages/user/address/add/add`
- })
- },
- clickView: function(item) {
- if (this.type == 'select') {
- uni.$emit("selectAddress", {
- addressId: item.id
- });
- uni.navigateBack();
- }
- }
- },
- }
- </script>
|