YpPrintName.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="layout_container">
  3. <header>
  4. <el-button type="primary" icon="Plus" @click="onAddItem" style="margin-left: 5px">新增</el-button>
  5. </header>
  6. <div class="layout_main">
  7. <el-table :data="ypPrintNameData" border style="width: 100%" :height="tableHeight" stripe highlight-current-row>
  8. <el-table-column type="index" label="序号" width="80" />
  9. <el-table-column prop="chargeCode" label="药品编码" width="100" />
  10. <el-table-column prop="printName" label="药品别名" width="300">
  11. <template v-slot="scope">
  12. <el-input v-if="scope.row.isEdit" size="small" v-model="scope.row.printName"></el-input>
  13. <span v-else>{{ scope.row.printName }}</span>
  14. </template>
  15. </el-table-column>
  16. <el-table-column prop="pyCode" label="拼音码" width="160" />
  17. <el-table-column prop="dcode" label="五笔码" width="160" />
  18. <el-table-column prop="ypFlag" label="类别" width="120">
  19. <template #default="scope">
  20. <div v-if="scope.row.isEdit">
  21. <el-select v-model="scope.row.ypFlag" clearable placeholder="请选择类别">
  22. <el-option v-for="option in ypFlagOptions" :key="option.code" :label="option.name"
  23. :value="option.code"></el-option>
  24. </el-select>
  25. </div>
  26. <div v-else>
  27. <el-select v-model="scope.row.ypFlag" disabled placeholder="请选择类别">
  28. <el-option v-for="option in ypFlagOptions" :key="option.code" :label="option.name"
  29. :value="option.code"></el-option>
  30. </el-select>
  31. </div>
  32. </template>
  33. </el-table-column>
  34. <el-table-column fixed="right" label="操作" min-width="180" width="180" center>
  35. <template #default="scope">
  36. <el-button type="primary" size="small" v-if="!scope.row.isEdit"
  37. @click="editPrintName(scope.row)">编辑</el-button>
  38. <el-button type="primary" size="small" v-if="scope.row.isEdit"
  39. @click="updatePrintName(scope.row)">保存</el-button>
  40. <el-button type="primary" size="small" v-if="scope.row.isEdit"
  41. @click="cancelPrintName(scope.row)">取消
  42. </el-button>
  43. <el-button type="danger" size="small" @click.prevent="deletePrintName(scope.$index, scope.row)">
  44. 删除
  45. </el-button>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. </div>
  50. </div>
  51. </template>
  52. <script setup name="YpPrintName">
  53. import { ref, onMounted, nextTick } from 'vue'
  54. import { ElMessage, ElMessageBox } from 'element-plus'
  55. import { selectYpPrintNameData, savePrintName, delYpPrintNameByPrintName } from '@/api/yp-dict/yp-print-name.js'
  56. const tableHeight = '500'
  57. const ypFlagOptions = [{ code: 'T', name: '通用名' }, { code: '1', name: '商用名' }, { code: '2', name: '别名' }]
  58. const ypPrintNameData = ref([])
  59. const props = defineProps({
  60. ypPrintNameDetail: {
  61. type: Object,
  62. default: {}
  63. }
  64. })
  65. onMounted(async () => {
  66. await nextTick(() => {
  67. selectYpPrintNameList()
  68. })
  69. })
  70. const selectYpPrintNameList = () => {
  71. selectYpPrintNameData(props.ypPrintNameDetail.chargeCode)
  72. .then((res) => {
  73. res.forEach(row => {
  74. // 是否标记
  75. row['isEdit'] = false
  76. // 是否新增
  77. row['isAdd'] = false
  78. })
  79. ypPrintNameData.value = res
  80. })
  81. .catch(() => {
  82. ypPrintNameData.value = []
  83. })
  84. }
  85. // 新增
  86. const onAddItem = () => {
  87. ypPrintNameData.value.push({
  88. chargeCode: props.ypPrintNameDetail.chargeCode,
  89. printName: '',
  90. ypFlag: '',
  91. pyCode: '',
  92. dCode: '',
  93. isEdit: true,
  94. isAdd: true,
  95. })
  96. }
  97. // 编辑
  98. const editPrintName = (row) => {
  99. // 备份原始数据
  100. row['oldRow'] = JSON.parse(JSON.stringify(row))
  101. row.isEdit = true
  102. }
  103. // 取消
  104. const cancelPrintName = (row) => {
  105. // 如果是新增的数据
  106. if (row.isAdd) {
  107. ypPrintNameData.value.splice(ypPrintNameData.value.length - 1, 1)
  108. } else {
  109. // 不是新增的数据 还原数据
  110. for (const i in row.oldRow) {
  111. row[i] = row.oldRow[i]
  112. }
  113. }
  114. }
  115. // 保存
  116. const updatePrintName = (row) => {
  117. if (row.isAdd) {
  118. let fe = 0
  119. for (let num in ypPrintNameData.value) {
  120. if (ypPrintNameData.value[num].printName === row.printName) {
  121. fe++
  122. }
  123. }
  124. if (fe === 2) {
  125. ElMessage({
  126. type: "warning",
  127. message: "存在重复的药品别名,请核对!",
  128. duration: 2500,
  129. showClose: true,
  130. });
  131. } else {
  132. callSavePrintName(row, null)
  133. }
  134. } else {
  135. if (!row.chargeCode || !row.printName) {
  136. ElMessage({
  137. type: "warning",
  138. message: "药品的编码或别名不存在,请检查!",
  139. duration: 2500,
  140. showClose: true,
  141. });
  142. return
  143. }
  144. let oldName = row.oldRow.printName
  145. if (oldName !== row.printName) {
  146. let fe = 0
  147. for (let num in ypPrintNameData.value) {
  148. if (ypPrintNameData.value[num].printName === row.printName) {
  149. fe++
  150. }
  151. }
  152. if (fe === 2) {
  153. ElMessage({
  154. type: "warning",
  155. message: row.printName + "存在重复的药品别名,请核对!",
  156. duration: 2500,
  157. showClose: true,
  158. });
  159. } else {
  160. callSavePrintName(row, oldName)
  161. }
  162. } else {
  163. callSavePrintName(row, oldName)
  164. }
  165. }
  166. }
  167. const callSavePrintName = (row, oldName) => {
  168. let title = '请确认是否保存<span style="color:#d12020;">' + row.printName + '</span>?'
  169. ElMessageBox.confirm(title, {
  170. cancelButtonText: '取消',
  171. confirmButtonText: '确定',
  172. type: 'warning',
  173. distinguishCancelAndClose: true,
  174. dangerouslyUseHTMLString: true
  175. }).then(() => {
  176. savePrintName(row).then((res) => {
  177. ElMessage({
  178. type: "success",
  179. message: res.cg,
  180. duration: 2500,
  181. showClose: true,
  182. });
  183. if (oldName !== null && oldName !== row.printName) {
  184. // 删除原始数据
  185. delYpPrintNameByPrintName(row.chargeCode, oldName).then((res) => {
  186. selectYpPrintNameList()
  187. })
  188. } else {
  189. selectYpPrintNameList()
  190. }
  191. })
  192. }).catch((action) => {
  193. if (action === 'cancel') {
  194. selectYpPrintNameList()
  195. }
  196. })
  197. }
  198. const deletePrintName = (index, row) => {
  199. let title = '请确认是否删除<span style="color:#d12020;">' + row.printName + '</span>?'
  200. ElMessageBox.confirm(title, {
  201. cancelButtonText: '取消',
  202. confirmButtonText: '确定',
  203. type: 'warning',
  204. distinguishCancelAndClose: true,
  205. dangerouslyUseHTMLString: true
  206. }).then(() => {
  207. delYpPrintNameByPrintName(row.chargeCode, row.printName).then((res) => {
  208. ElMessage({
  209. type: "success",
  210. message: res.cg,
  211. duration: 2500,
  212. showClose: true,
  213. });
  214. selectYpPrintNameList()
  215. })
  216. }).catch((action) => {
  217. if (action === 'cancel') {
  218. selectYpPrintNameList()
  219. }
  220. })
  221. }
  222. </script>