<script >
import langMap from "@/map/langMap";
import {apiMap} from "@/map/apiMap";
import {handle} from "@/until/handle";
import {rCode} from "@/map/rcodeMap_esm";
import {unescapeHtml} from "@/until/unescapeHtml";
import {timestampToTime} from "@/until/time";
import RoundedTitle from "@/components/public/roundedTitle.vue";
import productAdd from "@/pages/manger/product/add.vue"
export default {
  name: "productInfoView",
  components: {RoundedTitle, productAdd},
  data() {
    return {
      loading: false,
      productInfo: {},
      // 英文的产品信息
      productId: '',
      lang: langMap.lang.zh,
      showImage: ''
    }
  },
  beforeMount() {
    this.productId = this.$route.query.id;
    this.loadProductInfo();
  },
  computed: {
  },
  methods: {
    async loadProductInfo() {
      let productId = this.productId;
      if (!productId) {
        this.$message.error('未获取到产品id');
        return;
      }
      this.loading = true;
      let url = apiMap.productInfo.path;
      url += `/${productId}?lang=${this.lang}`
      let [err, res] = await handle(this.$axios.get(url));
      this.loading = false;
      if (err) {
        this.$message.error('获取产品信息失败');
        return console.log(err);
      }
      let result = res.data;
      if (result.code !== rCode.OK) {
        this.$message.error(`获取产品信息失败,${result.msg}`)
        return
      }
      console.log(result)
      let data = result.data;
      data.showImage = data.image;
      this.productInfo = data;
    },
    getLangText(str) {
      return langMap.getText(this.lang, str);
    },
  }
}
</script>

<template>
  <product-add :product="productInfo" :lang="lang" />
</template>

<style scoped>
.page{
  width: 100%;
  height: calc(100% - 60px);
}
.product-show{
  margin-top: 20px;
  width: 100%;
  height: calc(100% - 50px);
  overflow: auto;
  background-color: #fff;
  border-radius: 10px;
}
.edit-btn{
  font-size: 14px;
}


</style>
