<template>
  <!-- 报工详情 -->
  <div>
    <div class="" v-if="taskType != 5">
      <div v-for="(objData, index) in list" :key="index" class="card_box">
        <div class="rx-bc">
          <div class="item_box rx-bc">
            <div class="round">{{ index + 1 }}</div>
            <div class="time"
              >报工时间:<span v-if="objData.workReportInfo.executorStartTime">
                {{ objData.workReportInfo.executorStartTime }}- </span
              ><span>{{
                objData.workReportInfo
                  ? objData.workReportInfo.executorTime
                  : ''
              }}</span>
              <span
                style="margin-left: 10px"
                v-if="objData.workReportInfo.workTime"
                >工时：{{ objData.workReportInfo.workTime }}小时</span
              >
            </div>
            <!-- <div v-if="objData.workReportInfo.executorStartTime"></div> -->
          </div>

          <div class="item_box rx-bc">
            <div class="time"
              >工序名称：
              {{
                objData.currentTaskDiagram &&
                objData.currentTaskDiagram.taskTypeName
              }}</div
            >
          </div>
        </div>

        <div class="rx-bc">
          <div class="item_box rx-bc">
            <div class="time"
              >报工人:{{
                objData.workReportInfo
                  ? objData.workReportInfo.executorName
                  : ''
              }}
            </div>
          </div>

          <div class="item_box rx-bc">
            <div
              class="time"
              v-if="
                objData.workReportInfo.executorList &&
                objData.workReportInfo.executorList.length != 0
              "
              >执行人:<span v-for="item in objData.workReportInfo.executorList"
                >【{{ item.name }}】</span
              >
            </div>
          </div>
        </div>

        <paramBom
          v-if="objData.paramDetailList.length != 0"
          :list="objData.paramDetailList"
        ></paramBom>
        <div>
          <workOrderBom
            :item="objData"
            v-if="objData"
            :isDetails="true"
            :isReportWork="true"
          ></workOrderBom>
          <jobBom
            :item="objData"
            v-if="objData.notFormedList"
            :palletList="objData.palletList"
            :notFormed="objData.notFormedList"
            :isDetails="true"
          ></jobBom>

          <deviceBom
            v-if="objData.equipmentList && objData.equipmentList.length != 0"
            :list="objData.equipmentList"
          >
          </deviceBom>

          <modelBom
            v-if="objData.modelList && objData.modelList.length != 0"
            :list="objData.modelList"
          >
          </modelBom>
          <!--
          <qualityStat
            :normalQuality="objData.normalQuality"
            v-if="objData && taskType == 3"
          ></qualityStat> -->

          <!-- <sampleBom
            :item="objData.quality"
            v-if="objData.quality && taskType == 2"
            :workReportInfo="objData.workReportInfo"
            :isDetails="true"
          ></sampleBom> -->

          <palletBom
            v-if="objData.palletList && objData.palletList.length != 0"
            :palletList="objData.palletList"
            :isDetails="true"
          >
          </palletBom>

          <revolvingDiskBom
            v-if="
              objData.revolvingDiskList && objData.revolvingDiskList.length > 0
            "
            pattern="job"
            :revolvingDiskList="objData.revolvingDiskList"
          ></revolvingDiskBom>

          <!-- //单件报工 -->
          <semiProductJobBom
            v-if="
              objData.semiProductList &&
              objData.semiProductList.length != 0 &&
              objData.singleReport == 1 &&
              clientEnvironmentId != 3
            "
            :list="objData.semiProductList"
            :item="objData"
            :isDetails="true"
            :singleReport="objData.singleReport"
            :equipmentList="objData.equipmentList"
          >
          </semiProductJobBom>

          <!-- 碳谷单件报工 -->
          <semiProductJobBom
            v-if="
              objData.semiProductList &&
              objData.semiProductList.length != 0 &&
              objData.singleReport == 1 &&
              clientEnvironmentId == 3 &&
              taskType != 4
            "
            :list="objData.semiProductList"
            :item="objData"
            :isDetails="true"
            :singleReport="objData.singleReport"
            :equipmentList="objData.equipmentList"
          >
          </semiProductJobBom>

          <!-- 批量报工 -->

          <batchSemiProductJobBom
            v-if="
              objData.product &&
              objData.product.length != 0 &&
              clientEnvironmentId != 3 &&
              objData.singleReport == 0
            "
            :list="objData.product"
            :item="objData"
            :isDetails="true"
            :singleReport="objData.singleReport"
            :equipmentList="objData.equipmentList"
          >
          </batchSemiProductJobBom>

          <!-- 批量报工 -->
          <semiProductJobBomPL
            v-if="
              objData.semiProductList &&
              objData.semiProductList.length != 0 &&
              objData.singleReport == 0 &&
              taskType != 6 &&
              clientEnvironmentId == 3
            "
            :list="objData.semiProductList"
            :item="objData"
            :equipmentList="objData.equipmentList"
            :isDetails="true"
            :singleReport="objData.singleReport"
          >
          </semiProductJobBomPL>

          <!-- <oneJobQualityBom v-if="
            objData.semiProductList &&
            (objData.semiProductList.length != 0) && (taskType == 6) && clientEnvironmentId == 3 && objData.singleReport == 1
          " :list="objData.semiProductList" :item="objData" :isDetails="true"></oneJobQualityBom> -->

          <oneJobQualityBomPL
            v-if="
              objData.currentTaskDiagram.type == 6 &&
              clientEnvironmentId == 3 &&
              objData.singleReport == 0
            "
            :list="objData.semiProductList"
            :item="objData"
            :isDetails="true"
          ></oneJobQualityBomPL>

          <byProductBom
            v-if="
              objData.productRecycleList &&
              objData.productRecycleList.length != 0
            "
            :list="objData.productRecycleList"
            :isDetails="true"
          >
          </byProductBom>

          <turnoverBom
            v-if="objData.turnover && objData.turnover.length != 0"
            :list="objData.turnover"
            :wordItem="objData"
            pattern="job"
            :isDetails="true"
          >
          </turnoverBom>

          <aridRegion
            v-if="objData.aridRegionList && objData.aridRegionList.length != 0"
            :list="objData.aridRegionList"
            :remainingTime="0"
            :isType="true"
          ></aridRegion>

          <div
            v-if="
              objData &&
              objData.currentTaskDiagram.type == 4 &&
              clientEnvironmentId == 3 &&
              objData.singleReport == 0
            "
          >
            <detailPackagingGrouping
              ref="packagingGroupingRef"
              :objData="objData"
              :workOrderId="objData.workOrderId"
              :taskId="objData.currentTaskDiagram.taskId"
              :isDetails="true"
            >
            </detailPackagingGrouping>
          </div>

          <div
            v-if="
              objData &&
              objData.currentTaskDiagram.type == 4 &&
              clientEnvironmentId != 3
            "
          >
            <!-- <packagingGrouping
              ref="packagingGroupingRef"
              :objData="objData"
              :workOrderId="objData.workOrderId"
              :taskId="objData.currentTaskDiagram.taskId"
            >
            </packagingGrouping> -->

            <detailPackagingGrouping
              ref="packagingGroupingRef"
              :objData="objData"
              :workOrderId="objData.workOrderId"
              :taskId="objData.currentTaskDiagram.taskId"
              :isDetails="true"
            >
            </detailPackagingGrouping>
          </div>

          <div
            v-if="
              planValue == 1 &&
              (taskType == 2 || taskType == 3 || taskType == 6)
            "
          >
            <detailsIndex
              :code="objData.code"
              :taskId="objData.currentTaskDiagram.sourceTaskId"
              :isDetails="true"
            >
            </detailsIndex>
          </div>

          <packingTgBom
            v-if="
              objData.packInfo &&
              objData.packInfo.pickOutInList &&
              objData.singleReport == 1 &&
              taskType == 4 &&
              clientEnvironmentId == 3
            "
            :list="objData.packInfo.pickOutInList"
            :isWarehousing="true"
            :isDetails="true"
            :item="objData"
          >
          </packingTgBom>

          <!-- <div
            v-if="
              taskType == 4 &&
              clientEnvironmentId != 3 &&
              objData.semiProductList.length != 0
            "
          >
            <semiProductJobBom
              :singleReport="objData.singleReport"
              :item="objData"
              :isDetails="true"
              :list="
                taskType == 4 ? objData.pickOutInList : objData.semiProductList
              "
              :equipmentList="objData.equipmentList"
            ></semiProductJobBom>
          </div> -->
        </div>
      </div>
    </div>

    <div v-if="taskType == 5">
      <div class="card_box" v-for="(objData, index) in list" :key="index">
        <div class="rx-bc">
          <div class="item_box rx-bc">
            <div class="round">{{ index + 1 }}</div>
            <div class="time">报工时间:{{ objData.executorTime }} </div>
          </div>

          <div class="item_box rx-bc">
            <div class="time">报工人:{{ objData.executorName }} </div>
          </div>

          <div class="item_box rx-bc">
            <div class="time">工序名称：入库</div>
          </div>
        </div>
        <!-- <div class="rx-bc">
          <div class="item_box rx-bc">
            <div class="round">{{ index + 1 }}</div>
            <div class="time">报工时间:{{ objData.executorTime }} </div>
          </div>

          <div class="item_box rx-bc">
            <div class="time">报工人:{{ objData.executorName }} </div>
          </div>

          <div class="item_box rx-bc">
            <div class="time"
              >工序名称：入库</div
            >
          </div>
        </div> -->

        <workOrderBom2
          :item="objData"
          v-if="objData"
          :isDetails="true"
        ></workOrderBom2>
        <div v-if="objData.detailList && objData.detailList.length">
          <detailsBom :list="objData.detailList" :isDetails="true"></detailsBom>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { listWorkReport, listApplystorage } from '@/api/produce/workOrder';
  import { parameterGetByCode } from '@/api/system/dictionary-data';
  import workOrderBom from '../feeding/components/workOrderBom.vue';
  import deviceBom from '../feeding/components/deviceBom.vue';
  import modelBom from '../feeding/components/modelBom.vue';
  import jobBom from '../jobBooking/components/jobBom.vue';

  import semiProductJobBom from '../jobBooking/components/semiProductJobBom.vue';
  import semiProductJobBomPL from '../jobBooking/components/semiProductJobBomPL.vue';
  import batchSemiProductJobBom from './components/batchSemiProductJobBom.vue';
  import oneJobQualityBom from '../jobBooking/components/oneJobQualityBom.vue';
  import oneJobQualityBomPL from '../jobBooking/components/oneJobQualityBomPL.vue';
  import packagingGrouping from './components/packagingGrouping.vue';
  import detailPackagingGrouping from './components/detailPackagingGrouping.vue';

  // import byProductBom from '../jobBooking/components/byProductBom';
  import byProductBom from '../jobBooking/components/newByProductBom.vue';
  import turnoverBom from '../jobBooking/components/turnoverBom.vue';
  import aridRegion from '../feeding/components/aridRegion.vue';
  import paramBom from '../feeding/components/paramBom.vue';

  //   import qualityStat from '../sample/components/qualityStat.vue';
  //   import sampleBom from '../sample/components/sampleBom.vue';
  import palletBom from '../feeding/components/palletBom.vue';

  import revolvingDiskBom from '../feeding/components/revolvingDiskBom.vue';
  import packingTgBom from '../jobBooking/components/packingTgBom.vue';

  //   import packingBom from '../jobBooking/components/packingBomDetails.vue';

  import detailsBom from '../warehousing/components/detailsBom.vue';
  import workOrderBom2 from '../warehousing/components/workOrderBom.vue';
  import detailsIndex from '../workPlan/detailsIndex.vue';
  import { getList } from '@/api/inspectionWork';

  export default {
    components: {
      workOrderBom,
      workOrderBom,
      deviceBom,
      modelBom,
      jobBom,

      semiProductJobBom,
      semiProductJobBomPL,
      oneJobQualityBom,
      oneJobQualityBomPL,

      byProductBom,
      turnoverBom,
      aridRegion,
      paramBom,

      //   qualityStat,
      //   sampleBom,
      palletBom,
      revolvingDiskBom,
      packingTgBom,
      //   packingBom,

      detailsBom,
      workOrderBom2,
      batchSemiProductJobBom,
      packagingGrouping,
      detailsIndex,
      detailPackagingGrouping
    },
    props: {
      // 工单信息对象 包含id 工单id
      routeObj: {
        type: Object,
        default() {
          return {};
        }
      },
      // taskId 工序id
      newId: {
        type: String,
        default: ''
      },
      // 包含 taskId 和 type(taskType)
      curTaskObj: {
        type: Object,
        default() {
          return () => {};
        }
      }
    },

    watch: {
      curTaskObj: {
        handler(obj) {
          if (obj && obj.taskId != -2) {
            if (obj.taskId == '-1') {
              this.taskType = 5;
            } else {
              this.taskType = obj.type;
            }
            this.getList();
          }
        },
        deep: true,
        immediate: true
      },
      newId: {
        handler(newval) {
          this.newIdTo = newval;
        },
        deep: true,
        immediate: true
      }
    },

    computed: {
      clientEnvironmentId() {
        return this.$store.state.user.info.clientEnvironmentId;
      }
    },

    data() {
      return {
        taskType: null,
        list: [],
        newIdTo: '',
        planValue: ''
      };
    },

    created() {
      this.getPlanCode();
      // this.get;
      // console.log(this.curTaskObj, 'curTaskObj');
    },

    methods: {
      async getList() {
        console.log('出发啊');

        let param = {
          workOrderId: this.routeObj.id,
          taskId: this.newId
        };

        console.log(this.taskType, 99999999);

        let URL = this.taskType == 5 ? listApplystorage : listWorkReport;

        await URL(param).then((res) => {
          console.log(res, 'res');

          this.list = JSON.parse(JSON.stringify(res));
        });
      },

      async getPlanCode() {
        await parameterGetByCode({ code: 'enable_quality_plus' }).then(
          (res) => {
            this.planValue = res.value;
          }
        );
      }
    }
  };
</script>

<style scoped lang="scss">
  .rx-bc {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .item_box {
    margin-top: 5px;
    margin-bottom: 6px;
    padding: 0 10px;

    .round {
      width: 20px;
      height: 20px;
      line-height: 20px;
      border-radius: 50%;
      background: #157a2c;
      color: #fff;
      text-align: center;
      font-size: 12px;
    }

    .time {
      color: #157a2c;
      font-family: PingFang HK;
      font-size: 14px;
      font-style: normal;
      font-weight: 500;
      margin-left: 8px;
    }
  }

  .title_card {
    height: 35px;
    width: 100%;
    background: #157a2c;
    font-size: 16px;
    color: #fff;
    line-height: 35px;
    padding: 0 20px;
    box-sizing: border-box;
  }
</style>
