<template>
<mu-dialog class="selDialog" width="750px" :open.sync="isShowFriDialog">
<mu-sub-header>选择好友<span style="float: right; color: #3279e5" @click="submitFriList">确定</span></mu-sub-header>
<!-- <mu-pagination v-if="friAllCount>=showCount" small :page-size="showCount" :total="friAllCount" :current.sync="currentPage" @change="showFriList"></mu-pagination> -->
<mu-sub-header>
<mu-checkbox v-model="checkedAll" label="全选" @change="changeState"></mu-checkbox>
</mu-sub-header>
<mu-list v-loading="friLoading" data-mu-loading-color="#3279e5" data-mu-loading-overlay-color="rgba(0, 0, 0, .12)">
<div class="list-wrapper" v-for="(vo, index) in friendsList[showCount]" :key="index">
<mu-list-item avatar button :ripple="false" >
<mu-list-item-action>
<mu-checkbox v-model="checkFriModel" :value="vo.friendWechatyId" @change="RecordFri($event)"></mu-checkbox>
</mu-list-item-action>
<mu-list-item-action>
<mu-avatar style="box-shadow: 0 3px 5px -1px rgba(0,0,0,.2), 0 5px 8px 0 rgba(0,0,0,.14), 0 1px 14px 0 rgba(0,0,0,.12);border: 2px solid;">
<img :src="vo.friendAvatar || ''" />
</mu-avatar>
</mu-list-item-action>
<mu-list-item-title>{{vo.friendAlias || vo.friendName}}</mu-list-item-title>
</mu-list-item>
<mu-divider></mu-divider>
</div>
</mu-list>
</mu-dialog>
</template>
<script>
import { getBotContacts } from '@/api/bot'
import { mapGetters } from 'vuex'
export default {
data() {
return {
friendsList: [],
checkedAll: false,
checkFriModel: [],
showCount: 500,
friAllCount: 0,
friLoading: false,
currentPage: 1,
isShowFriDialog: false
}
},
watch: {
checkFriModel: {
handler () {
console.log(this.checkFriModel)
let newFri = []
if(!Array.prototype.subsetTo){
Array.prototype.subsetTo=function(arr){
return this.every(v=>arr.includes(v))
}
}
this.friendsList[this.showCount].forEach(item=>{
newFri.push(item.friendWechatyId)
})
if(newFri.subsetTo(this.checkFriModel)) {
this.checkedAll = true
} else {
this.checkedAll = false
}
},
deep: true
}
},
// props: ['isShowFriDialog'],
computed: {
...mapGetters(['userId', 'botId'])
},
methods: {
// 好友全选
changeState(e) {
if (this.checkedAll == true) {
// this.checkFriModel = []
this.friendsList[this.showCount].forEach(item=>{
this.checkFriModel.push(item.friendWechatyId)
})
} else {
for(var i=0;i<this.friendsList[this.showCount].length;i++){
for(var j=0;j<this.checkFriModel.length;j++){
if(this.checkFriModel[j]==this.friendsList[this.showCount][i].friendWechatyId){
this.checkFriModel.splice(j,1);
j--;
}
}
}
}
},
submitFriList() {
this.$emit('submitFriList', this.checkFriModel)
},
RecordFri(data) {
this.friChecked = data
},
showFriList() {
console.log(this.botId)
this.isShowFriDialog = true
this.friLoading = true
if(!this.botId) return
getBotContacts({botId: this.botId, pageSize: 5000, pageNum: this.currentPage}).then(res=>{
if (res && res.status === 'success') {
var newFriList = []
this.friendsList[this.showCount] = res.data.botContactList
this.friendsList[this.showCount].forEach(item=>{
newFriList.push(item.friendWechatyId)
})
if(!Array.prototype.subsetTo){
Array.prototype.subsetTo=function(arr){
return this.every(v=>arr.includes(v))
}
}
this.checkedAll = newFriList.subsetTo(this.checkFriModel)
console.log(this.friendsList.length)
// this.friendsList = this.friendsList.concat(res.data.botContactList)
this.friAllCount = res.data.allCount
this.friLoading = false
}
})
},
hidden() {
this.isShowFriDialog = false
}
}
}
</script>
分页下的全选组件
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 公共js文件写省市区联动 ** * @param grade 2省,3市,4区 * @param regionId...
- 前言 分页其实很容易实现,我自己写了一个简单的分页组件,可以实现上下翻页,输入页码跳转到指定页,刷新页面后不会回到...