index.vue 3.22 KB
Newer Older
李嘉林 committed
1 2
<template>
  <!-- 工作区域 -->
李嘉林 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
  <div class="workRegion">
    <div class="list">
      <div class="item flex" v-for="(item, index) in list" :key="index" @click="selectItem(item,index)">
        <div class="select" :class="{ selected: item.selected}">
          <i class="iconfont icon-icon_duihao-mian" v-if="item.selected"></i>
        </div>
        <div class="name">{{ item.name }}</div>
      </div>
    </div>
    <div class="seat"></div>
    <div class="btm flex">
      <div class="btn" :class="{ btn1: onInput }" @click="confirm">确定</div>
    </div>
  </div>
李嘉林 committed
17 18 19 20 21 22
</template>

<script type="text/ecmascript-6">
export default {
  name: "workRegion",
  data() {
李嘉林 committed
23 24 25 26
    return {
      list: [],
      selectList: [],
    };
李嘉林 committed
27 28
  },
  components: {},
李嘉林 committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  computed: {
    selectListIds() {
      return this.selectList.map(item=>item.id)
    },
    listIds() {
      return this.list.map(item=>item.id)
    }
  },
  onReady() {
    wx.setNavigationBarTitle({ title: "工作区域" });
  },
  onLoad() {
    console.log("---onLoad");
  },
  onShow() {
    for(let i = 0; i<20;i++){
      this.list.push({
        id:i,
        name: `云顶大酒店${i}`,
        selected: false,
      })
    }
    console.log("---onready");
    let workAreaList = wx.getStorageSync('wo-selectWorkAreaList');
    if(workAreaList){
      this.selectList = JSON.parse(workAreaList);
    }
    console.log(this.selectList,this.selectListIds,'--this.selectList')
    this.list.forEach(item=>{
      if(this.selectListIds.includes(item.id)){
        item.selected = true;
      } else {
        item.selected = false;
      }
    })
    console.log(this.list,'---------------63')
    console.log("---onShow");
  },
  methods: {
    selectItem(item,index){
      item.selected = !item.selected
      console.log(item,index,'----56')
      console.log(this.selectListIds,'----57')
      if(this.selectListIds.includes(item.id)) {
        this.selectList.splice(this.selectListIds.indexOf(item.id),1);
      } else {
        this.selectList.push(item);
      }
    },
    confirm() {
      console.log(this.selectList,'--selectList')
      wx.setStorageSync('wo-selectWorkAreaList', JSON.stringify(this.selectList));
      wx.navigateBack();
    },
  },
李嘉林 committed
84 85 86 87 88
};
</script>

<style lang="scss" scoped>
.workRegion {
李嘉林 committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
  .list {
    .item {
      padding: 18px 24px;
      border-bottom: 1px solid #d8d8d8;
      align-items: center;
      .select {
        width: 20px;
        height: 20px;
        border-radius: 20px;
        overflow: hidden;
        border: 1px solid #d8d8d8;
        i {
          font-size: 20px;
          color: #229df1;
        }
      }
      .selected {
        border-color: transparent;
      }
      .name {
        margin-left: 10px;
        flex: 1;
        font-size: 15px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #333;
      }
    }
  }
  .seat {
    width: 100%;
    height: 60px;
  }
  .btm {
    position: fixed;
    bottom: 0;
    height: 60px;
    background: #fff;
    width: 100%;
    justify-content: center;
    align-items: center;
    .btn {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 90%;
      height: 46px;
      border-radius: 4px;
      color: #fff;
      background: #229df1;
    }
  }
李嘉林 committed
140 141
}
</style>