<template>
  <div class="page_consumable">
    <div class="consumableList">
      <van-list v-if="list.length > 0">
        <div class="consumableListOne" v-for="(item,index) in list" :key="index">
          <p v-for="subItem,index in item.good_type" :key="index">
            {{subItem.id == 0? subItem.name:subItem.name+": "}}
            <span style="color:#258ffc">{{ getGoodUserInfo(subItem.id,item.good_user,item.last_good_user, item.good_user_detail,item.last_good_user_detail,item.prescription) }}</span>
          </p>

        </div>
      </van-list>
      <div class="noimgBox" v-else>
        <img src="../../../../assets/images/none.png" alt />
      </div>
    </div>
    <img class="statisticsImg" @click="toDetail" src="@/assets/images/statistics.png" />
  </div>
</template>

<script>
  import {getDialysisGoods} from '@/api/dialysis'

  export default {
    props: {
      query: Object,
      list: Array,
      goodInfo: Array,
      total: Number,
      zone_selected: Number,
      schedual_type_selected: Number,
      partition_id:Number,
    },
    data() {
      return {
        loading: false,
        finished: false,

      }
    },
    methods: {
      getGoodUserInfo(good_type_id, good_user, last_good_user, good_user_detail, last_good_user_detail,prescription) {
        // console.log("good_type_id",good_type_id)
        
        if (good_user != null && good_user.length > 0) {
          let desc = ""
          for (let b = 0; b < good_user.length; b++) {
            if (good_type_id == good_user[b].good_type_id)
              desc = desc + " " + good_user[b].info.specification_name + "*" + good_user[b].count
          }
          return desc
       
        }else{
          if(good_type_id == 9741){
            return prescription.dialysis_dialyszers
          }
          if(good_type_id == 9742){
            return  prescription.dialysis_irrigation
          }

          if(good_type_id == 9743){
            return prescription.dialysis_strainer
          }
          if(good_type_id ==9748){
            return prescription.dialysis_dialyszers
          }
          if(good_type_id ==9749){
            return prescription.dialysis_irrigation
          }
          if(good_type_id ==9750){
            return prescription.dialysis_strainer
          }
          
          if(good_type_id == 9769){
            return prescription.dialysis_dialyszers
          }

          if(good_type_id == 9770){
            return prescription.dialysis_irrigation
          }

          if(good_type_id == 9774){
            return prescription.dialysis_strainer
          }

          if(good_type_id == 9775){
            return prescription.dialysis_dialyszers
          }
          if(good_type_id ==9776){
            return prescription.dialysis_strainer
          }
          if(good_type_id == 9777){
            return prescription.dialysis_irrigation
          }

          if(good_type_id == 10275){
            return prescription.dialysis_dialyszers
          }
          if(good_type_id == 10277){
            return prescription.dialysis_irrigation
          }
          if(good_type_id == 10278){
            return prescription.dialysis_strainer
          }
        }
        
      },
      // GetDialysisGoods() {
      //   var newDate = new Date();
      //   var y = newDate.getFullYear();
      //   var m = newDate.getMonth() + 1;
      //   var d = newDate.getDate();
      //   var schedule_date =
      //     y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
      //   let params = {
      //     schedule_date:schedule_date,
      //     schedule_type:0,
      //     partition_id:0,
      //     page:1,
      //   }
      //   getDialysisGoods(params).then(rs => {
      //     var res = rs.data
      //     if (res.state == 1) {
      //       this.list = []
      //       for(let i = 0; i < res.data.dialysis_goods.length; i++){
      //           let arr =[]
      //           let obj = {
      //             id:0,
      //             name:"姓名：" + res.data.dialysis_goods[i].patient.name
      //           }
      //           arr.push(obj)
      //
      //           for (let a = 0; a <  res.data.good_type.length; a++){
      //             let obj = {
      //               id:res.data.good_type[a].id,
      //               name:res.data.good_type[a].type_name,
      //             }
      //             arr.push(obj)
      //           }
      //         this.list.push(arr)
      //
      //       }
      //
      //       var zoneMap = {}
      //       var schedualMap = {}
      //       for (let index = 0; index < res.data.dialysis_goods.length; index++) {
      //         const schedual = res.data.dialysis_goods[index]
      //         if (schedual.dialysis_order == null) {
      //           continue
      //         }
      //         if (schedualMap[schedual.device_number.zone.name] == null) {
      //           schedualMap[schedual.device_number.zone.name] = []
      //         }
      //         schedualMap[schedual.device_number.zone.name].push(schedual)
      //         if (zoneMap[schedual.device_number.zone.name] == null) {
      //           zoneMap[schedual.device_number.zone.name] =
      //             schedual.device_number.zone
      //         }
      //       }
      //
      //       var zones = []
      //       zones.push({ value: 0, text: '全部分区' })
      //       for (var zoneName in zoneMap) {
      //         zones.push({ value: zoneMap[zoneName].id, text: zoneName })
      //       }
      //
      //       zones = zones.sort(function (a, b) {
      //         return a.value > b.value
      //       })
      //       this.zones = zones
      //       // console.log('this.zones',this.zones)
      //
      //       // eslint-disable-next-line camelcase
      //       var dialysis_scheduals = []
      //       for (let index = 0; index < zones.length; index++) {
      //         const zone = zones[index]
      //         // eslint-disable-next-line no-redeclare
      //         var scheduals = schedualMap[zone.text]
      //         if (scheduals == null) {
      //           continue
      //         }
      //         dialysis_scheduals.push({
      //           zone_name: zone.text,
      //           scheduals: scheduals
      //         })
      //       }
      //
      //
      //
      //     }
      //   })
      //
      //
      // },
      onLoad() {
        // 异步更新数据
        // setTimeout 仅做示例，真实场景中一般为 ajax 请求
        setTimeout(() => {
          this.query.page++;
          if (this.query.page <= Math.ceil(this.total / 10)) {
            this.getAllGroup(this.query);
          } else {
            this.loading = false;
            this.finished = true;
          }
        }, 1000);
      },
      toDetail() {
        if(this.$store.getters.user.template_info.org_id != 10579 && this.$store.getters.user.template_info.org_id != 10587 && this.$store.getters.user.template_info.org_id != 10597 && this.$store.getters.user.template_info.org_id != 10599  && this.$store.getters.user.template_info.org_id != 10742){
          this.$router.push("/consumablesDetail");
        }else{
          console.log("2332o32o3223o",this.partition_id)
          this.$router.push("/consumablesDetailOne?zone_selected="+this.zone_selected +"&schedual_type_selected="+this.schedual_type_selected+"&partion_id="+this.partition_id);
        }
       
      }
    },
    created() {
       console.log("元旦",this.list)
     
    }
  }
</script>


<style lang="scss" scoped>
  .page_consumable {
    font-size: 0.5rem;

  .consumableListOne {
    padding: 0.66rem;
    display: flex;
    flex-wrap: wrap;
    border-bottom: 1px solid #e5e5e5;
    color:#313234;

  > p {
    width: 50%;
    line-height: 0.8rem;
  }

  }
  .statisticsImg{
    position: fixed;
    bottom: 0.625rem;
    right: 0.2rem;
    width: 1.875rem;
    height: 1.875rem;
  }
  }
  .noimgBox {
    margin-top: 40%;
    img {
      width: 5rem;
      height: 5rem;
      margin: 0 auto;
      display: block;
    }
  }

</style>
