<template>
  <div class="app-container">
    <el-card style="height: 850px">
      <el-row>
        <el-col style="width: 400px;">
          <el-button type="primary" plain style="margin: 10px 0 3px 0" icon="el-icon-circle-plus-outline" size="small" @click="addProcess">新增工艺</el-button>
          <el-table :data="tableData2" :row-key="getRowKeys" size="mini" highlight-current-row stripe border height="780" width="100%">
            <el-table-column label="序号" align="center" type="index" width="60"/>
            <el-table-column label="工艺名称" align="center" width="200">
              <template slot-scope="scope">
                {{ scope.row.工艺名称 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="操作">
              <template slot-scope="scope">
                <el-tooltip :open-delay="1200" effect="dark" content="编辑" placement="top">
                  <div style="display: inline-block">
                    <el-button type="text" size="mini" icon="el-icon-edit-outline" style="margin-left: 10px" @click="editProcess(scope.row)"/>
                  </div>
                </el-tooltip>
                <el-tooltip :open-delay="1200" effect="dark" content="删除" placement="top">
                  <div style="display: inline-block">
                    <el-button type="text" size="mini" icon="el-icon-delete" style="margin-left: 10px" @click="delProcess(scope.row)"/>
                  </div>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-card>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible" :title="title" center style="min-height: 300px" width="400px">
      <el-form ref="form1" :model="form1" :rules="rules1" label-position="left" label-width="110px" >
        <el-form-item label="工艺名称" prop="ProcessClassification">
          <el-input v-model="form1.ProcessClassification" size="small" clearable style="width:200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="calloff">取 消</el-button>
        <el-button v-show="title==='新增工艺'" type="primary" @click="submitaddProcess('form1')">确 定</el-button>
        <el-button v-show="title==='编辑工艺'" type="primary" @click="submiteditProcess('form1')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 工艺分类所需变量
      title: '',
      expands: [],
      tableData1: [],
      ProcessNum: '',
      loading: false,
      dialogFormVisible: false,
      temp: null,
      ProcessClassificationNumS: '',
      form1: {
        ProcessClassification: '',
        TechnologicalRequirements: ''
      },
      rules1: {
        ProcessClassification: [{ required: true, message: '请输入工艺分类名称', trigger: 'blur' }]
      },
      tableData2: [],
      tableData3: [],
      Num: [],
      maxNum: '',
      max: [],
      code: ''
    }
  },
  created() {
    this.getProcess()
  },
  methods: {
    getProcess() {
      var param = []
      // 参数数量与名称要与存储过程对应
      var Data = this.CreateData('11', '工艺名称_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData2 = response.data
      })
    },
    calloff() {
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.dialogFormVisible = false
      this.form1 = {
        ProcessClassification: ''
      }
    },
    addProcess() {
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.form1.ProcessClassification = ''
      this.title = '新增工艺'
      this.dialogFormVisible = true
    },
    submitaddProcess(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['工艺名称', this.form1.ProcessClassification]
          // 参数数量与名称要与存储过程对应
          var Data = this.CreateData('12', '车间生产管理工艺_基础表_工艺名称_增加数据', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('增加成功')
              this.getProcess()
              this.dialogFormVisible = false
            } else {
              this.$message.error('增加失败')
            }
          })
        } else {
          return false
        }
      })
    },
    editProcess(row) {
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.title = '编辑工艺'
      this.dialogFormVisible = true
      this.form1.ProcessClassification = row.工艺名称
      this.ProcessNum = row.工艺编号
    },
    submiteditProcess(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['工艺名称', this.form1.ProcessClassification]
          param[1] = ['工艺编号', this.ProcessNum]
          // 参数数量与名称要与存储过程对应
          var Data = this.CreateData('12', '车间生产管理工艺_基础表_工艺名称_修改名称及简称', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功')
              this.getProcess()
              this.dialogFormVisible = false
            } else {
              this.$message.error('编辑失败')
            }
          })
        } else {
          return false
        }
      })
    },
    getRowKeys(row) {
      return row.工艺编号
    },
    delProcess(row) {
      this.$confirm('此操作将永久删除' + row.工艺名称 + '行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['工艺编号', row.工艺编号]
        // 参数数量与名称要与存储过程对应
        var Data = this.CreateData('12', '车间生产管理工艺_基础表_工艺名称_删除数据', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.getProcess()
          } else {
            this.$message.error('删除失败')
          }
        })
      })
    }
  }
}
</script>

<style scoped>
  /*.el-card {*/
  /*  margin-top: 15px;*/
  /*  margin-left: 15px;*/
 /* }!**!*/

</style>
<style lang="scss">
  .subTableHeader {
    th {
      background: #8ff4ea !important;
      color: black;
    }

    tr.el-table__row td {
      background-color: #d8e5f6 !important;
    }

    tr.el-table__row.el-table__row--striped td {
      background: #e9f0f9 !important;
    }
  }
</style>

