<template>
  <div>
      <div class="my-title">确认</div>
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
        <el-row class="my-row">
          <el-col :span="8">
            <el-form-item label="确认状态" prop="confirmState">
              <el-select
                v-model="dataForm.confirmState"
                placeholder="请选择">
                <el-option v-for="item in options"
                           :key="item.value"
                           :label="item.label"
                           :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16" style="padding-left: 20px">
            <el-form-item label="退回说明" prop="backExplain">
              <el-input v-model="dataForm.backExplain" placeholder="退回说明"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="onChose">取消</el-button>
          <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
        </span>
  </div>
</template>

<script>
  import {confirm} from '@/api/task'

export default {
    name: 'work-confirm',
    data () {
      return {
        options: [{
          value: '1',
          label: '确认完成'
        },
        {
          value: '2',
          label: '退回'
        }],
        dataForm: {},
        dataRule: {
          confirmState: [{ required: true, message: '请选择确认状态', trigger: 'change' }]
        }
      }
    },
    methods: {
      onChose () {
        this.$emit('onChose')
      },
      async init (taskId) {
        this.dataForm = {
          taskId: taskId
        }
      },
      validateField (type) {
        this.$refs.dataForm.validateField(type)
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            confirm(this.dataForm).then(({data}) => {
              if (data && data.code === '200') {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.onChose()
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            }).catch(() => {})
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
