ReedawFoodApp/body/my/manage.vue

223 lines
4.5 KiB
Vue

<template>
<view class="common">
<view class="add" @click="handleAddUser">
<icon class="iconfont icon-tianjia"></icon>{{$t('titleManageAdd')}}
</view>
<view class="box" v-if="familayList.lenght!=0">
<view class="list">
<uni-swipe-action>
<uni-swipe-action-item v-for="(item ,index) in familayList" :key="index"
:right-options="item.options" @click="handleDeldet($event, index)">
<view class="item">
<view class="left">
<image :src="item.head_pic" class="image1" />
<view class="name">
<view class="title">
{{item.nickname}}
</view>
<view class="title2">
<text>{{item.gender==1?$t('infoMan'):$t('infoWoman')}}</text>
<text>{{item.age}}{{$t('infoAgeunit')}}</text>
</view>
</view>
</view>
<view class="right" @click.stop>
<view class="blueBtn" @click="editorInfo(item)">{{$t('btnEdit')}}</view>
</view>
</view>
</uni-swipe-action-item>
</uni-swipe-action>
</view>
</view>
<view v-else>
{{$t("noMoreData")}}
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
export default {
data() {
return {
id: ""
}
},
computed: {
...mapState(["familayList"])
},
onPullDownRefresh() {
let that = this
that.handleUserList()
setTimeout(() => {
uni.stopPullDownRefresh()
}, 1000);
},
methods: {
//删除
handleDeldet(e, ind) {
let that = this
that.id = that.familayList[ind].id
uni.showModal({
title: that.$t('msgTitle'),
content: that.$t("verifyDeleteUser"),
cancelText: that.$t('btnSancellation'),
confirmText: that.$t('btnConfirm'),
success: function(res) {
if (res.confirm) {
that.$model.getDelUser({
aud_id: that.id,
}).then(res => {
if (res.code != 0) return
that.$tools.msg(that.$t('msgDelete'));
that.familayList.splice(ind, 1)
that.handleUserList()
})
} else if (res.cancel) {
that.$tools.msg(that.$t('msgCancel'));
}
}
});
},
handleUserList() {
let that = this
that.$model.getUserList({
type: 2
}).then(res => {
if (res.code != 0) {
that.$tools.msg(res.msg)
return
}
that.$store.commit('changeFamilay', res.data.user_list)
console.log("删除", that.id, uni.getStorageSync('userid'))
// 删除的是当前用户
if (that.id == uni.getStorageSync('userid')) {
let userid = res.data.user_list[0].id
uni.setStorageSync('userid', userid)
that.$store.dispatch('getUserInfo', {
aud_id: userid
})
// 厨房秤接口
that.$store.dispatch("getCountFoodInfo", {
aud_id: userid,
time: that.$tools.getDate("start")
})
// 全部卡片
that.$store.dispatch("getCardAllList", {
aud_id: userid
})
//
that.$store.dispatch("getResult", {
aud_id: userid
})
that.$store.dispatch("getPublicRecord", {
aud_id: userid
})
}
}).catch(err => {})
},
//编辑
editorInfo(item) {
uni.navigateTo({
url: "/body/my/userInfo?info=" + JSON.stringify(item)
})
},
//添加
handleAddUser() {
uni.navigateTo({
url: "/body/my/userInfo"
})
},
}
}
</script>
<style scoped="scoped" lang="scss">
.common {
padding: 15px;
background-color: #f7f7f7;
min-height: calc(100vh - 30px);
}
.add {
width: 100%;
height: 40px;
line-height: 40px;
font-size: 32rpx;
margin-bottom: 10px;
color: #fff;
border-radius: 15px;
display: flex;
justify-content: center;
background: $btncolor;
}
.box {
width: 100%;
height: auto;
margin: 15px 0;
padding-bottom: 40px;
}
.list {
width: 100%;
font-size: 36rpx;
.item {
background: #fff;
padding: 10px 15px;
width: calc(100% - 30px);
border-radius: 10px;
margin-top: 15px;
display: flex;
align-items: center;
justify-content: space-between;
}
.left {
width: 75%;
display: flex;
align-items: center;
.image1 {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
margin-right: 15px;
display: block;
}
.name {
width: calc(100% - 70px);
.title {
font-size: 34rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-top: 5px;
}
.title2 {
font-size: 32rpx;
color: #999;
margin-top: 15px;
text {
margin-right: 10px;
}
}
}
}
.blueBtn {
width: auto;
font-size: 32rpx;
text-align: center;
}
}
</style>