<!-- 工艺管理 -->
<template>
  <div class="order">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="queryData()">
      <el-form-item label="工艺名称">
        <el-input v-model="dataForm.techName" clearable/>
      </el-form-item>
      <el-form-item label="产品名称">
        <el-input v-model="dataForm.productName" clearable/>
      </el-form-item>
      <el-form-item label="状态">
        <el-select
          v-model="dataForm.state"
          placeholder="请选择">
         <el-option
           v-for="item in optionsState"
           :key="item.code"
           :label="item.value"
           :value="item.code">
         </el-option>
       </el-select>
      </el-form-item>
      <el-form-item label="创建日期">
        <el-date-picker
          v-model="dataForm.createTime"
          value-format="yyyy-MM-dd"
          type="date">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="queryData()">查询</el-button>
        <el-button v-if="isAuth('pro:technology:save')" type="primary" @click="addOrUpdateHandle(0, false)">新建工艺</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center">
      </el-table-column>
      <el-table-column
        prop="techCode"
        header-align="center"
        align="center"
        min-width="180"
        label="工艺编码">
      </el-table-column>
      <el-table-column
        prop="techName"
        header-align="center"
        align="center"
        min-width="180"
        :show-overflow-tooltip="true"
        label="工艺名称">
      </el-table-column>
      <el-table-column
        prop="techVersion"
        header-align="center"
        align="center"
        min-width="120"
        label="工艺版本">
      </el-table-column>
      <el-table-column
        prop="productName"
        header-align="center"
        align="center"
        min-width="120"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        min-width="160"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="updateTime"
        header-align="center"
        align="center"
        min-width="160"
        label="上次修改时间">
      </el-table-column>
      <el-table-column
        prop="creatorName"
        header-align="center"
        align="center"
        min-width="160"
        label="创建人">
      </el-table-column>
      <el-table-column
        prop="notes"
        header-align="center"
        align="center"
        min-width="160"
        label="备注">
      </el-table-column>
      <el-table-column
        prop="state"
        header-align="center"
        align="center"
        min-width="100"
        label="当前状态">
        <template slot-scope="scope">
          <span>{{ scope.row.techState == -1 ? '停用' : '启用'  }}</span>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        fixed="right"
        align="center"
        width="100"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('pro:technology:update')" type="text" size="small" @click="addOrUpdateHandle1(scope.row.techId, scope.row.techState)">{{ scope.row.techState == -1 ? '启用' : '停用' }}</el-button>
          <el-button v-if="isAuth('pro:technology:info')" type="text" size="small" @click="addOrUpdateHandle(scope.row.techId, 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>
    <!-- 弹窗, 新增 / 修改 -->
    <ctafts-add-or-detail v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getTechnology" />
  </div>
</template>

<script>
  import { getTechnology, update } from '@/api/crafts'
  import ctaftsAddOrDetail from './ctafts-add-or-detail'
  export default {
    name: 'order',
    components: {
      ctaftsAddOrDetail
    },
    created () {
      this.queryData()
    },
    data () {
      return {
        addOrUpdateVisible: false,
        addOrUpdateVisible1: false,
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        optionsState: [
          {
            code: null, value: '全部'
          },
          {
            code: '0', value: '正常'
          },
          {
            code: '-1', value: '停用'
          }
        ],
        optionsCustomer: []
      }
    },
    methods: {
      // 查询
      queryData () {
        this.pageIndex = 1
        this.getTechnology()
      },
      // 获取数据列表
      getTechnology () {
        this.dataListLoading = true
        let params = {
          'current': this.pageIndex,
          'size': this.pageSize,
          'createTimeS': this.dataForm.createTime ? this.dataForm.createTime : null,
          'techState': this.dataForm.state ? this.dataForm.state : null,
          'techName': this.dataForm.techName ? this.dataForm.techName : null,
          'productName': this.dataForm.productName ? this.dataForm.productName : null
        }
        getTechnology(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.getTechnology()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getTechnology()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id, display) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id, display)
        })
      },
      addOrUpdateHandle1 (id, type) {
        update({ techId: id, techState: type === 1 ? 0 : 1 }).then(({data}) => {
          if (data && data.code === '200') {
            this.getTechnology()
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
