123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- <template>
- <mobile-frame>
- <view class="main">
- <view class="one">
- <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
- <view class="list-scroll-view">
- <view class="list" v-for="(item,index) in list" :key="index">
- <view class="name">
- <text>{{item.name}}</text>
- <text>{{item.phone}}</text>
- </view>
- <view class="address">
- <text>{{item.province}}</text>
- <text>{{item.city}}</text>
- <text>{{item.area}}</text>
- <text>{{item.address}}</text>
- <text>{{item.number}}</text>
- </view>
- <view class="btn">
- <view class="btn_1" v-if="item.is_default==false">
- <button type="default" size="mini" @click="toDefa(item)">设为默认</button>
- </view>
- <view class="btn_1">
- <button type="default" size="mini" @click="toCommon(item)">编辑</button>
- </view>
- <view class="btn_1">
- <button type="default" size="mini" @click="toDel(item)">删除</button>
- </view>
- </view>
- <view class="default" v-if="item.is_default==true">
- <text>默认</text>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- <view class="two">
- <view class="two_1">
- <button type="default" @click="toWxaddress()">获取微信地址</button>
- </view>
- <view class="two_1">
- <button type="default" @click="toCommon()">新增收货地址</button>
- </view>
- </view>
- </view>
- </mobile-frame>
- </template>
- <script>
- export default {
- data() {
- return {
- user: {},
- list: [],
- total: 0,
- skip: 0,
- limit: 5,
- page: 0
- };
- },
- onShow: function() {
- const that = this;
- that.watchLogin()
- },
- methods: {
- // 监听用户是否登录
- watchLogin() {
- const that = this;
- uni.getStorage({
- key: 'token',
- success: function(res) {
- let user = that.$jwt(res.data);
- that.$set(that, `user`, user);
- that.search()
- },
- fail: function(err) {
- uni.reLaunch({
- url: `/pages/login/index`
- })
- }
- })
- },
- // 查询列表
- async search() {
- const that = this;
- let user = that.user;
- let info = {
- skip: that.skip,
- limit: that.limit,
- customer: user._id
- }
- const res = await that.$api(`/address`, 'GET', {
- ...info
- })
- if (res.errcode == '0') {
- let list = [...that.list, ...res.data];
- that.$set(that, `list`, list);
- that.$set(that, `total`, res.total)
- }
- },
- // 分页
- toPage() {
- const that = this;
- let list = that.list;
- let limit = that.limit;
- if (that.total > list.length) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- let page = that.page + 1;
- that.$set(that, `page`, page)
- let skip = page * limit;
- that.$set(that, `skip`, skip)
- that.search();
- uni.hideLoading();
- } else uni.showToast({
- title: '没有更多数据了'
- });
- },
- // 获取微信地址
- toWxaddress() {
- const that = this;
- let user = that.user;
- uni.getStorage({
- key: 'system',
- success: function(res) {
- if (res.data.uniPlatform == 'app') {
- uni.showToast({
- title: '请进入微信小程序进行获取微信地址',
- icon: 'none'
- })
- } else if (res.data.uniPlatform == 'mp-weixin') {
- uni.chooseAddress({
- success: async function(add) {
- let params = {
- customer: user._id,
- name: add.userName,
- phone: add.telNumber,
- province: add.provinceName,
- city: add.cityName,
- area: add.countyName,
- address: add.detailInfo
- }
- const arr = await that.$api(`/address`, 'POST', params);
- if (arr.errcode == '0') {
- uni.showToast({
- title: '添加收货地址成功',
- icon: 'none'
- })
- that.clearPage();
- } else {
- uni.showToast({
- title: arr.errmsg,
- icon: 'none'
- })
- }
- },
- fail: function(err) {
- console.log(err);
- }
- })
- }
- }
- })
- },
- // 设置默认
- toDefa(e) {
- const that = this;
- uni.showModal({
- title: '提示',
- content: '确定设置该地址为默认地址吗?',
- success: async function(res) {
- if (res.confirm) {
- const arr = await that.$api(`/address/toDefault/${e._id}`, `POST`);
- if (arr.errcode == '0') {
- uni.showToast({
- title: '添加默认成功',
- icon: 'none'
- })
- that.clearPage();
- that.search();
- } else {
- uni.showToast({
- title: arr.errmsg,
- icon: 'none'
- })
- }
- }
- }
- });
- },
- // 编辑
- toCommon(e) {
- const that = this;
- that.clearPage();
- uni.navigateTo({
- url: `/pagesMy/address/add?id=${e&&e.id?e.id:''}`
- })
- },
- // 删除
- toDel(e) {
- const that = this;
- uni.showModal({
- title: '提示',
- content: '确定删除该地址吗?',
- success: async function(res) {
- if (res.confirm) {
- const arr = await that.$api(`/address/${e._id}`, 'DELETE');
- if (arr.errcode == '0') {
- uni.showToast({
- title: '删除信息成功',
- icon: 'none'
- })
- that.clearPage();
- that.search();
- } else {
- uni.showToast({
- title: arr.errmsg,
- icon: 'none'
- })
- }
- }
- }
- });
- },
- // 清空列表
- clearPage() {
- const that = this;
- that.$set(that, `list`, [])
- that.$set(that, `skip`, 0)
- that.$set(that, `limit`, 5)
- that.$set(that, `page`, 0)
- }
- }
- }
- </script>
- <style lang="scss">
- .main {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 100vh;
- .one {
- position: relative;
- flex-grow: 1;
- background-color: var(--f5Color);
- .list {
- position: relative;
- background: var(--fffColor);
- padding: 2vw;
- width: 92vw;
- margin: 2vw 2vw 0 2vw;
- border-radius: 5px;
- .name {
- font-size: var(--font16Size);
- margin: 0 0 2vw 0;
- text {
- padding: 0 2vw 0 0;
- }
- }
- .address {
- font-size: var(--font14Size);
- margin: 0 0 1vw 0;
- text {
- padding: 0 2vw 0 0;
- }
- }
- .btn {
- display: flex;
- flex-direction: row;
- justify-content: space-around;
- border-top: 1px solid var(--font16Size);
- padding: 2vw 0 0 0;
- .btn_1 {
- button {
- width: 100%;
- color: var(--fffColor);
- background-color: var(--f35BColor);
- }
- }
- .btn_1:nth-child(2) {
- button {
- background-color: var(--f0fColor);
- }
- }
- .btn_1:last-child {
- button {
- background-color: var(--fFB1Color);
- }
- }
- }
- .default {
- position: absolute;
- top: 0;
- right: 0;
- text {
- background: var(--ff0Color);
- color: var(--fffColor);
- font-size: var(--font12Size);
- padding: 1vw;
- border-radius: 5px;
- }
- }
- }
- }
- .two {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- .two_1 {
- width: 50vw;
- button {
- width: 100%;
- color: var(--fffColor);
- background-color: var(--f08Color);
- border-radius: 0;
- }
- }
- .two_1:nth-child(2) {
- button {
- background-color: var(--fFB1Color);
- }
- }
- }
- }
- .scroll-view {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .list-scroll-view {
- display: flex;
- flex-direction: column;
- }
- }
- </style>
|