vaccineName.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!-- 品种 -->
  2. <template>
  3. <div class="">
  4. <tables ref="TableRef" :requestApi="productList" :columns="columns" :initParam="data.initParam" :border="true">
  5. <template #right="{ row }">
  6. <el-button link type="primary" size="small" @click="showEdit(row)">编辑</el-button>
  7. <el-button link type="danger" size="small" @click="deleteFy(row)">删除</el-button>
  8. </template>
  9. </tables>
  10. </div>
  11. </template>
  12. <script setup lang="ts">
  13. import tables from "@/components/table.vue";
  14. import { productList, productDel, productedit } from "@/api";
  15. import { ElMessage, ElMessageBox } from 'element-plus'
  16. import { reactive,ref} from 'vue'
  17. const TableRef = ref()
  18. // 渲染表格
  19. const columns: any = [
  20. { type: 'index', label: '编号', width: 80, },
  21. { prop: 'name', label: '名称', width: 300 },
  22. { prop: 'operation', label: '操作', fixed: 'right', align: 'left', 'min-width': 200 }
  23. ]
  24. const emit:any = defineEmits(['setTable','setBasic'])
  25. //请求参数
  26. const data: any = reactive({
  27. initParam: {
  28. "name": ""
  29. }
  30. })
  31. /**
  32. * 删除
  33. * @param data 列数据
  34. */
  35. const deleteFy = (data: any) => {
  36. ElMessageBox.confirm('该字段所有已有数据会一同被删除,且无法恢复', '是否确认删除', {
  37. confirmButtonText: '立即删除',
  38. cancelButtonText: '取消',
  39. type: 'error',
  40. center: true,
  41. }).then(async() => {
  42. const reslut:any = await productDel({id:data.id})
  43. if(reslut.code==200)ElMessage.success('删除成功');TableRef.value?.getTableList();emit('setBasic', '')
  44. }).catch(() => {
  45. ElMessage.info('已取消删除')
  46. })
  47. }
  48. //编辑
  49. const showEdit = async (row: any) => {
  50. console.log('编辑',row)
  51. ElMessageBox.prompt(`编辑规格,请填写正确格式`, '编辑', {
  52. confirmButtonText: 'OK',
  53. cancelButtonText: 'Cancel',
  54. inputValue:row.name,
  55. inputPattern: /\S/,
  56. inputErrorMessage: `名称格式不能为空`,
  57. }).then(async ({ value }) => {
  58. const reslut: any = await productedit({id:row.id,name:value})
  59. if (reslut.code == 200 && reslut.msg == '更新成功') {
  60. ElMessage.success(reslut.msg)
  61. emit('setTable', '')
  62. }
  63. }).catch(() => {
  64. ElMessage.info('已取消编辑')
  65. })
  66. }
  67. //暴露方法
  68. defineExpose({
  69. TableRef
  70. })
  71. </script>
  72. <style lang="scss">
  73. /* @import url(); 引入css类 */
  74. </style>