<!-- 图库管理 -->
<template>
    <el-dialog title="选择图纸"
        width="70%"
        :close-on-click-modal="false"
        :visible.sync="visible">
        <div class="draw-management">
            <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
            <el-form-item label="名称">
                <el-input v-model="dataForm.keyword" placeholder="名称" clearable/>
            </el-form-item>
            <el-form-item>
                <el-button @click="search()">查询</el-button>
                <el-button type="primary" @click="addSubmit">确认添加</el-button>
                <el-button type="text" @click="gotoPage">没有找到？去上传</el-button>
            </el-form-item>
            </el-form>
            <el-table
            :data="dataList"
            border
            v-loading="dataListLoading"
            @selection-change="selectionChangeHandle"
            style="width: 100%;">
            <el-table-column type="selection"></el-table-column>
            <el-table-column
                label="序号"
                type="index"
                width="50"
                align="center">
            </el-table-column>
            <el-table-column
                prop="drawingCode"
                header-align="center"
                align="center"
                min-width="100"
                :show-tooltip-when-overflow="true"
                label="图纸编码">
            </el-table-column>
            <el-table-column
                prop="drawingName"
                header-align="center"
                align="center"
                min-width="120"
                :show-tooltip-when-overflow="true"
                label="图纸名称">
            </el-table-column>
            <el-table-column
                prop="drawingNo"
                header-align="center"
                align="center"
                min-width="120"
                :show-tooltip-when-overflow="true"
                label="图号">
            </el-table-column>
            <el-table-column
                prop="source"
                header-align="center"
                align="center"
                min-width="200"
                :show-overflow-tooltip="true"
                label="来源">
            </el-table-column>
            <el-table-column
                prop="creatorName"
                header-align="center"
                align="center"
                min-width="100"
                label="上传者">
            </el-table-column>
            <el-table-column
                prop="notes"
                header-align="center"
                align="center"
                min-width="180"
                :show-overflow-tooltip="true"
                label="备注">
            </el-table-column>
            </el-table>
            <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            layout="total, sizes, prev, pager, next, jumper">
            </el-pagination>
        </div>
    </el-dialog>
  </template>
  
  <script>
    import { getDrawList } from '@/api/product'
    import ProductComponent from '@/views/modules/common/product-component'
    export default {
      name: 'draw-template-choose',
      components: {
        ProductComponent
      },
      data () {
        return {
          visible: false,
          detailVisible: false,
          dataForm: {
            keyword: ''
          },
          optionsProducts: [],
          dataList: [],
          pageIndex: 1,
          pageSize: 10,
          totalPage: 0,
          dataListLoading: false,
          dataListSelections: []
        }
      },
      created () {
        this.getDataList()
      },
      methods: {
        init () {
          this.visible = true
        },
        onChose () {
          this.addOrUpdateVisible = false
          this.detailVisible = false
        },
        // 查询
        search () {
          this.pageIndex = 1
          this.getDataList()
        },
        // 获取数据列表
        getDataList () {
          this.addOrUpdateVisible = false
          this.dataListLoading = true
          let params = {
            'current': this.pageIndex,
            'size': this.pageSize,
            'keyword': this.dataForm.keyword,
            'createTime': this.dataForm.createTime ? this.dataForm.createTime : null,
            'productId': this.dataForm.productId ? this.dataForm.productId : null
          }
          getDrawList(params).then(({data}) => {
            if (data && data.code === '200') {
              this.dataList = data.data.records
              this.totalPage = Number(data.data.total)
            } else {
              this.dataList = []
              this.totalPage = 0
            }
            this.dataListLoading = false
          })
        },
        // 每页数
        sizeChangeHandle (val) {
          this.pageSize = val
          this.pageIndex = 1
          this.getDataList()
        },
        // 当前页
        currentChangeHandle (val) {
          this.pageIndex = val
          this.getDataList()
        },
        // 多选
        selectionChangeHandle (val) {
          this.dataListSelections = val
        },
        addSubmit () {
          if (this.dataListSelections.length === 0) {
            this.$message.warning('请选择')
            return
          }
          this.visible = false
          this.$emit('addItems', this.dataListSelections)
        },
        // 跳转上传图纸页面
        gotoPage () {
          this.visible = false
          this.$router.push('/tech-draw-management')
        }
      }
    }
  </script>
  
  <style scoped>
  
  </style>
  