<template>
  <div>
    <Tinymce v-model="defaultValue" :height="750" placeholder="在这里输入文字"/>
    <el-button type="primary" style="float:right;margin: 10px" @click="save">保存</el-button>
    <el-button v-if="this.$route.query.instructionsId" style="float:right;margin-top: 10px" type="warning"
               @click="goBack"
    >返回
    </el-button>
  </div>
</template>

<script>
import Tinymce from '../index.vue'
import { updateTechnology, getTechnologyInfo } from '../../../api/system/machinery'
import { getInstructionsInfo, updateInstructions } from '../../../api/mes/instructions'

export default {
  components: {
    Tinymce
  },
  data() {
    return {
      defaultValue: '',
      form: null
    }
  },
  computed: {},

  created() {
    this.getInfo()
  },
  mounted() {

  },
  methods: {
    getInfo() {
      if (this.$route.query.machineryId) {
        getTechnologyInfo(this.$route.query.machineryId).then((response) => {
          this.form = response.data
          this.defaultValue = response.data.remark
        })
      } else if (this.$route.query.instructionsId) {
        getInstructionsInfo(this.$route.query.instructionsId).then((response) => {
          console.log(response, '物资使用说明')
          this.form = response.data
          this.defaultValue = response.data.remark
        })
      }

    },
    save() {
      console.log(this.defaultValue, '拿到的设备工艺 信息------')
      if (this.$route.query.machineryId) {
        this.form.remark = this.defaultValue
        updateTechnology(this.form).then(response => {
          console.log(response, '更新设备工艺')
          if (response.data) {
            this.$message.success('保存成功')
          }
        })
      } else {
        this.form.remark = this.defaultValue
        updateInstructions(this.form).then(response => {
          console.log(response, '更新物资使用说明')
          if (response.data) {
            this.$message.success('保存成功')
          }
        })
      }

    },
    goBack() {
      this.$router.push('/material/instructions')
    }
  }
}
</script>
