<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item  prop="proName">
          <el-input
            v-model="queryParams.proName"
            placeholder="工程名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item  prop="departName">
          <el-input
            v-model="queryParams.departName"
            placeholder="项目部"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item  prop="teamName">
          <el-input
            v-model="queryParams.teamName"
            placeholder="领用班组"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item  prop="devName">
          <el-input
            v-model="queryParams.devName"
            placeholder="设备名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
       
        <el-form-item  prop="devCode">
          <el-input
            v-model="queryParams.devCode"
            placeholder="设备编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item prop="devType">
          <el-select v-model="queryParams.devType" placeholder="设备类型" clearable style="width: 100%;">
            <el-option
              v-for="dict in dict.type.sys_device_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

     <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">     
        <el-form-item prop="lyTime">
          <el-date-picker
            v-model="queryParams.lyTime"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            placeholder="领用时间"
            type="date"
          ></el-date-picker>
        </el-form-item>
        <el-form-item prop="ghTime">
          <el-date-picker
            v-model="queryParams.ghTime"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            placeholder="归还时间"
            type="date"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-col>
    </el-row>
  </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"
          v-hasPermi="['basic:deviceLyRecord:export']"
        >导出数据</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableData">
        <el-table-column label="工程名称" align="center" prop="proName" />
        <el-table-column label="项目部名称" align="center" prop="departName" />
        <el-table-column label="领用班组" align="center" prop="teamName" />
        <el-table-column label="领用设备类型" align="center" prop="deviceTypeName">
        </el-table-column>
        <el-table-column label="设备名称" align="center" prop="devName" />
        <el-table-column label="领用设备编码" align="center" prop="devCode" />
        <el-table-column label="班组负责人" align="center" prop="teamLeader">
          <template slot-scope="scope">
            <div @click="openShall(scope.row)">
              <div>
                    <span >{{ scope.row.teamLeader }}\</span><span>{{ scope.row.leaderPhone }}</span>
                </div>
            </div>
        </template>

        </el-table-column>
        <el-table-column label="领用时间" align="center" prop="lyTime" />
        <el-table-column label="归还时间" align="center" prop="ghTime">
          <template slot-scope="scope">
            <span v-if="!scope.row.ghTime" style="font-weight: bold;color: green;">在用</span>
            <span v-else>{{ scope.row.ghTime }}</span>
          </template>
        </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" />
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

  </div>
</template>

<script>
import { DeviceLyRecord, exportDeviceLyRecord} from "@/api/comprehensive/deviceLyRecord";
import { downloadFile } from '@/utils/download'
import { getToken } from '@/utils/auth'
import uploadFile from '../../components/uploadFile.vue'
export default {
  name: "Post",
  dicts: ['sys_normal_disable','sys_device_type','sys_device_status'],
  components: {
    uploadFile
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备表格数据
      tableData: [],
      // 弹出层标题
      title: "",
      shxName:"shx",
      // 是否显示弹出层
      open: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proName:undefined,
        departName:undefined,
        teamName: undefined,
        devType: undefined,
        devName: undefined,
        devCode: undefined,
        // lyTime: undefined,
        // ghTime: undefined,
      },
      // 表单参数
      form: {},
    };
  },
  computed: {

  },
  created() {
    this.getList();
    
  },
  mounted(){
    console.log(this.dict.type.sys_device_type)
  },
  methods: {

      /** 查询设备领用记录列表 */
      getList() {
          this.loading = true;
          DeviceLyRecord(this.queryParams).then(response => {
            this.tableData = response.rows;
            this.total = response.total;
            this.loading = false;
          });
      },

      // 取消按钮
      cancel() {
          this.open = false;
          this.reset();
      },
      // 表单重置
      reset() {
          this.form = {};
          this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
          this.resetForm("queryForm");
          this.handleQuery();
      },

      // 多选框选中数据
      handleSelectionChange(selection) {
          this.ids = selection.map(item => item.deviceCode)
          this.single = selection.length!=1
          this.multiple = !selection.length
      },

     
      /** 导出按钮操作 */
      handleExport() {
        exportDeviceLyRecord(this.queryParams).then(res => {
          downloadFile({ fileName: `设备领用记录_${new Date().getTime()}.xlsx`, fileData: res, fileType: 'application/vnd.ms-excel;charset=utf-8' })
        })
      },

  }
};
</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;
    }
}
</style>