TitleCommon_shangfei.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div>
  3. <div class="form-tip">{{ '提示:' + getTipByTab(props.tab) }}</div>
  4. <el-form inline ref="ruleFormRef" :model="form">
  5. <el-form-item style="margin-top: 0px">
  6. <el-input
  7. v-model="form.name"
  8. :placeholder="`请输入` + props.type + `名称`"
  9. class="input-with-select"
  10. >
  11. <template #append>
  12. <el-button :icon="Search" @click="findDataByName(ruleFormRef)" />
  13. </template>
  14. </el-input>
  15. <!-- <el-input style="width: 200px" :placeholder="`请输入` + props.type + `名称`" v-model="form.name" clearable
  16. @clear="clearData" /> -->
  17. </el-form-item>
  18. <!-- <el-button type="primary" :icon="Search" @click="findDataByName(ruleFormRef)">查询</el-button> -->
  19. <el-button
  20. type="primary"
  21. :icon="Plus"
  22. @click="addForm"
  23. style="position: absolute; right: 0; width: 100px"
  24. v-if="props.type === '标签'"
  25. >
  26. {{ props.type }}</el-button
  27. >
  28. </el-form>
  29. </div>
  30. <el-drawer
  31. v-model="titleDrawer"
  32. direction="rtl"
  33. :title="props.type === '模板' ? '添加模板' : '添加标签'"
  34. :before-close="handleClose"
  35. >
  36. <DrawerCommonVue_shangfei
  37. :detail="drawerFormData"
  38. :type="props.type"
  39. @submit-drawer="submitDrawer"
  40. />
  41. </el-drawer>
  42. </template>
  43. <script setup lang="ts">
  44. import { Search, Plus } from '@element-plus/icons-vue';
  45. import { onMounted, ref, watch } from 'vue';
  46. import { ElMessageBox, FormInstance } from 'element-plus';
  47. import DrawerCommonVue_shangfei, { FormModelCommon } from './DrawerCommon_shangfei.vue';
  48. import { useKeyPress } from 'vue-hooks-plus';
  49. import { LabelType, getTipByTab } from './constant';
  50. export type CreateType = '添加模板' | '修改模板';
  51. const props = defineProps<{
  52. type: string;
  53. pagesize: number;
  54. pagenumber: number;
  55. drawer: boolean;
  56. tab: LabelType;
  57. }>();
  58. const emit = defineEmits([
  59. 'findDataByName',
  60. 'submitDrawer',
  61. 'handleClose',
  62. 'addForm',
  63. 'clearData',
  64. ]);
  65. const form = ref({
  66. name: '',
  67. });
  68. const ruleFormRef = ref<FormInstance>();
  69. const currentType = ref<CreateType>('添加模板');
  70. const defaultFormValue = { id: 0, code: '', name: '', remark: '', status: 0 };
  71. const drawerFormData = ref<FormModelCommon>({ ...defaultFormValue } as FormModelCommon);
  72. export interface DataCommon {
  73. name: string;
  74. size: number;
  75. page: number;
  76. }
  77. useKeyPress('enter', () => {
  78. findDataByName(ruleFormRef.value);
  79. });
  80. const titleDrawer = ref(false);
  81. watch(
  82. () => props.drawer,
  83. (newdrawer) => {
  84. titleDrawer.value = newdrawer;
  85. },
  86. { immediate: true },
  87. );
  88. // 根据名称找到数据-finish
  89. function findDataByName(formEl: FormInstance | undefined) {
  90. console.log('findDataByName');
  91. if (!formEl) return;
  92. formEl.validate((valid, fields) => {
  93. if (valid) {
  94. const data = ref<DataCommon>({
  95. name: form.value.name,
  96. size: props.pagesize,
  97. page: props.pagenumber,
  98. });
  99. emit('findDataByName', data.value);
  100. } else {
  101. console.log('error submit!', fields);
  102. }
  103. });
  104. }
  105. function addForm() {
  106. currentType.value = '添加模板';
  107. emit('addForm');
  108. }
  109. // 添加
  110. function submitDrawer(data) {
  111. emit('submitDrawer', data);
  112. setTimeout(() => {
  113. drawerFormData.value = { ...defaultFormValue };
  114. }, 500);
  115. }
  116. const handleClose = (done: () => void) => {
  117. done();
  118. emit('handleClose');
  119. };
  120. // function clearData() {
  121. // emit('clearData');
  122. // }
  123. onMounted(() => {});
  124. </script>
  125. <style scoped>
  126. .form-tip {
  127. font-family: PingFangSC, PingFang SC;
  128. font-weight: 400;
  129. font-size: 12px;
  130. color: #909399;
  131. line-height: 38px;
  132. text-align: left;
  133. font-style: normal;
  134. }
  135. </style>