addressBook.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <!-- 地址簿管理 -->
  3. <div class="home" v-loading="pageLoading">
  4. <actionBar :operateList="operateList" :formList="formList" :ruleForm="searchRuleForm" @openModel="openModel"
  5. @searchProtocol="searchProtocol"></actionBar>
  6. <div class="card_content">
  7. <!-- 表单 -->
  8. <tables :suspension="true" :tableList="tableList" :tableData="tableData" @buttonData="buttonData"></tables>
  9. <!-- 分页 -->
  10. <div v-if="Total">
  11. <pagination :total="Total" :currentPage="Pagination.PageIndex" @changeSize="changeSize"
  12. @changeCurrent="changeCurrent">
  13. </pagination>
  14. </div>
  15. </div>
  16. <el-dialog :title="staffTitle" :visible.sync="staffDialogVisible" width="600px" :close-on-click-modal="false"
  17. @close="closeDialog">
  18. <forms ref="childRules" :formNewList="formRuleList" :ruleForm="ruleForm" labelWidth="100px">
  19. </forms>
  20. <span slot="footer" class="dialog-footer" v-if="operationType != 'logs'">
  21. <el-button plain @click="staffDialogVisible = false">取 消</el-button>
  22. <el-button type="primary" :loading="confirmLoading" @click="handleAdd">确 定</el-button>
  23. </span>
  24. </el-dialog>
  25. </div>
  26. </template>
  27. <script>
  28. import {
  29. getAddress,
  30. addAddress,
  31. putAddress,
  32. delAddress
  33. } from '@/api/address'
  34. import { getPostMenuIds, getMenuTree } from '@/api/post'
  35. import actionBar from '@/components/actionBar'
  36. import tables from '@/components/tables'
  37. import pagination from '@/components/pagination'
  38. import forms from '@/components/forms'
  39. import {
  40. formRules,
  41. employee,
  42. } from "./address.js";
  43. export default {
  44. name: 'addressBook',
  45. components: {
  46. actionBar,
  47. tables,
  48. pagination,
  49. forms
  50. },
  51. data() {
  52. return {
  53. operateList: [{
  54. type: 'add',
  55. title: '添加',
  56. icon: 'el-icon-plus',
  57. }],
  58. formList: [{
  59. type: 'input',
  60. label: '关键字',
  61. field: 'name',
  62. placeholder: '请输入关键字快速查找',
  63. }],
  64. searchRuleForm: {
  65. name: '',
  66. },
  67. searchValue: {},
  68. Pagination: {
  69. PageIndex: 1,
  70. PageSize: 10,
  71. },
  72. Total: 0,
  73. tableData: [],
  74. operationType: '',
  75. tableList: employee(),
  76. staffTitle: '添加',
  77. staffDialogVisible: false,
  78. formRuleList: [],
  79. ruleForm: {
  80. name: '',
  81. phone: '',
  82. address: '',
  83. addressType: '',
  84. },
  85. confirmLoading: false,
  86. selectingData: {},
  87. pageLoading: true,
  88. }
  89. },
  90. mounted() {
  91. this.hideButtonsByPerm()
  92. this.getList()
  93. },
  94. methods: {
  95. hideButtonsByPerm() {
  96. try {
  97. const user = JSON.parse(localStorage.getItem('userList') || '{}')
  98. if (!user.postId) { this.pageLoading = false; return }
  99. getPostMenuIds(user.postId).then(res => {
  100. if (res.code !== 200) return
  101. const ids = res.data.menuIds || []
  102. getMenuTree().then(treeRes => {
  103. if (treeRes.code !== 200) return
  104. const map = {}
  105. function walk(n) { (n || []).forEach(x => { map[x.id] = x.label; walk(x.children) }) }
  106. walk(treeRes.data)
  107. const labels = ids.map(id => map[id]).filter(Boolean)
  108. const has = label => labels.includes(label)
  109. // 精确匹配页面专属菜单标签
  110. const pageLabels = ['查询患者','新增患者','编辑患者','删除患者','患者详情']
  111. const anyMatch = pageLabels.some(l => labels.includes(l))
  112. if (!anyMatch) return
  113. // 表格按钮
  114. const btnMap = { '详情': '患者详情', '编辑': '编辑患者', '删除': '删除患者' }
  115. const col = this.tableList.find(c => c.field === 'action')
  116. if (col && col.labelButton) {
  117. const keep = col.labelButton.filter(b => has(btnMap[b.label] || b.label))
  118. col.labelButton.splice(0, col.labelButton.length, ...keep)
  119. }
  120. // 顶部新增按钮
  121. if (!has('新增患者')) {
  122. const top = this.operateList.filter(b => b.type !== 'add')
  123. this.operateList.splice(0, this.operateList.length, ...top)
  124. }
  125. this.pageLoading = false
  126. })
  127. })
  128. } catch(e) { this.pageLoading = false }
  129. },
  130. // 搜索
  131. searchProtocol(value) {
  132. this.Pagination.PageIndex = 1
  133. this.searchValue = value
  134. this.getList()
  135. },
  136. // 获取列表
  137. getList() {
  138. var params = {
  139. page: this.Pagination.PageIndex,
  140. pageSize: this.Pagination.PageSize,
  141. ...this.searchValue
  142. }
  143. getAddress(params).then(res => {
  144. if (res.code == 200) {
  145. this.tableData = res.data.list
  146. this.Total = res.data.count
  147. }
  148. })
  149. },
  150. // 弹窗表单添加
  151. handleAdd() {
  152. let flag = this.$refs['childRules'].validateForm();
  153. if (flag) {
  154. if (this.operationType == 'add') {
  155. this.confirmLoading = true
  156. var params = {
  157. ...this.ruleForm
  158. }
  159. params.addressType = 'consignee'
  160. addAddress(params).then(res => {
  161. if (res.code == 200) {
  162. this.$message({
  163. message: '操作成功',
  164. type: 'success'
  165. });
  166. this.getList()
  167. }
  168. this.staffDialogVisible = false
  169. this.confirmLoading = false
  170. }).catch(() => {
  171. this.confirmLoading = false
  172. })
  173. } else if (this.operationType == 'edit') {
  174. this.confirmLoading = true
  175. var params = {
  176. id: this.selectingData.id,
  177. name: this.ruleForm.name,
  178. phone: this.ruleForm.phone,
  179. address: this.ruleForm.address,
  180. addressType: this.ruleForm.addressType,
  181. }
  182. putAddress(params).then(res => {
  183. if (res.code == 200) {
  184. this.$message({
  185. message: '操作成功',
  186. type: 'success'
  187. });
  188. this.getList()
  189. }
  190. this.staffDialogVisible = false
  191. this.confirmLoading = false
  192. }).catch(() => {
  193. this.confirmLoading = false
  194. })
  195. }
  196. } else {
  197. this.$message.error('表单信息不完整,请继续填写完整');
  198. }
  199. },
  200. buttonData(row, type) {
  201. const dataList = formRules();
  202. this.formRuleList = dataList;
  203. this.selectingData = row
  204. this.operationType = type
  205. if (type == 'edit') {
  206. this.staffTitle = '编辑'
  207. this.staffDialogVisible = true
  208. setTimeout(() => {
  209. this.$nextTick(() => {
  210. this.ruleForm.name = row.name
  211. this.ruleForm.phone = row.phone
  212. this.ruleForm.address = row.address
  213. this.ruleForm.addressType = row.addressType
  214. })
  215. })
  216. } else if (type == 'logs') {
  217. this.staffTitle = '详情'
  218. this.staffDialogVisible = true
  219. this.formRuleList.forEach((item, index) => {
  220. item.disabled = true
  221. })
  222. this.ruleForm = JSON.parse(JSON.stringify(row))
  223. } else if (type == 'del') {
  224. this.deleteUser(row.id)
  225. }
  226. },
  227. openModel(type) {
  228. const dataList = formRules();
  229. this.formRuleList = dataList;
  230. this.staffTitle = '添加'
  231. this.staffDialogVisible = true
  232. this.operationType = type
  233. },
  234. // 删除该地址
  235. deleteUser(id) {
  236. this.$confirm('此操作将永久删除该地址, 是否继续?', '提示', {
  237. confirmButtonText: '确定',
  238. cancelButtonText: '取消',
  239. type: 'warning'
  240. }).then(() => {
  241. delAddress({
  242. id: id,
  243. }).then(res => {
  244. if (res.code == 200) {
  245. this.$message({
  246. message: '操作成功',
  247. type: 'success'
  248. });
  249. const precisePage = Math.ceil((this.Total - 1) / this.Pagination.PageSize)
  250. this.Pagination.PageIndex = this.Pagination.PageIndex > precisePage ? precisePage : this
  251. .Pagination.PageIndex
  252. this.Pagination.PageIndex = this.Pagination.PageIndex < 1 ? 1 : this.Pagination.PageIndex
  253. this.getList()
  254. }
  255. })
  256. }).catch(() => {});
  257. },
  258. changeSize(val) {
  259. this.Pagination.PageSize = val
  260. this.getList()
  261. },
  262. changeCurrent(val) {
  263. this.Pagination.PageIndex = val
  264. this.getList()
  265. },
  266. // 清空表单
  267. closeDialog() {
  268. this.$refs.childRules.resetCheck();
  269. }
  270. }
  271. }
  272. </script>
  273. <style lang="scss">
  274. </style>