<template>
    <div style="margin-bottom: 20px">
      <el-form :model="queryParams" ref="queryForm" :inline="true"  label-width="68px">
        <el-form-item label="图纸名称" prop="title">
          <el-input
            v-model="queryParams.title"
            placeholder="请输入图纸名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="图纸编号" prop="drawingNo">
          <el-input
            v-model="queryParams.drawingNo"
            placeholder="请输入图纸编号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="图纸分类" prop="cateId">
          <el-select v-model="queryParams.cateId" placeholder="请选择图纸分类" clearable size="small">
            <el-option
              v-for="dict in cateIdOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </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-form>

      <el-table v-loading="loading" :data="drawingList">
        <el-table-column label="图纸名称" align="center" prop="title" show-overflow-tooltip/>
        <el-table-column label="图纸编号" align="center" prop="drawingNo" show-overflow-tooltip/>
        <el-table-column label="图纸型号" align="center" prop="model">
          <template slot-scope="scope">
            <span v-if="scope.row.source">{{ scope.row.source }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="版本号" align="center" prop="version" />
        <el-table-column label="图纸分类" align="center" prop="cateId" :formatter="cateIdFormat" />
        <el-table-column label="图纸来源" align="center" prop="source">
          <template slot-scope="scope">
            <span v-if="scope.row.source">{{ scope.row.source }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="图纸附件" align="center" prop="fileUrl">
          <template slot-scope="scope">
           <span v-if="scope.row.fileUrl">
              <a style="color: #1c84c6" :href="JSON.parse(scope.row.fileUrl).url" target="_blank">查看/下载</a>
            </span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" show-overflow-tooltip/>
        <el-table-column label="创建人" align="center" prop="createBy" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-document"
              @click="handleDetail(scope.row)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 详情 -->
      <DetailInfo ref="detail"/>

    </div>
</template>

<script>
  import { getDrawInfoByDeviceId } from "@/api/track/drawing";
  import DetailInfo from "../../draw/components/DetailInfo";
  export default {
    name: "draw-info",
    props:{
      deviceId:{
        type: Number
      }
    },
    components:{
      DetailInfo
    },
    data(){
        return{
          // 总条数
          total: 0,
          loading: false,
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            title: null,
            drawingNo: null,
            cateId: null,
          },
          drawingList:[],
          cateIdOptions: []
        }
    },
    created(){
      this.getDicts("t_draw_type").then(response => {
          this.cateIdOptions = response.data;
      });
      this.queryParams.deviceId = this.deviceId;
      this.getList();
    },
    methods:{
      getList() {
        this.loading = true;
        getDrawInfoByDeviceId(this.queryParams).then(response => {
          this.drawingList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 图纸分类字典翻译
      cateIdFormat(row, column) {
        return this.selectDictLabel(this.cateIdOptions, row.cateId);
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      //详情
      handleDetail(row){
        this.$refs.detail.getDetailInfo(row.id);
      }
    }
  }
</script>

<style scoped>

</style>
