分頁下的全選組件

<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>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末瘫辩,一起剝皮案震驚了整個濱河市喘鸟,隨后出現(xiàn)的幾起案子例嘱,更是在濱河造成了極大的恐慌豪直,老刑警劉巖谓着,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異摧冀,居然都是意外死亡蹬跃,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門茂嗓,熙熙樓的掌柜王于貴愁眉苦臉地迎上來餐茵,“玉大人,你說我怎么就攤上這事述吸》拮澹” “怎么了?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵蝌矛,是天一觀的道長道批。 經(jīng)常有香客問我,道長入撒,這世上最難降的妖魔是什么隆豹? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮茅逮,結(jié)果婚禮上璃赡,老公的妹妹穿的比我還像新娘判哥。我一直安慰自己,他們只是感情好碉考,可當(dāng)我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布塌计。 她就那樣靜靜地躺著,像睡著了一般侯谁。 火紅的嫁衣襯著肌膚如雪锌仅。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天墙贱,我揣著相機與錄音热芹,去河邊找鬼。 笑死惨撇,一個胖子當(dāng)著我的面吹牛伊脓,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播串纺,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼丽旅,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了纺棺?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤邪狞,失蹤者是張志新(化名)和其女友劉穎祷蝌,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體帆卓,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡巨朦,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了剑令。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片糊啡。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖吁津,靈堂內(nèi)的尸體忽然破棺而出棚蓄,到底是詐尸還是另有隱情,我是刑警寧澤碍脏,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布梭依,位于F島的核電站,受9級特大地震影響典尾,放射性物質(zhì)發(fā)生泄漏役拴。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一钾埂、第九天 我趴在偏房一處隱蔽的房頂上張望河闰。 院中可真熱鬧科平,春花似錦、人聲如沸姜性。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽污抬。三九已至汞贸,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間印机,已是汗流浹背矢腻。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留射赛,地道東北人多柑。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像楣责,于是被迫代替她去往敵國和親竣灌。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容