EditKBFileDialog.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="add-kb-file-dialog">
  3. <el-dialog v-model="dialogVisible" title="文件修改" width="1000px" align-center :show-close="false"
  4. @closed="() => { emit('update:modelValue', false) }">
  5. <el-form ref="formRef" style="max-width: 100%" :model="formData" label-width="auto" class="demo-dynamic">
  6. <el-form-item prop="fileTableData" v-show="formData.fileTableData.length > 0">
  7. <div class="file-table">
  8. <el-table :data="formData.fileTableData" border table-layout="fixed" height="400"
  9. style="max-width: 100%;box-sizing: border-box;min-width: 0px;">
  10. <el-table-column type="index" label="#" width="50" />
  11. <el-table-column label="导入文件标题" prop="file_name">
  12. <template #default="{ row, $index }">
  13. <p :contenteditable="true" class="input-box" @blur="updateInputBox($event, $index, 'file_name')">{{
  14. row.file_name }}</p>
  15. </template>
  16. </el-table-column>
  17. <el-table-column label="知识类型" prop="knowledge_type" width="210">
  18. <template #default="{ row }">
  19. <!-- <p>{{ row.knowledge_type }}</p> -->
  20. <el-select v-model="row.knowledge_type" placeholder="Select" style="width: 180px">
  21. <el-option v-for="item in formData.knowledgeTypeOptions" :key="item.value" :label="item.label"
  22. :value="item.value" />
  23. </el-select>
  24. </template>
  25. </el-table-column>
  26. <el-table-column label="版本号" prop="version">
  27. <template #default="{ row, $index }">
  28. <p :contenteditable="true" class="input-box" @blur="updateInputBox($event, $index, 'version')">{{
  29. row.version }}</p>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="作者(主编)" prop="author">
  33. <template #default="{ row, $index }">
  34. <p :contenteditable="true" class="input-box" @blur="updateInputBox($event, $index, 'author')">{{
  35. row.author }}</p>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="年份" prop="year" width="80">
  39. <template #default="{ row, $index }">
  40. <p :contenteditable="true" class="input-box" @blur="updateInputBox($event, $index, 'year', 'number')">
  41. {{ row.year }}
  42. </p>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. </div>
  47. </el-form-item>
  48. </el-form>
  49. <template #footer>
  50. <div class="dialog-footer">
  51. <el-button type="primary" :disabled="formData.fileTableData.length === 0" @click="handleConfirm">
  52. 确认
  53. </el-button>
  54. <el-button @click="handleCancel">取消</el-button>
  55. </div>
  56. </template>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script setup>
  61. import { cloneDeep } from "lodash"
  62. import { ref, watch, getCurrentInstance, toRaw } from "vue"
  63. import { api } from "@/utils/config"
  64. import { ElMessage } from 'element-plus'
  65. const { proxy } = getCurrentInstance()
  66. const props = defineProps({ modelValue: Boolean, fileTable: Array })
  67. const emit = defineEmits(['update:modelValue', 'updateFiles'])
  68. const formData = ref({
  69. id: null,
  70. fileTableData: [],
  71. knowledgeTypeOptions: [
  72. { value: "中华医学会诊疗指南", label: "中华医学会诊疗指南" },
  73. { value: "规培十四五教材", label: "规培十四五教材" },
  74. { value: "临床路径", label: "临床路径" },
  75. ]
  76. })
  77. let dialogVisible = ref(false)
  78. const handleCancel = () => {
  79. emit('update:modelValue', false)
  80. }
  81. const handleConfirm = () => {
  82. updateFiles()
  83. }
  84. watch(() => props.modelValue, (newVal) => {
  85. dialogVisible.value = newVal
  86. }, { immediate: true })
  87. watch(() => props.fileTable, (newVal) => {
  88. formData.value.fileTableData = cloneDeep(newVal) || []
  89. }, { immediate: true, deep: true })
  90. const updateFiles = async () => {
  91. try {
  92. const data = await proxy.$http.put(api.batchUpdate, {
  93. files: formData.value.fileTableData
  94. })
  95. formData.value.fileTableData = []
  96. emit('updateFiles')
  97. emit('update:modelValue', false)
  98. } catch (e) {
  99. console.log(e)
  100. }
  101. }
  102. function updateInputBox(e, index, key, valueType = 'string') {
  103. let value = e.target.innerText || ""
  104. if (valueType === 'number') {
  105. value = Number(value)
  106. }
  107. formData.value.fileTableData[index][key] = value
  108. }
  109. </script>
  110. <style lang="less" scoped>
  111. .add-kb-file-dialog {
  112. :deep(.el-dialog) {
  113. label {
  114. margin: 20px 0px 10px;
  115. display: block;
  116. }
  117. .dialog-footer {
  118. text-align: center;
  119. // gap: 40px;
  120. .el-button {
  121. padding: 19px 50px;
  122. margin-left: 50px;
  123. &:first-child {
  124. margin-left: 0px;
  125. }
  126. }
  127. }
  128. }
  129. :deep(.el-form) {
  130. .input-box {
  131. &:focus {
  132. outline: none;
  133. }
  134. }
  135. .el-textarea__inner,
  136. .el-input__wrapper {
  137. background-color: #F1F3F6;
  138. }
  139. .import-method {
  140. .el-radio-button {
  141. // margin: 10px 0px;
  142. padding: 2px;
  143. background: #E3E8F0;
  144. &:is(.is-active) {
  145. .el-radio-button__inner {
  146. background-color: white;
  147. color: #306FF3;
  148. }
  149. }
  150. &:first-child {
  151. border-radius: 10px 0px 0px 10px;
  152. }
  153. &:last-child {
  154. border-radius: 0px 10px 10px 0px;
  155. }
  156. .el-radio-button__inner {
  157. color: #859299;
  158. border-radius: 10px;
  159. background-color: transparent;
  160. border: none;
  161. padding: 10px 30px;
  162. box-shadow: none;
  163. }
  164. }
  165. }
  166. .file-type {
  167. display: flex;
  168. gap: 10px;
  169. .file-type-box {
  170. width: 250px;
  171. border: 1px solid #EDEDEF;
  172. padding: 10px;
  173. border-radius: 10px;
  174. &:is(.active) {
  175. border-color: #4B73F2;
  176. background-color: #EEF3FE;
  177. .title {
  178. .name {
  179. color: #4B73F2;
  180. }
  181. }
  182. }
  183. .title {
  184. display: flex;
  185. align-items: center;
  186. .name {
  187. color: #000;
  188. }
  189. }
  190. }
  191. }
  192. .file-table {
  193. flex: 1 1 auto;
  194. }
  195. }
  196. .moxing1-icon {
  197. width: 24px;
  198. height: 24px;
  199. }
  200. }
  201. </style>