<!-- 生产监控管理 -->
<template>
  <div class="production">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="queryPage()">
      <el-form-item label="订单编号">
        <el-input v-model="dataForm.orderCode" placeholder="订单编号" clearable/>
      </el-form-item>
      <el-form-item label="产品名称">
        <el-input v-model="dataForm.productName" placeholder="产品名称" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button @click="queryPage()">查询</el-button>
        <el-button v-if="false" type="primary" disabled @click="createNewProduct()">创建新产品</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="prodCode"
        header-align="center"
        align="center"
        label="产品编号">
      </el-table-column>
      <el-table-column
        prop="productName"
        header-align="center"
        align="center"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="progressBar"
        header-align="center"
        align="center"
        min-width="100"
        label="生产进度">
        <template slot-scope="scope">
          <el-progress :percentage="50"></el-progress>
        </template>
      </el-table-column>
      <el-table-column
        prop="contactDate"
        header-align="center"
        align="center"
        label="交期时间">
      </el-table-column>
      <el-table-column
        prop="orderCode"
        header-align="center"
        align="center"
        label="订单编码">
      </el-table-column>
      <el-table-column
        prop="customerName"
        header-align="center"
        align="center"
        min-width="120"
        label="客户名称">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('prod:monitoring:info')" type="text" size="small" @click="detail(scope.row.id, scope.row.prodCode, true)">查看</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>
    <!-- 弹窗, 查看 -->
    <detail v-if="detailsVisible" ref="details" @refreshDataList="getDataList"/>
  </div>
</template>

<script>
  import Detail from './monitoring-details'
  import { getMonitoringList } from '@/api/production'
  export default {
    name: 'monitoring',
    components: {Detail},
    data () {
      return {
        detailsVisible: false,
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        // 状态：1：待排产，2:生产中，3:生产完成
        optionsState: [
          {
            code: '1',
            value: '待排产'
          },
          {
            code: '2',
            value: '生产中'
          },
          {
            code: '3',
            value: '生产完成'
          }
        ]
      }
    },
    created () {
      this.getDataList()
    },
    methods: {
      // 查询
      queryPage () {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        let params = {
          'current': this.pageIndex,
          'size': this.pageSize,
          'productName': this.dataForm.productName ? this.dataForm.productName : null,
          'orderCode': this.dataForm.orderCode ? this.dataForm.orderCode : null
        }
        getMonitoringList(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
          }
          console.log('monitor')
          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
      },
      // 新增 / 修改
      detail (id, prodCode, disable) {
        this.detailsVisible = true
        this.$nextTick(() => {
          this.$refs.details.init(id, prodCode, disable)
        })
      },
      // 创建新产品
      createNewProduct () {
        this.$message.warning('功能暂未开放')
      }
    }
  }
</script>

<style scoped>

</style>

