product.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div>
  3. <el-card>
  4. <el-button type="primary" @click="() => router.push({ path: '/product/add' })">添加产品服务
  5. </el-button>
  6. <!-- 添加el-dialog组件 -->
  7. <el-table :data="tableData" border style="width: 100%;margin-top:20px">
  8. <el-table-column label="序号" width="60">
  9. <template #default="scope">
  10. {{ scope.$index + 1 }}
  11. </template>
  12. </el-table-column>
  13. <el-table-column label="图片" width="120">
  14. <template #default="scope">
  15. <img :src="scope.row.url" alt="图片" style="max-width: 100%; height: auto;">
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="title" label="名称" width="180">
  19. <template #default="scope">
  20. {{ scope.row.title }}
  21. </template>
  22. </el-table-column>
  23. <el-table-column prop="title" label="是否首页显示" width="180">
  24. <template #default="scope">
  25. <el-switch v-model="scope.row.isIndex" size="large" active-text="显示" inactive-text="不显示"
  26. @change="updateProductsIsindex(scope.row)" />
  27. </template>
  28. </el-table-column>
  29. <el-table-column prop="ptype" label="产品类型" width="180">
  30. <template #default="scope">
  31. {{ ptypeMapping[scope.row.ptype] || '服务' }}
  32. </template>
  33. </el-table-column>
  34. <el-table-column prop="type" label="类型" width="180">
  35. <template #default="scope">
  36. {{ typeMapping[scope.row.type] || '其他' }}
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="操作" width="200">
  40. <template #default="scope">
  41. <el-button type="danger" size="small" @click="deleteProduct(scope.row.ID)">删除</el-button>
  42. <!-- <el-button type="primary" size="small" @click="deleteResource(scope.row.ID)">修改</el-button>-->
  43. <el-button size="small"
  44. @click="() => router.push({ path: '/product/detail', query: { id: scope.row.ID } })">
  45. 详情
  46. </el-button>
  47. </template>
  48. </el-table-column>
  49. </el-table>
  50. <!-- 分页 -->
  51. <el-pagination style="margin-top:20px" :current-page="searchForm.page" :page-size="searchForm.size"
  52. :total="total" @current-change="handleCurrentChange" />
  53. </el-card>
  54. </div>
  55. </template>
  56. <script setup>
  57. import { onMounted, reactive, ref } from "vue";
  58. import { ElMessage, ElMessageBox } from 'element-plus';
  59. import { useRouter } from 'vue-router'
  60. import resource from "../../api/resource";
  61. import product from "../../api/product.js";
  62. const isIndex = ref(false)
  63. const router = useRouter();
  64. // Dom 挂载之后
  65. onMounted(() => {
  66. getProductAll();
  67. })
  68. // 资源数据
  69. const ptypeMapping = {
  70. hardware: '硬件',
  71. software: '软件',
  72. example: '合作案列',
  73. 4: ''
  74. }
  75. const typeMapping = {
  76. serve: '服务',
  77. product: '产品',
  78. example: '合作案列',
  79. 4: ''
  80. }
  81. const productDetail = reactive({
  82. ID: '',
  83. type: '',
  84. isIndex: '',
  85. ptype: '',
  86. title: '',
  87. parentId: '',
  88. synopsis: '',
  89. detail: '',
  90. url: '',
  91. product_introduction: '',
  92. technical_parameters: '',
  93. instructions: '',
  94. supporting_software: '',
  95. optional_accessories: '',
  96. is_active: '',
  97. })
  98. const showUpload = ref(false);
  99. const showUploadDialog = ref(false);
  100. let tableData = ref([]);
  101. let total = ref(0);
  102. const toggleUpload = () => {
  103. showUpload.value = !showUpload.value;
  104. };
  105. // 搜索条件
  106. const searchForm = reactive({
  107. page: 1,
  108. size: 10,
  109. desc: 'created_at desc'
  110. })
  111. // 获取资源列表
  112. const getProductAll = async () => {
  113. const res = await product.getProductList(searchForm);
  114. tableData.value = res.data.Data.Data;
  115. total.value = res.data.Data.Size;
  116. }
  117. const updateProducts = async (row) => {
  118. const res = await product.updateProduct({ id: row.ID, isIndex: row.isIndex });
  119. if (res.data.Code === 200) {
  120. ElMessage.success("修改成功")
  121. // await getProductAll();
  122. } else {
  123. ElMessage.error(res.data.Msg)
  124. }
  125. }
  126. //根据id修改产品状态
  127. const updateProductsIsindex = async (row) => {
  128. const res = await product.updateProductIsindex({ id: row.ID, isIndex: row.isIndex });
  129. if (res.data.Code === 200) {
  130. ElMessage.success("修改成功")
  131. // await getProductAll();
  132. } else {
  133. ElMessage.error(res.data.Msg)
  134. }
  135. }
  136. const handleSizeChange = (size) => {
  137. searchForm.size = size;
  138. getProductList();
  139. }
  140. const handleCurrentChange = (current) => {
  141. searchForm.page = current;
  142. getProductAll();
  143. }
  144. const searchUser = () => {
  145. searchForm.current = 1;
  146. getProductAll();
  147. }
  148. // 删除资源信息
  149. const deleteProduct = (id) => {
  150. ElMessageBox.confirm(
  151. '确定要删除该资源信息吗?',
  152. {
  153. confirmButtonText: '确定',
  154. cancelButtonText: '取消',
  155. type: 'warning',
  156. }
  157. ).then(async () => {
  158. const res = await product.deleteProduct({ id: id });
  159. if (res.data.code === 200) {
  160. ElMessage.success("删除成功")
  161. await getProductAll();
  162. } else {
  163. ElMessage.error(res.data.Msg)
  164. }
  165. }).catch(() => {
  166. ElMessage({
  167. type: 'info',
  168. message: '取消删除',
  169. })
  170. })
  171. }
  172. </script>
  173. <style lang="scss" scoped></style>