ResourcePopup.vue 4.14 KB
<template>
  <van-popup
    v-model="show"
    round
    position="bottom"
    class="popup"
    @close="close"
  >
    <div class="content">
      <div class="title flex">
        {{obj.codeState}}
        <div
          class="all flex"
          @click="selectAll"
        >
          <template v-if="all">
            <div class="sprite-icon icon-active"></div>
          </template>
          <template v-else>
            <div class="radio"></div>
          </template>
          全选
        </div>
      </div>
      <div class="img-box">
        <template v-for="(item,index) in obj.imgList">
          <div
            :key="index"
            class="item"
            @click="choose({item,index})"
          >
            <img :src="item.autoUrl">
            <div class="radio-box">
              <template v-if="item.active">
                <div class="sprite-icon icon-active"></div>
              </template>
              <template v-else>
                <div class="radio"></div>
              </template>
            </div>
          </div>
        </template>
      </div>
      <div class="footer flex">
        <div
          class="cancel text-center"
          @click="close"
        >取消</div>
        <div class="confirm text-center">确定</div>
      </div>
    </div>
  </van-popup>
</template>

<script type='text/ecmascript-6'>
export default {
  name: 'ResourcePopup',
  props: {
    value: Boolean,
    data: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      show: false,
      obj: {},
      all: false
    }
  },
  watch: {
    value(n) {
      this.show = n
    },
    data(n) {
      console.log('123', n)
      this.obj = n
      this.checkAll()
    }
  },
  mounted() {},
  methods: {
    choose({ item, index }) {
      item.active = !item.active
      this.$set(this.obj.imgList, index, item)
      this.checkAll()
    },
    checkAll() {
      let { imgList } = this.obj
      try {
        imgList.map(e => {
          if (!e.active) throw false
        })
      } catch (error) {
        this.all = error
        return
      }
      this.all = true
    },
    selectAll() {
      let {
        all,
        obj: { imgList }
      } = this
      imgList.map(e => (e.active = !all))
      this.all = !all
      this.obj.imgList = imgList
    },
    close() {
      this.show = false
      this.$emit('close')
    }
  }
}
</script>

<style scoped lang='scss'>
.popup {
  height: 510px;
  .content {
    height: 100%;
    .title {
      height: 56px;
      padding: 0 16px;
      font-weight: 500;
      font-size: 16px;
      color: #333333;
      .all {
        margin-left: auto;
        font-weight: 400;
        color: #3a3a3a;
        font-size: 14px;
        .radio {
          width: 20px;
          height: 20px;
          box-sizing: border-box;
          border: 1.5px solid #999999;
          border-radius: 100%;
          overflow: hidden;
        }
        .sprite-icon,
        .radio {
          margin-right: 4px;
        }
      }
    }
    .img-box {
      padding: 4px 26px;
      display: flex;
      flex-wrap: wrap;
      box-sizing: border-box;
      height: 405px;
      overflow-y: scroll;
      .item {
        width: 102px;
        height: 102px;
        margin-bottom: 10px;
        margin-right: 8px;
        position: relative;
        &:nth-of-type(3n + 3) {
          margin-right: 0;
        }
        .radio-box {
          position: absolute;
          bottom: 2px;
          right: 2px;
          .radio {
            width: 20px;
            height: 20px;
            background: #999999;
            box-sizing: border-box;
            border: 1.5px solid #fff;
            border-radius: 100%;
            overflow: hidden;
          }
        }
      }
    }
    .footer {
      height: 49px;
      padding: 0 16px;
      justify-content: space-between;
      div {
        width: 164px;
        height: 38px;
        border: 1px solid transparent;
        font-size: 14px;
        border-radius: 100px;
      }
      .cancel {
        border-color: #dcdee0;
        color: #323233;
      }
      .confirm {
        border-color: #3975C6;
        color: #fff;
        background: #3975C6;
      }
    }
  }
}
</style>