2024-11-15 10:45:37 +08:00
|
|
|
|
<template>
|
2024-11-23 15:16:52 +08:00
|
|
|
|
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body @open="onOpen">
|
|
|
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px" v-loading="loading">
|
2024-11-15 10:45:37 +08:00
|
|
|
|
<el-form-item label="店铺" prop="storeId">
|
2024-11-23 15:16:52 +08:00
|
|
|
|
<store-input v-model="form.storeId" :disabled="hasView([views.store, views.mchStore])"/>
|
2024-11-15 10:45:37 +08:00
|
|
|
|
</el-form-item>
|
2024-11-23 15:16:52 +08:00
|
|
|
|
<el-form-item label="用户" prop="userId" v-if="userInputType === 'dialog'">
|
2024-11-15 10:45:37 +08:00
|
|
|
|
<user-input v-model="form.userId"/>
|
|
|
|
|
</el-form-item>
|
2024-11-23 15:16:52 +08:00
|
|
|
|
<el-form-item label="用户" prop="userId" v-else-if="userInputType === 'search'">
|
|
|
|
|
<user-search-input v-if="open && !loading" v-model="form.userId" :init-options="initUserSearchOptions"/>
|
|
|
|
|
</el-form-item>
|
2024-11-15 10:45:37 +08:00
|
|
|
|
<el-form-item label="备注名" prop="remark">
|
|
|
|
|
<el-input v-model="form.remark" placeholder="请输入备注名" maxlength="200" show-word-limit/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="角色" prop="role">
|
|
|
|
|
<el-select v-model="form.role" placeholder="请选择角色" style="width: 100%">
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="dict in dict.type.store_staff_role"
|
|
|
|
|
:key="dict.value"
|
|
|
|
|
:label="dict.label"
|
|
|
|
|
:value="dict.value"
|
|
|
|
|
></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="分成比例" prop="point">
|
|
|
|
|
<el-input-number
|
|
|
|
|
v-model="form.point"
|
|
|
|
|
placeholder="请输入分成比例"
|
|
|
|
|
:min="0"
|
|
|
|
|
:max="100"
|
|
|
|
|
style="width: calc(100% - 2em)"
|
|
|
|
|
controls-position="right"
|
|
|
|
|
/> %
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="是否启用" prop="enabled">
|
|
|
|
|
<el-switch v-model="form.enabled" active-text="启用" inactive-text="禁用"/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="权限列表" prop="permissions">
|
|
|
|
|
<el-checkbox-group v-model="form.permissions">
|
|
|
|
|
<el-checkbox
|
|
|
|
|
v-for="dict in dict.type.store_staff_permissions"
|
|
|
|
|
:key="dict.value"
|
|
|
|
|
:label="dict.value">
|
|
|
|
|
{{dict.label}}
|
|
|
|
|
</el-checkbox>
|
|
|
|
|
</el-checkbox-group>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
|
|
|
<el-button @click="cancel">取 消</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
2024-11-23 15:16:52 +08:00
|
|
|
|
import { StoreStaffRole, UserType } from '@/utils/constants'
|
|
|
|
|
import { addStoreStaff, getStoreStaff, updateStoreStaff } from '@/api/ss/storeStaff'
|
2024-11-15 10:45:37 +08:00
|
|
|
|
import StoreInput from '@/components/Business/Store/StoreInput.vue'
|
|
|
|
|
import UserInput from '@/components/Business/SmUser/UserInput.vue'
|
|
|
|
|
import { $view } from '@/utils/mixins'
|
2024-11-23 15:16:52 +08:00
|
|
|
|
import { mapGetters } from 'vuex'
|
|
|
|
|
import UserSearchInput from '@/components/Business/SmUser/UserSearchInput.vue'
|
2024-11-15 10:45:37 +08:00
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "StoreStaffEditDialog",
|
|
|
|
|
mixins: [$view],
|
|
|
|
|
dicts: ['store_staff_permissions', 'store_staff_role'],
|
2024-11-23 15:16:52 +08:00
|
|
|
|
components: { UserSearchInput, UserInput, StoreInput },
|
|
|
|
|
props: {
|
|
|
|
|
// ID
|
|
|
|
|
employId: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null,
|
|
|
|
|
},
|
|
|
|
|
show: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
initForm: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => ({})
|
|
|
|
|
},
|
|
|
|
|
// 用户的输入方式:dialog 弹窗选择,search 搜索选择
|
|
|
|
|
userInputType: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: "dialog"
|
|
|
|
|
},
|
|
|
|
|
// 更新API
|
|
|
|
|
updateApi: {
|
|
|
|
|
type: Function,
|
|
|
|
|
default: updateStoreStaff
|
|
|
|
|
},
|
|
|
|
|
// 新增API
|
|
|
|
|
addApi: {
|
|
|
|
|
type: Function,
|
|
|
|
|
default: addStoreStaff
|
|
|
|
|
},
|
|
|
|
|
// 加载API
|
|
|
|
|
loadApi: {
|
|
|
|
|
type: Function,
|
|
|
|
|
default: getStoreStaff
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-11-15 10:45:37 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
// 表单参数
|
|
|
|
|
form: {},
|
2024-11-23 15:16:52 +08:00
|
|
|
|
title: null,
|
|
|
|
|
loading: false,
|
2024-11-15 10:45:37 +08:00
|
|
|
|
// 表单校验
|
|
|
|
|
rules: {
|
|
|
|
|
storeId: [
|
|
|
|
|
{ required: true, message: "店铺不能为空", trigger: "change" }
|
|
|
|
|
],
|
|
|
|
|
userId: [
|
|
|
|
|
{ required: true, message: "用户不能为空", trigger: "change" }
|
|
|
|
|
],
|
|
|
|
|
point: [
|
|
|
|
|
{ required: true, message: "分成比例不能为空", trigger: "change" }
|
|
|
|
|
],
|
|
|
|
|
enabled: [
|
|
|
|
|
{ required: true, message: "是否启用不能为空", trigger: "change" }
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-11-23 15:16:52 +08:00
|
|
|
|
computed: {
|
|
|
|
|
initUserSearchOptions() {
|
|
|
|
|
return [{value: this.form.userId, label: this.form.userName}]
|
|
|
|
|
},
|
|
|
|
|
UserType() {
|
|
|
|
|
return UserType
|
|
|
|
|
},
|
|
|
|
|
...mapGetters(['userType']),
|
|
|
|
|
open: {
|
|
|
|
|
get() {
|
|
|
|
|
return this.show;
|
|
|
|
|
},
|
|
|
|
|
set(val) {
|
|
|
|
|
this.$emit('update:show', val)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.reset();
|
|
|
|
|
},
|
2024-11-15 10:45:37 +08:00
|
|
|
|
methods: {
|
2024-11-23 15:16:52 +08:00
|
|
|
|
onOpen() {
|
|
|
|
|
if (this.employId != null) {
|
|
|
|
|
this.loading = true;
|
|
|
|
|
this.loadApi(this.employId).then(res => {
|
|
|
|
|
this.form = res.data;
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.reset();
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-11-15 10:45:37 +08:00
|
|
|
|
// 取消按钮
|
|
|
|
|
cancel() {
|
|
|
|
|
this.open = false;
|
|
|
|
|
this.reset();
|
|
|
|
|
},
|
|
|
|
|
// 表单重置
|
|
|
|
|
reset() {
|
|
|
|
|
this.form = {
|
|
|
|
|
employId: null,
|
2024-11-23 15:16:52 +08:00
|
|
|
|
storeId: null,
|
2024-11-15 10:45:37 +08:00
|
|
|
|
userId: null,
|
|
|
|
|
remark: null,
|
|
|
|
|
role: StoreStaffRole.STAFF,
|
|
|
|
|
point: 0,
|
|
|
|
|
enabled: true,
|
|
|
|
|
permissions: [],
|
2024-11-23 15:16:52 +08:00
|
|
|
|
...this.initForm
|
2024-11-15 10:45:37 +08:00
|
|
|
|
};
|
|
|
|
|
this.resetForm("form");
|
|
|
|
|
},
|
|
|
|
|
/** 提交按钮 */
|
|
|
|
|
submitForm() {
|
|
|
|
|
this.$refs["form"].validate(valid => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
if (this.form.employId != null) {
|
2024-11-23 15:16:52 +08:00
|
|
|
|
this.updateApi(this.form).then(response => {
|
2024-11-15 10:45:37 +08:00
|
|
|
|
this.$modal.msgSuccess("修改成功");
|
|
|
|
|
this.open = false;
|
2024-11-23 15:16:52 +08:00
|
|
|
|
this.$emit('success')
|
2024-11-15 10:45:37 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
2024-11-23 15:16:52 +08:00
|
|
|
|
this.addApi(this.form).then(response => {
|
2024-11-15 10:45:37 +08:00
|
|
|
|
this.$modal.msgSuccess("新增成功");
|
|
|
|
|
this.open = false;
|
2024-11-23 15:16:52 +08:00
|
|
|
|
this.$emit('success')
|
2024-11-15 10:45:37 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|