<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="form" :inline="true" label-width="80px">
        <el-form-item label="产品名称">
          <el-input v-model="productName" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <tinymce v-model="content" :height="300" />
    </div>
  </div>
</template>

<script>
  import Tinymce from '@/components/Tinymce'
  import {
    viewProductContent,
    saveProductContent
  } from '@/api/productFile/productInfo.js'

  export default {
    name:'productDetile',
    components: {
      Tinymce
    },
    data() {
      return {
        idProduct: '',
        productName:'',
        content:'',
      }
    },
    mounted() {
      this.idProduct = this.$route.query.idProduct
      this.productName = this.$route.query.productName
      this.getInfo();
      this.tempRoute = Object.assign({}, this.$route);
      this.setTagsViewTitle();
    },
    methods: {

      //设置标签名称
      setTagsViewTitle() {
        const title = '产品详情';

        // console.log("tempRoute2",this.tempRoute);
        const route = Object.assign({}, this.tempRoute, { title: `${this.productName}-${title}` });
        // console.log("route",route)
        this.$store.dispatch('tagsView/updateVisitedView', route)
      },
      //获取列表
      getInfo() {
        const _that = this

        var data = {
          "idProduct": _that.idProduct
        }

        viewProductContent(data).then(response => {
          console.log(response)
          const data = response.data
          _that.content = data.content
        }).catch(err => {
          _that.$message.error(err)
        })
      },
      save(){

        const _that = this

        var data = {
              "idProduct": _that.idProduct,
              "content":_that.content
        }

        saveProductContent(data).then(response => {
          // console.log(response)
          const data = response.data
          if(response.httpCode == 200){
            _that.$message({
              message: '保存成功',
              type: 'success'
            });
          }else {
            _that.$message.error(response.msg)
          }
        }).catch(err => {
          _that.$message.error(err)
        })
      }


    }
  }
</script>
<style>
  /*处理input type = number的上下箭头*/
  input::-webkit-outer-spin-button,
  input::-webkit-inner-spin-button {
    -webkit-appearance: none;
  }
  input[type="number"]{
    -moz-appearance: textfield;
  }
</style>
<style lang="scss" scoped>
  .filter-container {
    margin-bottom: 15px;
  }
</style>
