info.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <script >
  2. import langMap from "@/map/langMap";
  3. import {apiMap} from "@/map/apiMap";
  4. import {handle} from "@/until/handle";
  5. import {rCode} from "@/map/rcodeMap_esm";
  6. import {unescapeHtml} from "@/until/unescapeHtml";
  7. import {timestampToTime} from "@/until/time";
  8. import RoundedTitle from "@/components/public/roundedTitle.vue";
  9. export default {
  10. name: "productInfoView",
  11. components: {RoundedTitle},
  12. data() {
  13. return {
  14. loading: false,
  15. productInfo: {},
  16. // 英文的产品信息
  17. productId: 0,
  18. lang: langMap.lang.zh,
  19. showImage: ''
  20. }
  21. },
  22. beforeMount() {
  23. this.productId = this.$route.query.id;
  24. this.loadProductInfo();
  25. },
  26. computed: {
  27. },
  28. methods: {
  29. async loadProductInfo() {
  30. let productId = this.productId;
  31. if (!productId) {
  32. this.$message.error('未获取到产品id');
  33. return;
  34. }
  35. this.loading = true;
  36. let url = apiMap.productInfo.path;
  37. url += `/${productId}?lang=${this.lang}`
  38. let [err, res] = await handle(this.$axios.get(url));
  39. this.loading = false;
  40. if (err) {
  41. this.$message.error('获取产品信息失败');
  42. return console.log(err);
  43. }
  44. let result = res.data;
  45. if (result.code !== rCode.OK) {
  46. this.$message.error(`获取产品信息失败,${result.msg}`)
  47. return
  48. }
  49. let data = result.data;
  50. data.showImage = data.image;
  51. this.productInfo = result.data;
  52. },
  53. deleteProduct(){
  54. this.$confirm({
  55. title: '删除产品',
  56. content: '是否删除该产品?',
  57. okText: '删除',
  58. okType: 'danger',
  59. cancelText: '取消',
  60. onOk: async () => {
  61. this.executeDelete();
  62. },
  63. });
  64. },
  65. async executeDelete() {
  66. let productId = this.productId;
  67. if (!productId) {
  68. this.$message.error('未获取到产品id');
  69. return;
  70. }
  71. let url = apiMap.productDelete.path;
  72. url += `?id=${productId}`
  73. let [err, res] = await handle(this.$axios.post(url, {
  74. id: productId
  75. }));
  76. if(err){
  77. this.$message.error(`删除产品失败, 出现异常:${err.message}`);
  78. return console.log(err);
  79. }
  80. let result = res.data;
  81. if (result.code !== rCode.OK) {
  82. this.$message.error(`删除产品失败,${result.msg}`)
  83. console.log(result)
  84. return
  85. }
  86. this.$message.success('删除产品成功');
  87. window.location.href = '/manger/product';
  88. },
  89. getLangText(str) {
  90. return langMap.getText(this.lang, str);
  91. },
  92. }
  93. }
  94. </script>
  95. <template>
  96. <div class="page p-2">
  97. <rounded-title class="text-xl flex justify-between">
  98. <a href="/manger/product">产品详情</a>
  99. <a :href="`/manger/product/edit?id=${productInfo.proid}`"
  100. class="edit-btn custom-btn btn-13">
  101. 编辑
  102. </a>
  103. <a-button type="danger" @click="deleteProduct">
  104. 删除产品
  105. </a-button>
  106. </rounded-title>
  107. <div class="product-show">
  108. <product-info
  109. :product="productInfo"
  110. :lang="lang"
  111. :productId="productId"
  112. />
  113. </div>
  114. </div>
  115. </template>
  116. <style scoped>
  117. .page{
  118. width: 100%;
  119. height: calc(100% - 60px);
  120. }
  121. .product-show{
  122. margin-top: 20px;
  123. width: 100%;
  124. height: calc(100% - 50px);
  125. overflow: auto;
  126. background-color: #fff;
  127. border-radius: 10px;
  128. }
  129. .edit-btn{
  130. font-size: 14px;
  131. }
  132. </style>