<template>
  <el-dialog
    title="质量处理"
    append-to-body
    :modelValue="openShow"
    width="30%"
    @close="closeDialog"
  >
    <el-form ref="form" v-model="formData" :rules="rules" label-width="80px" class="vd-form-row">
      <el-form-item label="订单是否继续" prop="rsCode" label-width="120px">
        <el-radio-group v-model="formData.rsCode">
          <el-radio label="是" />
          <el-radio label="否" />
        </el-radio-group>
      </el-form-item>
      <el-form-item label="处理意见" prop="handleResult">
        <el-input v-model="formData.handleResult" type="textarea" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="submit" :loading="saveLoading">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script>
import { getList, receiveOrder } from '@/api/productionManagement/reworkOrder';
import { taskComplete } from '@/api/productionManagement/WIPChange.js';

export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false,
    },
    rowItem: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      saveLoading: false,
      openShow: false,
      formData: { rsCode: null, handleResult: '' },
      rules: {
        rsCode: [{ required: true, message: '请选择', trigger: 'blur' }],
        handleResult: [{ required: true, message: '请输入', trigger: 'blur' }],
      },
    };
  },
  mounted() {
    this.openShow = this.showDialog;
  },
  methods: {
    closeDialog() {
      this.openShow = false;
      this.$emit('closeDialog');
    },
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$confirm('请确认此操作', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          })
            .then(() => {
              this.rowItem.rsCode = this.rowItem.rsCode;
              this.rowItem.handleResult = this.rowItem.handleResult;
              receiveOrder(this.rowItem).then(res => {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                });
                this.closeDialog();
              });
            })
            .catch(err => {
              this.$message.info(err.msg);
            });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped></style>
