<template>
  <div>
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="80px">
      <el-form-item label="是否同意" prop="state">
        <el-select
          v-model="ruleForm.state"
          class="form_select"
          filterable
          clearable
          placeholder="请选择是否同意"
        >
          <el-option label="同意" value="0" />
          <el-option label="退回" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { agreeChangeCollectionOrderCustomerService } from '@/api/customerServiceManagement/orderListCustomerService'
export default {
  props: {
    rowid: {
      type: String,
      default: ''
    },
    layerid: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      ruleForm: {
        orderids: '', // 订单编号
        state: '0', // 0同意；1退回
      },
      rules: {
        state: [
          {
            required: true,
            trigger: 'change',
            message: '请选择是否同意'
          }
        ]
      }
    }
  },
  created() {
    if (this.rowid) {
      this.ruleForm.orderids = this.rowid
    }
  },
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          agreeChangeCollectionOrderCustomerService(this.ruleForm)
            .then((response) => {
              if (response.state.toLowerCase() === 'success') {
                this.$parent.$layer.close(this.layerid)
                this.$parent.getList() // 重新加载父级数据
                this.$message.success('恭喜你，操作成功!')
              }
            })
            .catch(() => {
              this.loading = false
            })
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.form_select {
  width: 100%
}
</style>
