<template>
  <div class="div_item">
    <div class="div_item_title" @click="onClickArrow">
      <img :src="imgCheck" @click.stop="onClickTotal" width="20px" height="20px"/>
      <span class="span_value" style="margin-left: 20px">{{data.billName}}</span>
      <span class="span_value" style="flex: 1;display: flex;justify-content: flex-end;margin-right: 20px">合计  ¥  {{data.detailTotalMoney}}</span>
      <img :src="imgArrow"  width="20px" height="20px"/>
    </div>
    <div class="div_item_price" v-for="(item,index) in data.billDetailList" :key="index" v-if="imgArrowed">
      <div class="div_item_price_content">
        <img :src="imgCheckItem(item.value)" @click.stop="onClickItem(index)" width="20px" height="20px"/>
        <span class="span_value_light" style="margin-left: 20px;flex: 1">{{item.chargePeriod}}</span>
        <span class="span_value_light" style="display: flex;justify-content: flex-end;">¥  {{item.actualMoney}}</span>
      </div>
      <div class="line_h"></div>
    </div>
  </div>
</template>

<script>
  import CheckIcon from "vux/src/components/check-icon/index";
  export default {
    name: "mobileChargeItem",
    components: {CheckIcon},
    data(){
      return{
        totalCheck:false,
        imgChecked:true,
        imgArrowed:true,
      }
    },
    props:{
      data:{
        type:Object,
      }
    },
    computed:{
      imgCheck(){
        if (this.imgChecked){
          return require("../../assets/images/check_circle.png");
        }
        return require("../../assets/images/icon_uncheck_circle.png");
      },
      imgCheckItem(value){
        return function (value) {
          if (value){
            return require("../../assets/images/check_circle.png");
          }
          return require("../../assets/images/icon_uncheck_circle.png");
        }

      },

      imgArrow(){
        if (this.imgArrowed){
          return require("../../assets/images/common/icon_up_arrow.png");
        }
        return require("../../assets/images/common/icon_down_arrow.png");
      },


    },
    methods:{
      onClickTotal(){
        this.imgChecked = !this.imgChecked;
        for (let i = 0;i<this.data.billDetailList.length;i++){
          this.data.billDetailList[i].value = this.imgChecked;
        }
        this.$emit("onClickChargeItem");
      },
      onClickArrow(){
        this.imgArrowed = !this.imgArrowed;
      },
      onClickItem(index){
        this.data.billDetailList[index].value = !this.data.billDetailList[index].value;
        let count = 0;
        for (let i = 0; i < this.data.billDetailList.length; i++) {
          if (this.data.billDetailList[i].value) {
            count++;
          }
        }
        if (count === this.data.billDetailList.length) {
          this.imgChecked = true;
        } else {
          this.imgChecked = false;
        }
        this.$emit("onClickChargeItem");
      }

    },

  }
</script>

<style scoped>
  .div_item{
    display: flex;
    flex-direction: column;
  }
  .div_item_title{
    display: flex;
    flex-direction: row;
    background-color: #F9F9F9;
    padding: 10px 20px;
    align-items: center;
  }
  .div_item_price{
    display: flex;
    flex-direction: column;
    background-color: white;
    margin: 10px 20px 0;
  }
  .div_item_price_content{
    display: flex;
    flex-direction: row;
    margin: 0 20px 10px;
  }

  .span_value{
    color: #333333;
    font-size: 14px;
    display: flex;
    flex: 1;
  }
  .span_value_light{
    color: #999999;
    font-size: 14px;
    display: flex;
    flex: 1;
  }

  .check_button{
    width: 20px;
    height: 20px;
  }
  .line_h{
    width: 100%;
    background-color: #e8e8e8;
    height: 1px;
    transform-origin: 0 100%;
    transform: scaleY(0.5);
  }
</style>
