YpPrintName.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <PageLayer>
  3. <template #header class="hd-cl">
  4. <el-button type="primary" icon="Plus" @click="onAddItem" style="margin-left: 5px">新增</el-button>
  5. </template>
  6. <template #mainMaxContentHeight>
  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. </template>
  50. </PageLayer>
  51. </template>
  52. <script setup name="YpPrintName">
  53. import { ref, onMounted, nextTick } from 'vue'
  54. import PageLayer from '@/layout/PageLayer.vue'
  55. import { ElMessage, ElMessageBox } from 'element-plus'
  56. import { selectYpPrintNameData, savePrintName, delYpPrintNameByPrintName } from '@/api/yp-dict/yp-print-name.js'
  57. const tableHeight = '500'
  58. const ypFlagOptions = [{ code: 'T', name: '通用名' }, { code: '1', name: '商用名' }, { code: '2', name: '别名' }]
  59. const ypPrintNameData = ref([])
  60. const props = defineProps({
  61. ypPrintNameDetail: {
  62. type: Object,
  63. default: {}
  64. }
  65. })
  66. onMounted(async () => {
  67. await nextTick(() => {
  68. selectYpPrintNameList()
  69. })
  70. })
  71. const selectYpPrintNameList = () => {
  72. selectYpPrintNameData(props.ypPrintNameDetail.chargeCode)
  73. .then((res) => {
  74. res.forEach(row => {
  75. // 是否标记
  76. row['isEdit'] = false
  77. // 是否新增
  78. row['isAdd'] = false
  79. })
  80. ypPrintNameData.value = res
  81. })
  82. .catch(() => {
  83. ypPrintNameData.value = []
  84. })
  85. }
  86. // 新增
  87. const onAddItem = () => {
  88. ypPrintNameData.value.push({
  89. chargeCode: '',
  90. printName: '',
  91. ypFlag: '',
  92. pyCode: '',
  93. dCode: '',
  94. isEdit: true,
  95. isAdd: true,
  96. })
  97. }
  98. // 编辑
  99. const editPrintName = (row) => {
  100. // 备份原始数据
  101. row['oldRow'] = JSON.parse(JSON.stringify(row))
  102. row.isEdit = true
  103. }
  104. // 取消
  105. const cancelPrintName = (row) => {
  106. // 如果是新增的数据
  107. if (row.isAdd) {
  108. ypPrintNameData.value.splice(ypPrintNameData.value.length - 1, 1)
  109. } else {
  110. // 不是新增的数据 还原数据
  111. for (const i in row.oldRow) {
  112. row[i] = row.oldRow[i]
  113. }
  114. }
  115. }
  116. // 保存
  117. const updatePrintName = (row) => {
  118. if (!row.chargeCode || !row.printName) {
  119. ElMessage({
  120. type: "warning",
  121. message: "药品的编码或别名不存在,请检查!",
  122. duration: 2500,
  123. showClose: true,
  124. });
  125. return
  126. }
  127. if (row.isAdd) {
  128. let fe = 0
  129. for (let num in ypPrintNameData.value) {
  130. if (ypPrintNameData.value[num].printName === row.printName) {
  131. fe++
  132. }
  133. }
  134. if (fe == 2) {
  135. ElMessage({
  136. type: "warning",
  137. message: "存在重复的药品别名,请核对!",
  138. duration: 2500,
  139. showClose: true,
  140. });
  141. return
  142. } else {
  143. callSavePrintName(row, null)
  144. }
  145. } else {
  146. let oldName = row.oldRow.printName
  147. if (oldName !== row.printName) {
  148. let fe = 0
  149. for (let num in ypPrintNameData.value) {
  150. if (ypPrintNameData.value[num].printName === row.printName) {
  151. fe++
  152. }
  153. }
  154. if (fe == 2) {
  155. ElMessage({
  156. type: "warning",
  157. message: row.printName + "存在重复的药品别名,请核对!",
  158. duration: 2500,
  159. showClose: true,
  160. });
  161. return
  162. } else {
  163. callSavePrintName(row, oldName)
  164. }
  165. } else {
  166. callSavePrintName(row, oldName)
  167. }
  168. }
  169. }
  170. const callSavePrintName = (row, oldName) => {
  171. let title = '请确认是否保存<span style="color:#d12020;">' + row.printName + '</span>?'
  172. ElMessageBox.confirm(title, {
  173. cancelButtonText: '取消',
  174. confirmButtonText: '确定',
  175. type: 'warning',
  176. distinguishCancelAndClose: true,
  177. dangerouslyUseHTMLString: true
  178. }).then(() => {
  179. savePrintName(row).then((res) => {
  180. ElMessage({
  181. type: "success",
  182. message: res.cg,
  183. duration: 2500,
  184. showClose: true,
  185. });
  186. if (oldName !== null && oldName !== row.printName) {
  187. // 删除原始数据
  188. delYpPrintNameByPrintName(row.chargeCode, oldName).then((res) => {
  189. selectYpPrintNameList()
  190. })
  191. return
  192. } else {
  193. selectYpPrintNameList()
  194. }
  195. })
  196. }).catch((action) => {
  197. if (action === 'cancel') {
  198. selectYpPrintNameList()
  199. }
  200. })
  201. }
  202. const deletePrintName = (index, row) => {
  203. let title = '请确认是否删除<span style="color:#d12020;">' + row.printName + '</span>?'
  204. ElMessageBox.confirm(title, {
  205. cancelButtonText: '取消',
  206. confirmButtonText: '确定',
  207. type: 'warning',
  208. distinguishCancelAndClose: true,
  209. dangerouslyUseHTMLString: true
  210. }).then(() => {
  211. delYpPrintNameByPrintName(row.chargeCode, row.printName).then((res) => {
  212. ElMessage({
  213. type: "success",
  214. message: res.cg,
  215. duration: 2500,
  216. showClose: true,
  217. });
  218. selectYpPrintNameList()
  219. return
  220. })
  221. }).catch((action) => {
  222. if (action === 'cancel') {
  223. selectYpPrintNameList()
  224. }
  225. })
  226. }
  227. </script>