HealthEducation.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <page-layer>
  3. <template #header>
  4. <el-button type="primary" icon="Plus" @click="onAddItem" style="margin-left: 5px">新增</el-button>
  5. </template>
  6. <template #main>
  7. <el-tabs v-model="editableTabsValue" type="border-card" @tab-click="handleClick">
  8. <el-tab-pane key="healthEducation" label="健康教育字典" name="healthEducation">
  9. <el-table :data="healthEducationData" border style="width: 100%" stripe highlight-current-row
  10. :key="healthEducationKey">
  11. <el-table-column type="index" label="序号" width="100" />
  12. <el-table-column prop="code" label="编码" width="100"></el-table-column>
  13. <el-table-column prop="name" label="名称" width="280">
  14. <template v-slot="scope">
  15. <el-input v-if="scope.row.isEdit" size="small" v-model="scope.row.name"></el-input>
  16. <span v-else>{{ scope.row.name }}</span>
  17. </template>
  18. </el-table-column>
  19. <el-table-column prop="sortNo" label="排序" width="80">
  20. <template v-slot="scope">
  21. <el-input v-if="scope.row.isEdit" size="small" v-model="scope.row.sortNo"></el-input>
  22. <span v-else>{{ scope.row.sortNo }}</span>
  23. </template>
  24. </el-table-column>
  25. <el-table-column prop="url" label="路径" width="320">
  26. <template v-slot="scope">
  27. <el-input v-if="scope.row.isEdit" size="small" v-model="scope.row.url"></el-input>
  28. <span v-else>{{ scope.row.url }}</span>
  29. </template>
  30. </el-table-column>
  31. <el-table-column prop="type" label="类型" width="180">
  32. <template v-slot="scope">
  33. <div v-if="scope.row.isEdit">
  34. <el-select v-model="scope.row.type" clearable placeholder="请选择类型">
  35. <el-option v-for="option in HETypeOptions" :key="option.code" :label="option.name"
  36. :value="option.code"></el-option>
  37. </el-select>
  38. </div>
  39. <div v-else>
  40. <el-select v-model="scope.row.type" disabled placeholder="请选择类型">
  41. <el-option v-for="option in HETypeOptions" :key="option.code" :label="option.name"
  42. :value="option.code"></el-option>
  43. </el-select>
  44. </div>
  45. </template>
  46. </el-table-column>
  47. <el-table-column fixed="right" label="操作" min-width="180" width="180" center>
  48. <template #default="scope">
  49. <el-button type="primary" size="small" v-if="!scope.row.isEdit"
  50. @click="editHealthEducation(scope.row)">编辑</el-button>
  51. <el-button type="primary" size="small" v-if="scope.row.isEdit"
  52. @click="updateHealthEducation(scope.row)">保存</el-button>
  53. <el-button type="primary" size="small" v-if="scope.row.isEdit"
  54. @click="cancelHealthEducation(scope.row, scope.$index)">取消
  55. </el-button>
  56. <el-button type="danger" size="small"
  57. @click.prevent="deleteHealthEducation(scope.$index, scope.row)">
  58. 删除
  59. </el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. </el-tab-pane>
  64. <el-tab-pane key="heType" label="健康教育类型" name="heType">
  65. <el-table :data="heTypeData" border style="width: 100%" stripe highlight-current-row
  66. :key="heTypeKey">
  67. <el-table-column type="index" label="序号" width="100" />
  68. <el-table-column prop="code" label="类型编码" width="100">
  69. <template v-slot="scope">
  70. <el-input v-if="scope.row.isEdit" size="small" v-model="scope.row.code"></el-input>
  71. <span v-else>{{ scope.row.code }}</span>
  72. </template>
  73. </el-table-column>
  74. <el-table-column prop="name" label="名称" width="360">
  75. <template v-slot="scope">
  76. <el-input v-if="scope.row.isEdit" size="small" v-model="scope.row.name"></el-input>
  77. <span v-else>{{ scope.row.name }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column prop="sort" label="排序" width="100">
  81. <template v-slot="scope">
  82. <el-input v-if="scope.row.isEdit" size="small" v-model="scope.row.sort"></el-input>
  83. <span v-else>{{ scope.row.sort }}</span>
  84. </template>
  85. </el-table-column>
  86. <el-table-column prop="delFlag" label="是否有效" width="150">
  87. <template v-slot="scope">
  88. <div v-if="scope.row.isEdit">
  89. <el-select v-model="scope.row.delFlag" clearable placeholder="请选择是否有效">
  90. <el-option v-for="option in delFlagOptions" :key="option.code" :label="option.name"
  91. :value="option.code"></el-option>
  92. </el-select>
  93. </div>
  94. <div v-else>
  95. <el-select v-model="scope.row.delFlag" disabled placeholder="请选择是否有效">
  96. <el-option v-for="option in delFlagOptions" :key="option.code" :label="option.name"
  97. :value="option.code"></el-option>
  98. </el-select>
  99. </div>
  100. </template>
  101. </el-table-column>
  102. <el-table-column fixed="right" label="操作" min-width="180" width="180" center>
  103. <template #default="scope">
  104. <el-button type="primary" size="small" v-if="!scope.row.isEdit"
  105. @click="editHeType(scope.row)">编辑</el-button>
  106. <el-button type="primary" size="small" v-if="scope.row.isEdit"
  107. @click="updateHeType(scope.row)">保存</el-button>
  108. <el-button type="primary" size="small" v-if="scope.row.isEdit"
  109. @click="cancelHeType(scope.row, scope.$index)">取消
  110. </el-button>
  111. <el-button type="danger" size="small"
  112. @click.prevent="deleteHeType(scope.$index, scope.row)">
  113. 删除
  114. </el-button>
  115. </template>
  116. </el-table-column>
  117. </el-table>
  118. </el-tab-pane>
  119. </el-tabs>
  120. </template>
  121. </page-layer>
  122. </template>
  123. <script setup name="HealthEducation">
  124. import { ref, onMounted, nextTick } from 'vue'
  125. import PageLayer from '@/layout/PageLayer.vue'
  126. import { ElMessage, ElMessageBox } from 'element-plus'
  127. import {
  128. selectServiceNumberDict, selectHealthEducation, saveHealthEducation, delHealthEducationByCode,
  129. selectHeType, saveHeType, delHeTypeByCode
  130. } from '@/api/dictionary/serviceNumber/health-education.js'
  131. const editableTabsValue = ref('healthEducation')
  132. const megTip = '编码(code)有变更,原始字典记录存在关联,请谨慎做更改,是否确认!!!'
  133. const delFlagOptions = [{ code: '0', name: '有效' }, { code: '1', name: '无效' }]
  134. let healthEducationKey = ref(1)
  135. const HETypeOptions = ref([])
  136. const healthEducationData = ref([])
  137. let heTypeKey = ref(1)
  138. const heTypeData = ref([])
  139. onMounted(() => {
  140. nextTick(() => {
  141. queryServiceNumberDict()
  142. queryHealthEducation()
  143. })
  144. })
  145. const queryServiceNumberDict = () => {
  146. selectServiceNumberDict()
  147. .then((res) => {
  148. HETypeOptions.value = res.HEType
  149. })
  150. .catch(() => {
  151. HETypeOptions.value = []
  152. })
  153. }
  154. // 查询服务号字典中健康教育字典
  155. const queryHealthEducation = () => {
  156. selectHealthEducation()
  157. .then(res => {
  158. res.forEach(row => {
  159. // 是否标记
  160. row['isEdit'] = false
  161. // 是否新增
  162. row['isAdd'] = false
  163. })
  164. healthEducationData.value = res
  165. })
  166. .catch(() => {
  167. healthEducationData.value = []
  168. })
  169. }
  170. // 查询服务号字典中健康教育类型字典
  171. const queryHeType = () => {
  172. selectHeType()
  173. .then(res => {
  174. res.forEach(row => {
  175. // 是否标记
  176. row['isEdit'] = false
  177. // 是否新增
  178. row['isAdd'] = false
  179. })
  180. heTypeData.value = res
  181. })
  182. .catch(() => {
  183. heTypeData.value = []
  184. })
  185. }
  186. // 新增行
  187. const onAddItem = () => {
  188. if (editableTabsValue.value === 'healthEducation') {
  189. healthEducationData.value.push({
  190. code: '',
  191. name: '',
  192. sortNo: '',
  193. url: '',
  194. type: '',
  195. isEdit: true,
  196. isAdd: true,
  197. })
  198. } else if(editableTabsValue.value === 'heType'){
  199. heTypeData.value.push({
  200. code: '',
  201. name: '',
  202. sort: '',
  203. delFlag: '',
  204. isEdit: true,
  205. isAdd: true,
  206. })
  207. }
  208. }
  209. // 服务号字典中健康教育字典增删改存开始
  210. // 编辑
  211. const editHealthEducation = (row) => {
  212. // 备份原始数据
  213. row['oldRow'] = JSON.parse(JSON.stringify(row))
  214. row.isEdit = true
  215. }
  216. // 取消
  217. const cancelHealthEducation = (row, index) => {
  218. // 如果是新增的数据
  219. if (row.isAdd) {
  220. healthEducationData.value.splice(index, 1)
  221. } else {
  222. // 不是新增的数据 还原数据
  223. for (const i in row.oldRow) {
  224. row[i] = row.oldRow[i]
  225. }
  226. }
  227. healthEducationKey.value = Math.random()
  228. }
  229. // 保存
  230. const updateHealthEducation = (row) => {
  231. if (row.isAdd) {
  232. let fe = 0
  233. for (let num in healthEducationData.value) {
  234. if (healthEducationData.value[num].code === row.code) {
  235. fe++
  236. }
  237. }
  238. if (fe == 2) {
  239. ElMessage({
  240. type: "warning",
  241. message: "存在重复的健康教育,请核对!",
  242. duration: 2500,
  243. showClose: true,
  244. });
  245. } else {
  246. callSaveHealthEducation(row, null)
  247. }
  248. } else {
  249. if (!row.code || !row.name) {
  250. ElMessage({
  251. type: "warning",
  252. message: "健康教育编码或名称不存在,请检查!",
  253. duration: 2500,
  254. showClose: true,
  255. });
  256. return
  257. }
  258. let oldCode = row.oldRow.code
  259. if (oldCode !== row.code) {
  260. ElMessageBox.confirm(megTip, {
  261. cancelButtonText: '取消',
  262. confirmButtonText: '确定',
  263. type: 'warning',
  264. distinguishCancelAndClose: true,
  265. dangerouslyUseHTMLString: true
  266. }).then(() => {
  267. callSaveHealthEducation(row, oldCode)
  268. }).catch((action) => {
  269. if (action === 'cancel') {
  270. queryHealthEducation()
  271. }
  272. })
  273. } else {
  274. callSaveHealthEducation(row, oldCode)
  275. }
  276. }
  277. }
  278. const callSaveHealthEducation = (row, oldCode) => {
  279. let title = '请确认是否保存<span style="color:#d12020;">' + row.name + '</span>?'
  280. ElMessageBox.confirm(title, {
  281. cancelButtonText: '取消',
  282. confirmButtonText: '确定',
  283. type: 'warning',
  284. distinguishCancelAndClose: true,
  285. dangerouslyUseHTMLString: true
  286. }).then(() => {
  287. saveHealthEducation(row).then((res) => {
  288. ElMessage({
  289. type: "success",
  290. message: res.cg,
  291. duration: 2500,
  292. showClose: true,
  293. });
  294. if (oldCode !== null && oldCode !== row.code) {
  295. // 删除原始数据
  296. delHealthEducationByCode(oldCode).then((res) => {
  297. queryHealthEducation()
  298. })
  299. return
  300. } else {
  301. queryHealthEducation()
  302. }
  303. })
  304. }).catch((action) => {
  305. if (action === 'cancel') {
  306. queryHealthEducation()
  307. }
  308. })
  309. }
  310. const deleteHealthEducation = (index, row) => {
  311. let title = '请确认是否删除<span style="color:#d12020;">' + row.name + '</span>?'
  312. ElMessageBox.confirm(title, {
  313. cancelButtonText: '取消',
  314. confirmButtonText: '确定',
  315. type: 'warning',
  316. distinguishCancelAndClose: true,
  317. dangerouslyUseHTMLString: true
  318. }).then(() => {
  319. delHealthEducationByCode(row.code).then((res) => {
  320. ElMessage({
  321. type: "success",
  322. message: res.cg,
  323. duration: 2500,
  324. showClose: true,
  325. });
  326. queryHealthEducation()
  327. return
  328. })
  329. }).catch((action) => {
  330. if (action === 'cancel') {
  331. queryHealthEducation()
  332. }
  333. })
  334. }
  335. // 服务号字典中健康教育字典增删改存结束
  336. // 服务号字典中健康教育类型字典增删改存开始
  337. // 编辑
  338. const editHeType = (row) => {
  339. // 备份原始数据
  340. row['oldRow'] = JSON.parse(JSON.stringify(row))
  341. row.isEdit = true
  342. }
  343. // 取消
  344. const cancelHeType = (row, index) => {
  345. // 如果是新增的数据
  346. if (row.isAdd) {
  347. heTypeData.value.splice(index, 1)
  348. } else {
  349. // 不是新增的数据 还原数据
  350. for (const i in row.oldRow) {
  351. row[i] = row.oldRow[i]
  352. }
  353. }
  354. heTypeKey.value = Math.random()
  355. }
  356. // 保存
  357. const updateHeType = (row) => {
  358. if (!row.code || !row.name) {
  359. ElMessage({
  360. type: "warning",
  361. message: "健康教育类型编码或名称不存在,请检查!",
  362. duration: 2500,
  363. showClose: true,
  364. });
  365. return
  366. }
  367. if (row.isAdd) {
  368. let fe = 0
  369. for (let num in heTypeData.value) {
  370. if (heTypeData.value[num].code === row.code) {
  371. fe++
  372. }
  373. }
  374. if (fe == 2) {
  375. ElMessage({
  376. type: "warning",
  377. message: "存在重复的健康教育类型,请核对!",
  378. duration: 2500,
  379. showClose: true,
  380. });
  381. return
  382. } else {
  383. callSaveHeType(row, null)
  384. }
  385. } else {
  386. let oldCode = row.oldRow.code
  387. if (oldCode !== row.code) {
  388. ElMessageBox.confirm(megTip, {
  389. cancelButtonText: '取消',
  390. confirmButtonText: '确定',
  391. type: 'warning',
  392. distinguishCancelAndClose: true,
  393. dangerouslyUseHTMLString: true
  394. }).then(() => {
  395. callSaveHeType(row, oldCode)
  396. }).catch((action) => {
  397. if (action === 'cancel') {
  398. queryHeType()
  399. return
  400. }
  401. })
  402. } else {
  403. callSaveHeType(row, oldCode)
  404. }
  405. }
  406. }
  407. const callSaveHeType = (row, oldCode) => {
  408. let title = '请确认是否保存<span style="color:#d12020;">' + row.name + '</span>?'
  409. ElMessageBox.confirm(title, {
  410. cancelButtonText: '取消',
  411. confirmButtonText: '确定',
  412. type: 'warning',
  413. distinguishCancelAndClose: true,
  414. dangerouslyUseHTMLString: true
  415. }).then(() => {
  416. saveHeType(row).then((res) => {
  417. ElMessage({
  418. type: "success",
  419. message: res.cg,
  420. duration: 2500,
  421. showClose: true,
  422. });
  423. if (oldCode !== null && oldCode !== row.code) {
  424. // 删除原始数据
  425. delHeTypeByCode(oldCode).then((res) => {
  426. queryHeType()
  427. })
  428. return
  429. } else {
  430. queryHeType()
  431. }
  432. })
  433. }).catch((action) => {
  434. if (action === 'cancel') {
  435. queryHeType()
  436. }
  437. })
  438. }
  439. const deleteHeType = (index, row) => {
  440. let title = '请确认是否删除<span style="color:#d12020;">' + row.name + '</span>?'
  441. ElMessageBox.confirm(title, {
  442. cancelButtonText: '取消',
  443. confirmButtonText: '确定',
  444. type: 'warning',
  445. distinguishCancelAndClose: true,
  446. dangerouslyUseHTMLString: true
  447. }).then(() => {
  448. delHeTypeByCode(row.code).then((res) => {
  449. ElMessage({
  450. type: "success",
  451. message: res.cg,
  452. duration: 2500,
  453. showClose: true,
  454. });
  455. queryHeType()
  456. return
  457. })
  458. }).catch((action) => {
  459. if (action === 'cancel') {
  460. queryHeType()
  461. }
  462. })
  463. }
  464. // 服务号字典中健康教育类型字典增删改存结束
  465. const handleClick = (tab, event) => {
  466. // 查询哪个tab页面
  467. editableTabsValue.value = tab.props.name
  468. if (editableTabsValue.value === 'healthEducation') {
  469. queryHealthEducation()
  470. } else if(editableTabsValue.value === 'heType'){
  471. queryHeType()
  472. }
  473. }
  474. </script>
  475. <style lang="scss" deep>
  476. .el-dialog__body {
  477. padding: 0 16px;
  478. height: calc(100% - 25px);
  479. }
  480. .el-tabs {
  481. height: calc(100% - 27px);
  482. .el-tabs__content {
  483. padding: 5px;
  484. height: calc(100% - 27px);
  485. }
  486. .el-tab-pane {
  487. height: calc(100% - 27px);
  488. overflow: auto;
  489. }
  490. }
  491. </style>