dept.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view class="container">
  3. <view class="safe-area-inset-bottom">
  4. <rider-curd
  5. v-model="form"
  6. :option="option"
  7. :data="list"
  8. :rules="rules"
  9. :readonly.sync="readonly"
  10. @search="onSearch"
  11. @child="onChildren"
  12. @action-click="onActionClick"
  13. @submit="onSubmit"
  14. @del="onRemove"
  15. ref="crud"
  16. >
  17. <template #form>
  18. <u-form-item label="机构名称" prop="deptName" :label-width="option.labelWidth || 160" required>
  19. <u-input v-model="form.deptName" :disabled="readonly" placeholder="机构名称" />
  20. </u-form-item>
  21. <u-form-item label="机构全称" prop="fullName" :label-width="option.labelWidth || 160" required>
  22. <u-input v-model="form.fullName" :disabled="readonly" placeholder="机构全称" />
  23. </u-form-item>
  24. <u-form-item label="上级机构" prop="parentId" :label-width="option.labelWidth || 160" required>
  25. <u-input
  26. v-if="!isAddChild"
  27. v-model="formLabel.parentName"
  28. placeholder="机构全称"
  29. type="select"
  30. @click="
  31. () => {
  32. if (!readonly) $refs.treePicker._show()
  33. }
  34. "
  35. />
  36. <u-input v-else v-model="formLabel.parentName" placeholder="机构全称" disabled />
  37. </u-form-item>
  38. <u-form-item label="机构类型" prop="deptCategory" :label-width="option.labelWidth || 160" required>
  39. <u-input
  40. v-model="formLabel.category"
  41. placeholder="机构类型"
  42. type="select"
  43. @click="
  44. () => {
  45. if (!readonly) categoryShow = true
  46. }
  47. "
  48. />
  49. </u-form-item>
  50. <u-form-item label="排序" prop="sort" :label-width="option.labelWidth || 160" required>
  51. <u-input v-model="form.sort" :disabled="readonly" type="number" placeholder="排序" />
  52. </u-form-item>
  53. <u-form-item label="描述" :label-width="option.labelWidth || 160" prop="remark">
  54. <u-input v-model="form.remark" :disabled="readonly" type="textarea" :maxlength="-1" :height="35" placeholder="描述" />
  55. </u-form-item>
  56. </template>
  57. <template #loadmore>
  58. <u-loadmore :status="loadStatus" @loadmore="getList()" />
  59. </template>
  60. </rider-curd>
  61. </view>
  62. <u-select
  63. v-model="categoryShow"
  64. :list="categoryList"
  65. value-name="dictKey"
  66. label-name="dictValue"
  67. @confirm="onConfirm"
  68. safe-area-inset-bottom
  69. ></u-select>
  70. <!-- 上级机构tree -->
  71. <rider-tree
  72. ref="treePicker"
  73. :range="deptTreeList"
  74. idKey="id"
  75. nameKey="title"
  76. :multiple="false"
  77. :cascade="false"
  78. :foldAll="false"
  79. confirmColor="#4E7FF9"
  80. cancelColor="#757575"
  81. title="上级机构"
  82. titleColor="#757575"
  83. @cancel="$refs.treePicker._hide()"
  84. @confirm="onTreeConfirm"
  85. ></rider-tree>
  86. </view>
  87. </template>
  88. <script>
  89. import riderCurd from '@/components/rider-crud/index'
  90. import riderTree from '@/components/rider-crud/components/tree-picker'
  91. import { getList, add, update, remove, deptTree } from '@/api/system/dept.js'
  92. import { tenantSelect } from '@/api/system/tenant.js'
  93. import { dictionary } from '@/api/system/dict.js'
  94. import { getDicLabel } from '@/components/rider-crud/util/tool.js'
  95. export default {
  96. components: { riderCurd, riderTree },
  97. data() {
  98. return {
  99. checkedSwitch: false,
  100. form: {},
  101. formLabel: {},
  102. list: [],
  103. params: {
  104. current: 1,
  105. size: 10,
  106. parentId: 0
  107. },
  108. loadStatus: 'loadmore', // 列表加载状态
  109. readonly: false, // 查看时控制表单只读
  110. option: {
  111. navTitle: '部门管理', //标题
  112. manageBtn: true, // 右上角管理按钮,默认不显示
  113. searchShow: true, //是否显示搜索,默认不显示
  114. labelWidth: 160, //form表单lable宽度, 默认160,单位rpx
  115. column: [
  116. {
  117. label: '机构名称',
  118. prop: 'deptName'
  119. },
  120. {
  121. label: '所属租户',
  122. prop: 'tenantName'
  123. },
  124. {
  125. label: '机构全称',
  126. prop: 'fullName'
  127. },
  128. {
  129. label: '机构类型',
  130. prop: 'deptCategoryName'
  131. },
  132. {
  133. label: '排序',
  134. prop: 'sort'
  135. },
  136. {
  137. label: '描述',
  138. prop: 'remark'
  139. }
  140. ],
  141. actions: [
  142. {
  143. name: '编辑', // 操作名称
  144. icon: 'edit-pen', //操作图标,有图标文字不显示
  145. color: '#333', // 字体颜色
  146. fontsize: 30, //字体大小,单位rpx
  147. width: 40, // 宽度,单位px
  148. background: '#fff' // 菜单按钮背景色
  149. },
  150. {
  151. name: '删除',
  152. icon: 'trash',
  153. color: '#333',
  154. fontsize: 30,
  155. width: 40,
  156. background: '#fff'
  157. },
  158. {
  159. name: '新增子项',
  160. icon: 'plus',
  161. color: '#333',
  162. fontsize: 30,
  163. width: 40,
  164. background: '#fff'
  165. }
  166. ]
  167. },
  168. rules: {
  169. deptCategory: [{ required: true, message: '请选择机构类型', trigger: 'change', type: 'number' }],
  170. deptName: [{ required: true, message: '请输入机构名称', trigger: 'blur' }],
  171. fullName: [{ required: true, message: '请输入机构全称', trigger: 'blur' }],
  172. sort: [{ required: true, message: '请输入排序', trigger: 'blur', type: 'number' }]
  173. },
  174. categoryShow: false,
  175. categoryList: [],
  176. tenantList: [],
  177. deptTreeList: [],
  178. isAddChild: false
  179. }
  180. },
  181. onReady() {
  182. this.getList(true)
  183. this.getTenant().then(() => {
  184. this.getList(true)
  185. })
  186. this.getCategoryList()
  187. },
  188. onPullDownRefresh() {
  189. this.getList(true)
  190. },
  191. onReachBottom() {
  192. if (this.loadStatus == 'nomore') return
  193. this.getList()
  194. },
  195. methods: {
  196. // 获取列表
  197. getList(override = false) {
  198. if (override) {
  199. this.params.current = 1
  200. }
  201. const { size } = this.params
  202. getList(this.params)
  203. .then(res => {
  204. const records = res.data
  205. if (records.length < size) this.loadStatus = 'nomore'
  206. else this.loadStatus = 'loadmore'
  207. if (override) this.list = records
  208. else this.list = this.list.concat(records)
  209. if (this.list && this.list.length > 0) {
  210. this.list.map(e => {
  211. e.tenantName = getDicLabel(e.tenantId, this.tenantList, { label: 'tenantName', value: 'tenantId' })
  212. e.children = []
  213. })
  214. this.$refs.crud.setLazyLoad((item, index, cb) => {
  215. getList({ parentId: item.id }).then(res => {
  216. res.data.map(e => {
  217. e.tenantName = getDicLabel(e.tenantId, this.tenantList, { label: 'tenantName', value: 'tenantId' })
  218. })
  219. cb(res.data)
  220. })
  221. })
  222. }
  223. this.params.current++
  224. uni.stopPullDownRefresh()
  225. })
  226. .catch(err => {
  227. uni.stopPullDownRefresh()
  228. })
  229. },
  230. // 获取类型
  231. getCategoryList() {
  232. dictionary({ code: 'org_category' }).then(res => {
  233. this.categoryList = res.data
  234. })
  235. },
  236. // 租户类型
  237. getTenant() {
  238. return new Promise(resolve => {
  239. deptTree().then(res => {
  240. this.deptTreeList = res.data
  241. })
  242. tenantSelect().then(res => {
  243. this.tenantList = res.data
  244. resolve()
  245. })
  246. })
  247. },
  248. // 类型回调
  249. onConfirm(e) {
  250. this.$set(this.formLabel, 'category', e[0].label)
  251. this.$set(this.form, 'deptCategory', Number(e[0].value))
  252. },
  253. //上级机构选择回调
  254. onTreeConfirm(e) {
  255. this.$set(this.form, 'parentId', e[0].id)
  256. this.$set(this.formLabel, 'parentName', e[0].name)
  257. },
  258. // 搜索 (自行配置搜索内容)
  259. onSearch(val) {
  260. this.params = {
  261. current: 1,
  262. size: 10,
  263. deptName: val
  264. }
  265. this.getList(true)
  266. },
  267. // 左滑按钮点击
  268. onActionClick({ index, data, action, done }) {
  269. const { name } = action
  270. switch (name) {
  271. case '新增':
  272. this.form = {}
  273. this.formLabel = {}
  274. this.isAddChild = false
  275. done()
  276. break
  277. case '删除':
  278. this.onRemove(data.id)
  279. break
  280. case '查看':
  281. this.readonly = true
  282. case '编辑':
  283. this.isAddChild = false
  284. this.formLabel = {
  285. category: getDicLabel(data.deptCategory, this.categoryList),
  286. parentName: getDicLabel(data.parentId, this.deptTreeList, { label: 'title', value: 'id' })
  287. }
  288. done()
  289. break
  290. case '新增子项':
  291. this.isAddChild = true
  292. this.form = {}
  293. this.formLabel = {
  294. parentName: getDicLabel(data.id, this.deptTreeList, { label: 'title', value: 'id' })
  295. }
  296. this.$set(this.form, 'parentId', data.id)
  297. done()
  298. break
  299. }
  300. if (['删除', '编辑', '新增子项'].includes(name)) this.$refs['crud'].hideChildren()
  301. },
  302. // 删除
  303. onRemove(id) {
  304. uni.showModal({
  305. title: '确定要删除吗?',
  306. success: action => {
  307. if (action.confirm) {
  308. remove(id).then(() => {
  309. uni.showToast({
  310. title: '删除成功',
  311. icon: 'none'
  312. })
  313. setTimeout(() => {
  314. this.$refs['crud'].allCheckHide(false)
  315. }, 100)
  316. // #ifdef APP
  317. this.getList(true)
  318. // #endif
  319. // #ifndef APP
  320. uni.startPullDownRefresh({})
  321. // #endif
  322. })
  323. }
  324. }
  325. })
  326. },
  327. // 表单提交
  328. onSubmit(form, action, unloading, done) {
  329. if (action == '新增' || action == '新增子项') {
  330. add(form)
  331. .then(res => {
  332. uni.showToast({
  333. title: '新增成功',
  334. icon: 'none'
  335. })
  336. done()
  337. uni.startPullDownRefresh({})
  338. })
  339. .catch(() => {
  340. unloading()
  341. })
  342. } else if (action == '编辑') {
  343. update(form)
  344. .then(res => {
  345. uni.showToast({
  346. title: '编辑成功',
  347. icon: 'none'
  348. })
  349. done()
  350. uni.startPullDownRefresh({})
  351. })
  352. .catch(() => {
  353. unloading()
  354. })
  355. }
  356. }
  357. }
  358. }
  359. </script>
  360. <style>
  361. page {
  362. background: #f6f6f6;
  363. }
  364. </style>
  365. <style lang="scss" scoped>
  366. .nav-right {
  367. color: #fff;
  368. font-size: 28rpx;
  369. font-weight: normal;
  370. padding-right: 24rpx;
  371. }
  372. </style>