<!-- 车间管理 -->
<template>
  <div>
    <template v-if="!addOrUpdateVisible && !detailVisible">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="queryData()">
        <el-form-item label="项目/任务号">
          <el-input v-model="dataForm.orderCode" placeholder="" clearable/>
        </el-form-item>
        <el-form-item>
          <el-button @click="queryData()">查询</el-button>
          <el-button type="primary" @click="addOrUpdateHandle(0, false)">新增</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          label="序号"
          type="index"
          width="50"
          align="center">
        </el-table-column>
         <el-table-column
          prop="projectName"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="项目名称">
        </el-table-column>
        <el-table-column
          prop="orderCode"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="任务号">
        </el-table-column>
        <el-table-column
          prop="attachList"
          header-align="center"
          align="center"
          :show-tooltip-when-overflow="true"
          label="技术协议"
        >
        <template slot-scope="scope">
            <el-button
              :disabled="
                !scope.row.attachList || scope.row.attachList.length === 0
              "
              type="text"
              size="small"
              @click="attachDetails(scope.row.attachList)"
              >查看</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="attachList1"
          header-align="center"
          align="center"
          :show-tooltip-when-overflow="true"
          label="技术文件"
        >
        <template slot-scope="scope">
            <el-button
              :disabled="
                !scope.row.attachList1 || scope.row.attachList1.length === 0
              "
              type="text"
              size="small"
              @click="attachDetails(scope.row.attachList1)"
              >查看</el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="notes"
          header-align="center"
          align="center"
         :show-tooltip-when-overflow="true"
          label="备注">
        </el-table-column>
        <el-table-column
          prop="createTime"
          header-align="center"
          align="center"
          min-width="120"
          :show-tooltip-when-overflow="true"
          label="创建时间">
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="150"
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="detailHandle(scope.row)">查看</el-button>
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row, false)">编辑</el-button>
          </template>
        </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>
    </template>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" @onChose="onChose"></add-or-update>
    <detail v-if="detailVisible" ref="detail" @onChose="onChose"/>

    <attach-detail-dialog ref="attachDetail" @onChose="onChose" />
  </div>
</template>

<script>
  import AddOrUpdate from './workshop-add-or-update'
  import Detail from './file-manage-detail'
  import { getList } from '@/api/workshop'
  import AttachDetailDialog from '../common/attach-detail-dialog'
  export default {
    name: 'workshop-manage',
    components: {
      AddOrUpdate, Detail, AttachDetailDialog
    },
    data () {
      return {
        addOrUpdateVisible: false,
        detailVisible: false,
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        optionsLevel: []
      }
    },
    created () {
      this.getDataList()
    },
    methods: {
      onChose () {
        this.addOrUpdateVisible = false
        this.detailVisible = false
      },
      // 查询
      queryData () {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.addOrUpdateVisible = false
        let params = {
          'current': this.pageIndex,
          'size': this.pageSize,
          'orderCode': this.dataForm.orderCode ? this.dataForm.orderCode : null
        }
        getList(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
      },
      // 新增 / 修改
      addOrUpdateHandle (item, disable) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(item, disable)
        })
      },
      // 详情
      detailHandle (item) {
        this.detailVisible = true
        this.$nextTick(() => {
          this.$refs.detail.init(item)
        })
      },
      attachDetails (attachList) {
        this.$refs.attachDetail.init(attachList)
      }
    }
  }
</script>

<style scoped>

</style>
