<template>
  <el-dialog :visible.sync="innerVisible" title="退货工单标记" center>
    <vue-editor v-model="content" />
    <el-button class="fr" type="primary" size="mini" style="margin:10px 0px" :loading="loading" @click="() => onMark()">保存</el-button>
    <div style="clear:both" />
  </el-dialog>
</template>

<script>
import { VueEditor } from 'vue2-editor'
import asyncRequest from '@/apis/service/sellOut/returnGoodWorkOrder'
export default {
  components: { VueEditor },
  props: ['sitem', 'visible'],
  data: () => ({
    content: '',
    loading: false
  }),
  computed: {
    innerVisible: {
      get() {
        return this.visible
      },
      set(newValue) {
        this.$emit('update:visible', newValue)
      }
    }
  },
  watch: {
    visible: {
      handler() {
        if (!this.visible) return null
        this.$nextTick(() => {
          this.content = this.sitem.record
        })
      }
    }
  },
  methods: {
    async onMark() {
      this.loading = true
      const { code, message } = await asyncRequest.setAfterChildRecord({ record: this.content, id: this.sitem.id })
      this.loading = false

      switch (code) {
        case 0:
          this.content = ''
          this.innerVisible = false
          this.$emit('reload')
          break
        default:
          this.$message.warning(message)
          break
      }
    }
  }
}
</script>
