<template>
  <div>
    <el-form
      :model="maForm"
      ref="maForm"
      size="small" 
      :inline="true"
      label-width="120px"
    >
      <el-form-item label="租赁工程" prop="projectId">
        <el-input
          v-model="maForm.projectName"
          placeholder="租赁工程"
          clearable
          maxlength="50"
          style="width: 240px"
          readonly
        />
      </el-form-item>
       <el-form-item label="领用班组" prop="teamName">
        <el-input
          v-model="maForm.teamName"
          placeholder="领用班组"
          clearable
          maxlength="50"
          style="width: 240px"
          readonly
        />
      </el-form-item>
      <el-form-item label="班组长" prop="leasePerson">
        <el-input
          v-model="maForm.leasePerson"
          placeholder="班组长"
          clearable
          maxlength="50"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          readonly
        />
      </el-form-item>

      <el-form-item label="联系电话" prop="relPhone">
        <el-input
          v-model="maForm.relPhone"
          placeholder="联系电话"
          clearable
          maxlength="50"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          readonly
        />
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="equipmentList">
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column
        label="类型名称"
        align="center"
        prop="maTypeName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="规格型号"
        align="center"
        prop="typeName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="计量单位"
        align="center"
        prop="unitName"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="当前库存"
        align="center"
        prop="storageNum"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="预领数量"
        align="center"
        prop="preNum"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        :show-overflow-tooltip="true"
      />
    </el-table>
  </div>
</template>

<script>
import { getApplyInfo, getListProject, getListUnite } from "@/api/materialsStation";
export default {
  name: "QueryTools",
  dicts: ["purchase_task_status"],
  components: {
    // UploadImg,
  },
  props: {
    isView: {
      type: Boolean,
      default: () => {
        return false;
      },
    },
    queryTaskId: {
      type: [String, Number],
      default: () => {
        return "";
      },
    },
    queryId: {
      type: [String, Number],
      default: () => {
        return "";
      },
    },
  },
  data() {
    return {
      //任务ID
      taskId: "",
      // 遮罩层
      loading: true,
      //租赁单位
      uniteList: [],
      //租赁工程
      projectList: [],
      // 表格数据
      equipmentList: [],
      unitId: null,
      projectId: null,
      // 是否显示弹出层
      open: false,
      rowData: {},
      maForm: {
        unitId: undefined,
        projectId: undefined,
      },
      selectTreeProps: {
        children: "children",
        label: "name",
        // multiple: false,
        value: "id",
        // multiple: true,
      },
    };
  },
  computed: {},
  mounted() {
    this.taskId = this.queryTaskId;
    this.id = this.queryId;
    this.projectInfoList();
    this.getTaskInfo();
  },
  methods: {
    /** 租赁单位和工程-下拉选 */
    projectInfoList() {
      getListUnite({ id: null }).then((response) => {
        this.uniteList = response.data;
      });
      getListProject({ id: null }).then((response) => {
        this.projectList = response.data;
      });
    },
    //获取任务详情-列表数据
    getTaskInfo() {
      this.loading = true;
      getApplyInfo(this.id).then((response) => {
        this.maForm = response.data.leaseApplyInfo;
        this.maForm.unitId = response.data.leaseApplyInfo.leaseUnitId;
        this.maForm.projectId = response.data.leaseApplyInfo.leaseProjectId;
        this.unitId = this.treeParentsById(this.uniteList, this.maForm.unitId);
        this.projectId = this.treeParentsById(
          this.projectList,
          this.maForm.projectId
        );
        this.equipmentList = response.data.leaseApplyDetailsList;

        this.loading = false;
      });
    },
    //单位，工程树结构数据获取父
    treeParentsById(list, id) {
      for (let i in list) {
        if (list[i].id == id) {
          //查询到就返回该数组对象的value
          return [list[i].id];
        }
        if (list[i].children) {
          let node = this.treeParentsById(list[i].children, id);
          if (node !== undefined) {
            //查询到把父节把父节点加到数组前面
            node.unshift(list[i].id);
            return node;
          }
        }
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/material/material_lease_apply_info/exportDetails",
        { id: this.id },
        `领料申请详情_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep.el-table .fixed-width .el-button--mini {
  width: 60px !important;
  margin-bottom: 10px;
}
//隐藏图片上传框的css
::v-deep.disabled {
  .el-upload--picture-card {
    display: none;
  }
}
.custom-textarea {
  width: 300px;
  height: 100px;
}
.accept-img {
  color: #409eff;

  .a-two {
    margin-left: 20px;
  }
}

.left-tip {
  font-size: 16px;
  letter-spacing: 1px;
}
</style>
