123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- <template>
- <view class="container">
- <view class="safe-area-inset-bottom">
- <rider-curd
- v-model="form"
- :option="option"
- :data="list"
- :rules="rules"
- :readonly.sync="readonly"
- @search="onSearch"
- @action-click="onActionClick"
- @submit="onSubmit"
- @del="onRemove"
- ref="crud"
- >
- <template #form>
- <u-form-item label="字典编号" prop="code" :label-width="option.labelWidth || 160" required>
- <u-input v-model="form.code" :disabled="readonly" placeholder="字典编号" />
- </u-form-item>
- <u-form-item label="字典名称" prop="dictValue" :label-width="option.labelWidth || 160" required>
- <u-input v-model="form.dictValue" :disabled="readonly" placeholder="字典名称" />
- </u-form-item>
- <u-form-item label="字典排序" prop="sort" :label-width="option.labelWidth || 160" required>
- <u-input v-model="form.sort" :disabled="readonly" type="number" placeholder="字典排序" />
- </u-form-item>
- <u-form-item label="封存" prop="isSealed" :label-width="option.labelWidth || 160" required>
- <u-radio-group v-model="form.isSealed" :disabled="readonly">
- <u-radio shape="circle" :name="1" active-color="#4E7FF9">是</u-radio>
- <u-radio shape="circle" :name="0" active-color="#4E7FF9">否</u-radio>
- </u-radio-group>
- </u-form-item>
- <u-form-item label="字典备注" :label-width="option.labelWidth || 160" prop="remark">
- <u-input
- v-model="form.remark"
- :disabled="readonly"
- type="textarea"
- :maxlength="-1"
- :height="35"
- placeholder="字典备注"
- />
- </u-form-item>
- </template>
- <template #loadmore>
- <u-loadmore :status="loadStatus" @loadmore="getList()" />
- </template>
- </rider-curd>
- </view>
- <!-- 字典配置 -->
- <u-popup v-model="configShow" mode="bottom" height="100vh" @close="onConfigClose" :mask-close-able="false">
- <scroll-view scroll-y="true" style="height: 100vh; background: #f5f5f5">
- <rider-curd
- ref="childCrud"
- v-model="childForm"
- :navBack="onConfigClose"
- @search="onChildSearch"
- :option="{ ...configOption, navTitle: `${configName} - 字典配置` }"
- :data="childList"
- :rules="rules"
- :readonly.sync="readonly"
- @action-click="onActionClick"
- @submit="onSubmit"
- @del="onRemove"
- >
- <template #form>
- <u-form-item label="字典编号" prop="code" :label-width="configOption.labelWidth || 160" required>
- <u-input v-model="childForm.code" disabled placeholder="字典编号" />
- </u-form-item>
- <u-form-item label="字典名称" prop="dictValue" :label-width="configOption.labelWidth || 160" required>
- <u-input v-model="childForm.dictValue" :disabled="readonly" placeholder="字典名称" />
- </u-form-item>
- <u-form-item label="上级字典" :label-width="configOption.labelWidth || 160">
- <u-input v-model="parentData.dictValue" disabled placeholder="上级字典" />
- </u-form-item>
- <u-form-item label="字典键值" prop="dictKey" :label-width="configOption.labelWidth || 160" required>
- <u-input v-model="childForm.dictKey" :disabled="readonly" placeholder="字典键值" />
- </u-form-item>
- <u-form-item label="字典排序" prop="sort" :label-width="configOption.labelWidth || 160" required>
- <u-input v-model="childForm.sort" :disabled="readonly" type="number" placeholder="字典排序" />
- </u-form-item>
- <u-form-item label="封存" prop="isSealed" :label-width="configOption.labelWidth || 160" required>
- <u-radio-group v-model="childForm.isSealed" :disabled="readonly">
- <u-radio shape="circle" :name="1" active-color="#4E7FF9">是</u-radio>
- <u-radio shape="circle" :name="0" active-color="#4E7FF9">否</u-radio>
- </u-radio-group>
- </u-form-item>
- <u-form-item label="字典备注" prop="remark" :label-width="configOption.labelWidth || 160">
- <u-input
- v-model="childForm.remark"
- :disabled="readonly"
- type="textarea"
- :maxlength="-1"
- :height="35"
- placeholder="字典备注"
- />
- </u-form-item>
- </template>
- <template #loadmore>
- <u-loadmore :status="childLoadStatus" @loadmore="getChild()" />
- </template>
- </rider-curd>
- </scroll-view>
- </u-popup>
- </view>
- </template>
- <script>
- import riderCurd from '@/components/rider-crud/index'
- import { parentList, add, update, remove, dictionary, child, dictTree } from '@/api/system/dict.js'
- import { getDicLabel } from '@/components/rider-crud/util/tool.js'
- export default {
- components: { riderCurd },
- data() {
- return {
- configShow: false, //字典管理弹窗
- form: {
- isSealed: 0
- },
- list: [],
- params: {
- current: 1,
- size: 10
- },
- readonly: false, // 查看时控制表单只读
- parentData: {}, // 上级数据信息
- childList: [],
- childForm: {
- isSealed: 0
- },
- childParams: {
- current: 1,
- size: 10,
- parentId: null
- },
- loadStatus: 'loadmore', // 列表加载状态
- childLoadStatus: 'loadmore', // 列表加载状态
- option: {
- navTitle: '字典管理', //标题
- manageBtn: true, // 右上角管理按钮,默认不显示
- searchShow: true, //是否显示搜索,默认不显示
- labelWidth: 160, //form表单lable宽度, 默认160,单位rpx
- column: [
- {
- label: '字典编号',
- prop: 'code'
- },
- {
- label: '字典名称',
- prop: 'dictValue'
- },
- {
- label: '字典排序',
- prop: 'sort'
- },
- {
- label: '封存',
- prop: 'sealedName'
- },
- {
- label: '字典备注',
- prop: 'remark'
- }
- ],
- actions: [
- {
- name: '编辑', // 操作名称
- icon: 'edit-pen', //操作图标,有图标文字不显示
- color: '#333', // 字体颜色
- fontsize: 30, //字体大小,单位rpx
- width: 40, // 宽度,单位px
- background: '#fff' // 菜单按钮背景色
- },
- {
- name: '删除',
- icon: 'trash',
- color: '#333',
- fontsize: 30,
- width: 40,
- background: '#fff'
- },
- {
- name: '设置',
- icon: 'setting',
- color: '#333',
- fontsize: 30,
- width: 40,
- background: '#fff'
- }
- ]
- },
- configName: '',
- configOption: {
- navBackIcon: 'close', //导航栏左上角icon
- manageBtn: true, // 右上角管理按钮,默认不显示
- searchShow: true, //是否显示搜索,默认不显示
- labelWidth: 160, //form表单lable宽度, 默认160,单位rpx
- column: [
- {
- label: '字典编号',
- prop: 'code'
- },
- {
- label: '字典名称',
- prop: 'dictValue'
- },
- {
- label: '字典键值',
- prop: 'dictKey'
- },
- {
- label: '字典排序',
- prop: 'sort'
- },
- {
- label: '封存',
- prop: 'sealedName'
- },
- {
- label: '字典备注',
- prop: 'remark'
- }
- ],
- actions: [
- {
- name: '编辑', // 操作名称
- icon: 'edit-pen', //操作图标,有图标文字不显示
- color: '#333', // 字体颜色
- fontsize: 30, //字体大小,单位rpx
- width: 40, // 宽度,单位px
- background: '#fff' // 菜单按钮背景色
- },
- {
- name: '删除',
- icon: 'trash',
- color: '#333',
- fontsize: 30,
- width: 40,
- background: '#fff'
- },
- {
- name: '新增子项',
- icon: 'plus',
- color: '#333',
- fontsize: 30,
- width: 40,
- background: '#fff'
- }
- ]
- },
- rules: {
- code: [{ required: true, message: '请输入字典编号', trigger: 'blur' }],
- dictValue: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
- sort: [{ required: true, message: '请输入字典排序', trigger: 'blur', type: 'number' }],
- isSealed: [{ required: true, message: '请选择是否封存', trigger: 'blur', type: 'number' }],
- dictKey: [{ required: true, message: '请输入字典键值', trigger: 'blur' }]
- }
- }
- },
- onReady() {
- this.getList(true)
- },
- onPullDownRefresh() {
- this.getList(true)
- this.getChild(true)
- },
- onReachBottom() {
- if (this.loadStatus == 'nomore') return
- this.getList()
- if (this.childLoadStatus == 'nomore') return
- this.getChild()
- },
- methods: {
- // 获取列表
- getList(override = false) {
- if (override) {
- this.params.current = 1
- }
- const { size } = this.params
- parentList(this.params)
- .then(res => {
- const { records } = res.data
- if (records.length < size) this.loadStatus = 'nomore'
- else this.loadStatus = 'loadmore'
- if (override) {
- this.list = records
- } else {
- this.list = this.list.concat(records)
- }
- if (this.list && this.list.length > 0) {
- this.list.map(e => {
- e.sealedName = e.isSealed ? '是' : '否'
- })
- }
- this.params.current++
- uni.stopPullDownRefresh()
- })
- .catch(err => {
- uni.stopPullDownRefresh()
- })
- },
- // 获取子类列表
- getChild(override = false) {
- if (override) {
- this.childParams.current = 1
- }
- const { size } = this.childParams
- child(this.childParams)
- .then(res => {
- const records = res.data
- if (records.length < size) this.childLoadStatus = 'nomore'
- else this.childLoadStatus = 'loadmore'
- if (override) {
- this.childList = records
- } else {
- this.childList = this.childList.concat(records)
- }
- if (this.childList && this.childList.length > 0) {
- this.childList.map(e => {
- e.sealedName = e.isSealed ? '是' : '否'
- })
- }
- this.childParams.current++
- uni.stopPullDownRefresh()
- })
- .catch(err => {
- uni.stopPullDownRefresh()
- })
- },
- // 左滑按钮点击
- onActionClick({ index, data, action, done }) {
- const { name } = action
- switch (name) {
- case '新增':
- if (this.parentData.code) {
- this.$set(this.childForm, 'code', this.parentData.code)
- this.$set(this.childForm, 'parentId', this.parentData.id)
- this.$set(this.childParams, 'parentId', this.parentData.id)
- }
- done()
- break
- case '删除':
- this.onRemove(data.id)
- break
- case '查看':
- this.readonly = true
- case '编辑':
- if (data.id) done()
- break
- case '设置':
- this.childForm = {}
- this.parentData = data
- this.configName = data.dictValue
- this.$set(this.childParams, 'parentId', data.id)
- this.getChild(true)
- setTimeout(() => {
- this.configShow = true
- }, 100)
- break
- case '新增子项':
- this.childForm = {}
- this.parentData = data
- this.$set(this.childForm, 'code', data.code)
- this.$set(this.childForm, 'parentId', data.id)
- this.$set(this.childParams, 'parentId', data.id)
- done()
- break
- }
- if (['删除', '编辑', '新增子项'].includes(name)) {
- this.$refs['crud'].hideChildren()
- this.$refs['childCrud'].hideChildren()
- }
- },
- // 删除
- onRemove(id) {
- uni.showModal({
- title: '确定要删除吗?',
- success: action => {
- if (action.confirm) {
- remove(id).then(() => {
- uni.showToast({
- title: '删除成功',
- icon: 'none'
- })
- setTimeout(() => {
- this.$refs['crud'].allCheckHide(false)
- }, 100)
- // #ifdef APP
- this.getList(true)
- // #endif
- // #ifndef APP
- uni.startPullDownRefresh({})
- // #endif
- })
- }
- }
- })
- },
- // 表单提交
- onSubmit(form, action, unloading, done) {
- if (action == '新增' || action == '新增子项') {
- add(form)
- .then(res => {
- uni.showToast({
- title: '新增成功',
- icon: 'none'
- })
- done()
- uni.startPullDownRefresh({})
- })
- .catch(() => {
- unloading()
- })
- } else if (action == '编辑') {
- update(form)
- .then(res => {
- uni.showToast({
- title: '编辑成功',
- icon: 'none'
- })
- done()
- uni.startPullDownRefresh({})
- })
- .catch(() => {
- unloading()
- })
- }
- },
- //字典配置关闭
- onConfigClose() {
- this.configShow = false
- this.childParams = {
- current: 1,
- size: 10,
- parentId: null
- }
- this.parentData = {}
- this.form = { isSealed: 0 }
- this.childForm = { isSealed: 0 }
- setTimeout(() => {
- this.getChild(true)
- })
- },
- // 搜索 (自行配置搜索内容)
- onSearch(val) {
- this.params = {
- current: 1,
- size: 10,
- dictValue: val
- }
- this.getList(true)
- },
- // 子级搜索
- onChildSearch(val) {
- this.childForm = {
- current: 1,
- size: 10,
- dictValue: val
- }
- this.getChild(true)
- }
- }
- }
- </script>
- <style>
- page {
- background: #f6f6f6;
- }
- </style>
- <style lang="scss" scoped>
- .nav-right {
- color: #fff;
- font-size: 28rpx;
- font-weight: normal;
- padding-right: 24rpx;
- }
- .config-title {
- padding: 30rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- border-bottom: 20rpx solid #f5f5f5;
- color: #fff;
- background: linear-gradient(45deg, #4e7ff9 0%, #59a5fb 100%);
- }
- </style>
|