<!-- 排产模板 -->
<template>
  <div class="production">
    <template v-if="!detailsVisible && !detailsVisible">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="queryPage()">
        <el-form-item label="物料名称">
          <el-input v-model="dataForm.productName" placeholder="物料名称" clearable/>
        </el-form-item>
        <el-form-item label="模板名称">
          <el-input v-model="dataForm.mouldName" placeholder="模板名称" clearable/>
        </el-form-item>
        <el-form-item>
          <el-button @click="queryPage()">查询</el-button>
          <el-button v-if="isAuth('prod:productionMould:save')" type="primary" @click="detail(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="mouldName"
          header-align="center"
          align="center"
          min-width="120"
          :show-tooltip-when-overflow="true"
          label="模板名称">
        </el-table-column>
        <el-table-column
          prop="productName"
          header-align="center"
          align="center"
          min-width="120"
          :show-tooltip-when-overflow="true"
          label="物料名称">
        </el-table-column>
        <el-table-column
          prop="creatorName"
          header-align="center"
          align="center"
          label="创建人">
        </el-table-column>
        <el-table-column
          prop="createTime"
          header-align="center"
          align="center"
          min-width="160"
          label="创建时间">
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="100"
          label="操作">
          <template slot-scope="scope">
            <el-button v-if="isAuth('prod:productionMould:update')" type="text" size="small" @click="detail(scope.row.mouldId, true, scope.row.productName)">编辑</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>
    <!-- 弹窗, 新增 / 修改 -->
    <detail v-if="detailsVisible" ref="details" @refreshDataList="getDataList" @onChose="onChose"/>
  </div>
</template>

<script>
  import Detail from './scheduling-mould-details'
  import { getMouldList } from '@/api/production'
  export default {
    name: 'scheduling',
    components: {Detail},
    data () {
      return {
        detailsVisible: false,
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: []
      }
    },
    created () {
      this.getDataList()
    },
    methods: {
      onChose () {
        this.detailsVisible = false
      },
      // 查询
      queryPage () {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        let submitData = {
          'current': this.pageIndex,
          'size': this.pageSize,
          'mouldName': this.dataForm.mouldName ? this.dataForm.mouldName : null,
          'productName': this.dataForm.productName ? this.dataForm.productName : null
        }
        getMouldList(submitData).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
      },
      // 新增 / 修改
      detail (id, disable, productName) {
        this.detailsVisible = true
        this.$nextTick(() => {
          this.$refs.details.init(id, disable, productName)
        })
      }
    }
  }
</script>

<style scoped>

</style>
