由于子组件不能直接更新props,所以传值给父组件,由父组件来更新值。
子组件
<template>
<view class="listitem" @click="goadd(item)">
<div class="listitemTitle">
<div class="listitemTitlel">{{item.CustomerName}}</div>
<div class="listitemTitler">
<div class="qiyong" @click.stop="SetUionCustomerState(0)" v-if="item.Status==1">启用</div>
<div class="jinyong" @click.stop="SetUionCustomerState(1)" v-if="item.Status==0">禁用</div>
</div>
</div>
<div class="listitemcenter">
<div class="listitemcenterl">
<div class="label">
负责人
</div>
<div class="desc">
{{item.Contacts}}
</div>
</div>
<div class="listitemcenterl">
<div class="label">
电话
</div>
<div class="desc">
{{item.Mobile}}
</div>
</div>
</div>
<div class="address">
{{item.Address}}
</div>
<showToast ref="showToast"></showToast>
</view>
</template>
<script>
import {
SetUionCustomerState
} from '@/config/api.js'
export default {
components: {},
data() {
return {
CompanyId: 0,
style: {
// 字符串的形式
p: 'font-size:28rpx;',
span: 'font-size: 28rpx;',
}
}
},
props: {
item: {
type: Object,
default () {
return {};
}
}
},
computed: {
},
mounted() {
this.AccountId = JSON.parse(uni.getStorageSync('userData')).Id
},
methods: {
SetUionCustomerState(State) {
var that = this;
SetUionCustomerState({
params: {
AccountId: that.AccountId,
Id: that.item.Id,
State: State,
},
custom: {
auth: true
}
}).then(res => {
if (res.Code == 200) {
that.$refs['showToast'].success('状态更新成功');
that.$emit('getdata', State)
}
}).catch(err => {
})
},
goadd(item) {
uni.setStorageSync('companyManagementData', item)
uni.navigateTo({
url: '/pages/home/enterprise/companyManagement/add/add'
})
},
gettype(e) {
console.log(e)
this.type = e.value[0]
}
}
}
</script>
<style scoped lang="scss">
.listitem {
margin: 0 auto;
width: calc(694rpx - 64rpx);
background: #FFFFFF;
border-radius: 20rpx;
padding: 32rpx;
margin-bottom: 24rpx;
.listitemTitle {
font-size: 32rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #272A5F;
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
}
.listitemcenter {
width: 630rpx;
height: 139rpx;
background: rgba(#4087FF, 0.05);
border-radius: 12rpx;
margin-top: 28rpx;
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
.listitemcenterl {
width: calc(50% - 32rpx);
margin-left: 32rpx;
.label {
font-size: 24rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #6F7197;
}
.desc {
font-size: 30rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #141852;
}
}
.listitemcenterl:nth-child(1) {
border-right: 1rpx solid #E8EBF2;
}
}
.address {
font-size: 26rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #5B5D85;
margin-top: 28rpx;
}
}
.qiyong {
width: 72rpx;
height: 40rpx;
background: rgba(26, 196, 81, 0.05);
border-radius: 8rpx;
border: 2rpx solid #D2F0DC;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
background: #F5FCF8;
font-size: 24rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #45C36F;
flex-direction: row;
align-content: flex-start;
}
.jinyong {
width: 72rpx;
height: 40rpx;
background: rgba(26, 196, 81, 0.05);
border-radius: 8rpx;
border: 2rpx solid #FEC8C7;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
background: #FFF3F3;
font-size: 24rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #FA1B1B;
flex-direction: row;
align-content: flex-start;
}
</style>
父组件
<item @getdata="getStatus($event,index)" :item="item" v-for="(item,index) in list" :key="index"></item>
getStatus(e, index) {
this.list[index].Status = e
this.$forceUpdate()
},