<template>
  <div>
    <div class="shopping_list_page">
      <ShoppingCartCell
        :ref="`cartcell_${index}`"
        v-for="(item, index) in list"
        :cellItem="item"
        :cellIsService="item.app_id == 0"
        :cellIndex="index"
        :cellCheck="checkLists[index]"
        :key="item.id"
        :readOnly="readOnly"
        @changeState="changeState"
        @changeCellMsg="changeCellMsg"
        @deleteItem="deleteItem"
        @updateList="updateList"
      />
    </div>
  </div>
</template>

<script>
import ShoppingCartCell from "@/components/shopping-cart/shopping-cart-cell";
export default {
  components: {
    ShoppingCartCell
  },
  props: {
    readOnly: {
      type: Boolean,
      default: false
    },
    checkShopAll: {
      type: Boolean
    },
    list: {
      type: Array
    },
    checkList: {
      type: Array
    }
  },
  watch: {
    checkList: {
      immediate: true, // 这句重要
      handler(val) {
        this.checkLists = val;
      }
    }
  },
  data: () => ({
    checkedAll: false,
    checkLists: []
  }),
  mounted() {},
  methods: {
    changeState(val) {
      this.$emit("changeState", val);
    },
    setAllState(val) {
      for (let i = 0; i < this.checkLists.length; i++) {
        this.$set(this.checkLists, i, val);
        this.$refs["cartcell_" + i][0].getState(val);
      }
    },
    changeCellMsg(val) {
      this.$emit("changeCellMsg", val);
    },
    deleteItem(val) {
      this.$emit("deleteItem", val);
    },
    updateList() {
      this.$emit("updateList")
    }
  }
};
</script>
