<template>
  <div class="page">
    <el-form label-width="130px">
      <div class="content-detail">
        <div class="basic-details">
          <HeaderTitle title="基本信息" size="16px"></HeaderTitle>
          <el-row>
            <el-col :span="12">
              <el-col :span="12">
                <el-form-item label="计划单号">
                  <span> {{ infoData.code }} </span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="来源计划配置单号">
                  <span> {{ infoData.planConfigCode }} </span>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item label="名称">
                  <span> {{ infoData.planName }} </span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="部门">
                  <span>
                    {{ infoData.executeGroupName }}
                  </span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="人员">
                  <span>
                    {{ infoData.executeUserName }}
                  </span>
                </el-form-item>
              </el-col> -->
              <el-col :span="12">
                <el-form-item label="计划完成时长">
                  <span v-if="infoData.duration >= 0"
                    >{{ infoData.duration }}分钟</span
                  >
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="周期">
                  <span v-if="infoData.ruleInfo">
                    {{ infoData.ruleInfo.cycleValue
                    }}{{
                      getDictValue('巡点检周期', infoData.ruleInfo.cycleType)
                    }}
                  </span>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item label="设备分类">
                  <span> {{ infoData.categoryLevelName }} </span>
                </el-form-item>
              </el-col> -->
              <el-col :span="12">
                <el-form-item label="规则名称">
                  <span>
                    {{ infoData.name }}
                  </span>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item label="创建部门">
                  <span> {{ infoData.createGroupName }} </span>
                </el-form-item>
              </el-col> -->
              <el-col :span="12">
                <el-form-item label="创建人">
                  <span> {{ infoData.createUserName }} </span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="创建时间">
                  <span> {{ infoData.createTime }} </span>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注">
                  <span> {{ infoData.remark }} </span>
                </el-form-item>
              </el-col>
            </el-col>
          </el-row>
        </div>
        <div class="maintain_equipment_info">
          <HeaderTitle title="量具设备" size="16px">
            <template
              v-if="
                taskDefinitionKey !== 'user_submit' ||
                taskDefinitionKey !== 'user_receive'
              "
            >
              <span class="normarl_num"
                >正常：{{
                  infoData.planDeviceList?.length > 0
                    ? infoData.planDeviceList.filter(
                        (item) => item.teamLeaderResult == 1
                      ).length
                    : 0
                }}</span
              >
              <span class="unnormarl_num"
                >异常：{{
                  infoData.planDeviceList?.length > 0
                    ? infoData.planDeviceList.filter(
                        (item) => item.teamLeaderResult == 2
                      ).length
                    : 0
                }}</span
              >
              <span class="lose_num"
                >丢失：{{
                  infoData.planDeviceList?.length > 0
                    ? infoData.planDeviceList.filter(
                        (item) => item.teamLeaderResult == 3
                      ).length
                    : 0
                }}</span
              >
            </template>
          </HeaderTitle>
          <div class="maintain_equipment_info_content">
            <div class="confirmBtn">
              <el-button
                v-if="
                  taskDefinitionKey === 'leader_receive' &&
                  !infoData.planDeviceList[0].leaderVerifyTime
                "
                type="primary"
                @click="confirmReceive(1, 3)"
                >确定收到</el-button
              >
              <el-button
                v-if="
                  taskDefinitionKey === 'team_leader_receive1' &&
                  !infoData.planDeviceList[0].teamVerifyTime
                "
                @click="confirmReceive(2, 2)"
                type="primary"
                >确定收到</el-button
              >
            </div>

            <el-table :height="300" :data="infoData.planDeviceList" border>
              <el-table-column label="序号" type="index" width="50">
              </el-table-column>
              <el-table-column label="设备编码" prop="name">
                <template slot-scope="scope">
                  <div>
                    <span>{{ scope.row.substance.code }}</span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="编号" prop="norm">
                <template slot-scope="scope">
                  <div>
                    <span>{{ scope.row.substance.extInfo.codeNumber }}</span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="设备名称" prop="content">
                <template slot-scope="scope">
                  <div>
                    <span>{{ scope.row.substance.name }}</span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="设备型号" prop="norm">
                <template slot-scope="scope">
                  <div>
                    <span>{{ scope.row.substance.model }}</span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="质检" prop="qualityStatus">
                <template slot-scope="scope">
                  <el-select
                    v-if="
                      (taskDefinitionKey === 'leader_check' &&
                        infoData.logList.length == 1) ||
                      taskDefinitionKey === 'user_receive'
                    "
                    v-model="scope.row.qualityStatus"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in statusOption"
                      :label="item.label"
                      :value="item.value"
                      :key="item.value"
                    >
                    </el-option>
                  </el-select>
                  <span v-else>{{
                    scope.row.qualityStatus != null
                      ? statusOption.filter(
                          (item) => item.value == scope.row.qualityStatus
                        )[0].label
                      : ''
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column label="是否遗失" prop="isLose">
                <template slot-scope="scope">
                  <el-select
                    v-if="taskDefinitionKey === 'user_submit'"
                    v-model="scope.row.isLose"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in option"
                      :label="item.label"
                      :value="item.value"
                      :key="item.value"
                    >
                    </el-option>
                  </el-select>
                  <span v-else>{{
                    scope.row.isLose != null
                      ? option.filter(
                          (item) => item.value == scope.row.isLose
                        )[0].label
                      : ''
                  }}</span>
                </template>
              </el-table-column>
              <template
                v-if="
                  taskDefinitionKey !== 'user_submit' ||
                  taskDefinitionKey !== 'user_receive'
                "
              >
                <el-table-column
                  v-if="
                    taskDefinitionKey !== 'user_submit' ||
                    taskDefinitionKey !== 'user_receive'
                  "
                  label="上交时间"
                  prop="handTime"
                ></el-table-column>
                <el-table-column
                  label="负责人确认结果"
                  width="260"
                  prop="teamLeaderResult"
                >
                  <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.teamLeaderResult">
                      <el-radio :label="1">正常</el-radio>
                      <el-radio :label="2">异常</el-radio>
                      <el-radio :label="3">丢失</el-radio>
                    </el-radio-group>
                  </template>
                </el-table-column>
                <el-table-column
                  label="负责人确认时间"
                  prop="teamReceiptTime"
                ></el-table-column>
                <el-table-column
                  label="量具管理员确认时间"
                  prop="leaderVerifyTime"
                ></el-table-column>
                <el-table-column
                  label="负责人确认收到时间"
                  prop="teamVerifyTime"
                ></el-table-column>
                <el-table-column
                  label="使用人收取量具时间"
                  prop="harvestTime"
                ></el-table-column>
                <!-- <el-table-column label="操作" width="90">
                  <template slot-scope="scope">
                    <el-button
                      v-if="!scope.row.teamReceiptTime"
                      @click="configResult(scope.row)"
                      type="primary"
                      size="small"
                      >确认</el-button
                    >
                  </template>
                </el-table-column> -->
              </template>
            </el-table>
            <!-- <div
              class="equipment_item"
              v-for="item in infoData.planDeviceList"
              :key="item.id"
            >
              <div class="equipment_info" v-if="item.substance">
                <div class="item_info">
                  <span class="item_label">设备编码</span>
                  <span class="item_value">{{ item.substance.code }}</span>
                </div>
                <div class="item_info">
                  <span class="item_label">设备名称</span>
                  <span class="item_value">{{ item.substance.name }}</span>
                </div>
                <div class="item_info">
                  <span class="item_label">设备型号</span>
                  <span class="item_value">{{ item.substance.model }}</span>
                </div>
                <div class="item_info">
                  <span class="item_label">设备位置</span>
                  <span class="item_value">{{
                    item.substance.positionNames
                  }}</span>
                </div>
                <div
                  class="item_info"
                  v-if="
                    taskDefinitionKey === 'leader_check' &&
                    infoData.logList.length == 1
                  "
                >
                  <span class="item_label">质检</span>
                  <span class="item_value">
                    <el-select v-model="item.status" placeholder="请选择">
                      <el-option
                        v-for="item in statusOption"
                        :label="item.label"
                        :value="item.value"
                        :key="item.value"
                      >
                      </el-option>
                    </el-select>
                  </span>
                </div>
              </div>
            </div> -->
          </div>
        </div>
        <div class="ruleMatters_box">
          <HeaderTitle title="操作事项" size="16px"></HeaderTitle>
          <el-table
            :height="300"
            :data="infoData.planDeviceList[0].workItems"
            border
          >
            <el-table-column label="序号" width="50">
              <template slot-scope="scope">
                <span>{{ scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column label="事项" prop="name" width="100">
              <template slot-scope="scope">
                <div>
                  <span>{{ scope.row.name }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="内容" prop="content" width="300">
              <template slot-scope="scope">
                <div>
                  <span>{{ scope.row.content }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作指导" prop="operationGuide">
              <template slot-scope="scope">
                <div class="operationGuide_box">
                  <div class="left_content">
                    <template v-if="scope.row.operationGuide">
                      <div
                        v-for="(item, index) in scope.row.operationGuide
                          .toolList"
                        :key="item.id"
                        >{{ index + 1 }}.{{ item.name }}</div
                      >
                    </template>
                  </div>
                  <div class="line"></div>
                  <div class="right_content">
                    <template v-if="scope.row.operationGuide">
                      <div
                        v-for="(item, index) in scope.row.operationGuide
                          .procedureList"
                        :key="item.id"
                        >{{ index + 1 }}.{{ item.content }}</div
                      >
                    </template>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="标准" prop="norm" width="100">
              <template slot-scope="scope">
                <div>
                  <span>{{ scope.row.norm }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="状态" prop="status" width="100">
              <template slot-scope="scope">
                <div>
                  <span>{{ options[scope.row.status] }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="结果" prop="result" width="200">
            </el-table-column>
          </el-table>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
  import { EventBus } from './eventBus';
  import dictMixins from '@/mixins/dictMixins';
  import {
    processById,
    getList,
    adminVerify
  } from '@/api/bpm/components/inspectionManage/index.js';
  export default {
    name: 'measuringToolInspection_detailDialog',
    mixins: [dictMixins],
    props: {
      businessId: {
        default: ''
      },
      taskId: {
        default: ''
      },
      taskDefinitionKey: {
        default: ''
      }
    },
    data() {
      return {
        infoData: {
          planDeviceList: [
            {
              substance: {},
              workItems: []
            }
          ]
        },
        option: [
          {
            value: 0,
            label: '否'
          },
          {
            value: 1,
            label: '是'
          }
        ],
        statusOption: [
          {
            value: 0,
            label: '正常'
          },
          {
            value: 1,
            label: '异常'
          },
          {
            value: 2,
            label: '未收'
          }
        ],
        options: {
          0: '正常',
          '-1': '缺陷'
        },
        type: {
          1: '使用人',
          2: '班组',
          3: '负责人'
        }
      };
    },
    async created() {
      this.requestDict('巡点检周期');
      let type = '';
      switch (this.taskDefinitionKey) {
        case 'user_submit':
          type = 1;
          break;
        case 'team_leader_receive':
          type = 2;
          break;
        case 'team_leader_submit':
          type = 2;
          break;
        case 'leader_receive':
          type = 3;
          break;
        case 'leader_send':
          type = 3;
          break;
        case 'team_leader_receive1':
          type = 2;
          break;
        case 'team_leader_send':
          type = 2;
          break;
        case 'user_receive':
          type = 1;
          break;
      }
      processById({ id: this.businessId, type }).then(async (data) => {
        console.log(data);
        // 查询日志
        let res = await getList({
          planId: data.planId,
          node: this.taskDefinitionKey
        });
        console.log(res);
        data.logList = res.data;
        this.infoData = data;
        if (this.taskDefinitionKey == 'leader_check') {
          this.infoData.planDeviceList = this.infoData.planDeviceList.map(
            (item) => {
              return {
                ...item,
                qualityStatus: 0
              };
            }
          );
        }
        EventBus.$emit('getData', this.infoData);
      });
    },
    methods: {
      confirmReceive(confirmType, listType) {
        let params = this.infoData.planDeviceList.map((item) => {
          return {
            id: item.id,
            type: confirmType
          };
        });
        adminVerify(params).then(() => {
          processById({ id: this.businessId, type: listType }).then(
            async (data) => {
              this.infoData = data;
              this.$message.success('确认成功');
            }
          );
        });
      },
      async getTableValue() {
        return this.infoData;
      }
    }
  };
</script>

<style lang="scss" scoped>
  ::v-deep .el-form-item--medium .el-form-item__label {
    color: #6e6e6e;
    font-size: 14px;
    font-weight: bold;
  }
  .maintain_equipment_info {
    margin-bottom: 20px;
    .normarl_num {
      font-size: 14px !important;
      color: green;
      margin-right: 10px;
    }
    .unnormarl_num {
      font-size: 14px !important;
      color: red;
      margin-right: 10px;
    }
    .lose_num {
      font-size: 14px !important;
      color: orange;
    }
    .maintain_equipment_info_title {
      border-bottom: 1px solid #1890ff;
      padding-bottom: 3px;
      margin-bottom: 20px;
      > span {
        display: inline-block;
        line-height: 16px;
        border-left: 6px solid #1890ff;
        padding-left: 6px;
      }
    }
    .maintain_equipment_info_content {
      padding: 0 30px;
      .confirmBtn {
        display: flex;
        justify-content: flex-end;
        margin: 20px 0;
      }
      .equipment_item {
        font-size: 14px;
        padding: 15px;
        margin-bottom: 30px;
        .equipment_info {
          display: flex;
          flex-wrap: wrap;
          border: 1px solid #ddd;
          .item_info {
            width: 33.33%;
            height: 44px;
            line-height: 44px;
            display: flex;
            .item_label {
              width: 90px;
              text-align: center;
              background-color: #f2f2f2;
              font-weight: 700;
            }
            .item_value {
              border-bottom: 1px solid #f2f2f2;
              flex: 1;
              padding-left: 5px;
            }
            // &:last-child {
            //   width: 100%;
            //   .item_value {
            //     border: 0;
            //   }
            // }
          }
        }
        > p {
          margin-top: 20px;
          color: #797979;
        }
        .matter_info {
          ::v-deep .el-table {
            th.el-table__cell {
              background-color: #f2f2f2;
              padding: 0;
            }
            td.el-table__cell {
              padding: 0;
            }
          }
        }
      }
    }
  }
  .ruleMatters_box {
    height: 100%;
    display: flex;
    flex-direction: column;
    .divider {
      flex: 0 0 50px;
      .title {
        height: 35px;
      }
    }
    .el-table {
      overflow: auto;
      .operationGuide_box {
        width: 100%;
        display: flex;
        position: relative;
        .left_content {
          flex: 0 0 150px;
          padding: 10px;
          margin-right: 10px;
          overflow-y: auto;
        }
        .line {
          position: absolute;
          top: -10px;
          left: 150px;
          bottom: -10px;
          height: 110%;
          width: 1px;
          background-color: #ededed;
        }
        .right_content {
          flex: 1;
          padding: 10px;
          overflow-y: auto;
        }
      }
    }
  }
</style>
