Commit a33563e7 by cwq0219

员工-新增/编辑

1 parent 9e08eb6c
...@@ -71,4 +71,27 @@ const getDetailLogApi = params => { ...@@ -71,4 +71,27 @@ const getDetailLogApi = params => {
}) })
} }
export default { getListApi, getAllMerchantListApi, getRoleListApi, getAllDictApi, getMerchantTreeApi, getDetailInfoApi, getDetailLogApi } const addEmployeeApi = params => {
params.method = `${defaultPath}staff.saveStaff`
return http({
url: 'rop-merchants/router',
method: 'POST',
data: params,
sign: true,
returnAll: true
})
}
const updateEmployeeApi = params => {
params.method = `${defaultPath}staff.updateStaff`
return http({
url: 'rop-merchants/router',
method: 'POST',
data: params,
sign: true,
returnAll: true
})
}
export default { getListApi, getAllMerchantListApi, getRoleListApi, getAllDictApi, getMerchantTreeApi, getDetailInfoApi, getDetailLogApi, addEmployeeApi, updateEmployeeApi }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
</div> </div>
<div class="container"> <div class="container">
<p class="edit-sub-title p-rl-20">员工基本信息</p> <p class="edit-sub-title p-rl-20">员工基本信息</p>
<glsx-combi-form class="p-rl-20" ref="editFormRef" labelWidth="160px" :isBlock="isBlock" :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule"> <glsx-combi-form class="p-rl-20" ref="editFormRef" labelWidth="160px" @handleImgDelete="handleImgDelete" :isBlock="isBlock" :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule">
<template slot="merchantId" slot-scope="item"> <template slot="merchantId" slot-scope="item">
<select-page :form="editForm" width="300px" :targetItem="item.scope" @handleChange="handleChangeMerchant"></select-page> <select-page :form="editForm" width="300px" :targetItem="item.scope" @handleChange="handleChangeMerchant"></select-page>
</template> </template>
...@@ -59,18 +59,27 @@ export default { ...@@ -59,18 +59,27 @@ export default {
staffPhone: '', staffPhone: '',
password: '', password: '',
visibleInferiorMer: '', visibleInferiorMer: '',
roleId: '', roleIds: '',
merhcnatImg: '', merchantImg: '',
fileName: '' fileName: ''
}, },
editRule: { editRule: {
merchantId: [{ required: true, message: '请选择所属商户', trigger: 'change' }], merchantId: [{ required: true, message: '请选择所属商户', trigger: 'change' }],
staffName: [{ required: true, message: '请输入员工姓名', trigger: 'change' }], staffName: [{ required: true, message: '请输入员工姓名', trigger: 'change' }],
staffPhone: [{ required: true, message: '请输入登录手机号', trigger: 'change' }], staffPhone: [{ required: true, message: '请输入登录手机号' },
{ required: true, validator: (rule, value, callback) => {
(/^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/).test(value) ? callback() : callback(new Error('请输入正确的手机号')
)}, trigger: 'change'
}],
// 6-15位 // 6-15位
password: [{ required: true, message: '请输入登录密码', trigger: 'change' }], password: [{ required: true, message: '请输入登录密码', trigger: 'change' },
{ required: true, validator: (rule, value, callback) => {
(/^[\S]{6,15}$/).test(value) ? callback() : callback(new Error('密码必须6-15位'))
}, trigger: 'change'
}],
visibleInferiorMer: [{ required: true, message: '请选择可见商户', trigger: 'change' }], visibleInferiorMer: [{ required: true, message: '请选择可见商户', trigger: 'change' }],
roleId: [{ required: true, message: '请选择角色权限', trigger: 'change' }] roleIds: [{ required: true, message: '请选择角色权限', trigger: 'change' }]
// staffEmail: [{ required: false, validator: (rule, value, callback) => {}, trigger: 'change' }]
}, },
isBlock: true, isBlock: true,
editFormData: [ editFormData: [
...@@ -103,6 +112,7 @@ export default { ...@@ -103,6 +112,7 @@ export default {
{ {
label: '登录密码', label: '登录密码',
name: 'password', name: 'password',
showPass: true,
width: '360px', width: '360px',
type: 'input', type: 'input',
maxlength: 15 maxlength: 15
...@@ -114,7 +124,7 @@ export default { ...@@ -114,7 +124,7 @@ export default {
}, },
{ {
label: '角色权限', label: '角色权限',
name: 'roleId', name: 'roleIds',
type: 'select', type: 'select',
width: '360px', width: '360px',
optionList: [], optionList: [],
...@@ -124,7 +134,7 @@ export default { ...@@ -124,7 +134,7 @@ export default {
}, },
{ {
label: '头像', label: '头像',
name: 'merhcnatImg', name: 'merchantImg',
type: 'upload', type: 'upload',
maxPhotoNum: 1, maxPhotoNum: 1,
// wdithLt: 800, // wdithLt: 800,
...@@ -133,16 +143,15 @@ export default { ...@@ -133,16 +143,15 @@ export default {
handleUpload: (e, file, targetItem) => { handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1] const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
this.$apis.common.pictureUpload({ file: base64}).then((res) => { this.$apis.common.pictureUpload({ file: base64 }).then(res => {
if (res) { if (res) {
console.log(res) console.log(res)
// fileName this.editForm[targetItem.name] = res
this.editForm.fileName = file.name
console.log(this.editForm)
this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
} }
}) })
// uploadImg({ file: base64, fileType: 'image' }).then(res => {
// this.editForm[targetItem.name] = res
// this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
// })
} }
}, },
{ {
...@@ -188,6 +197,10 @@ export default { ...@@ -188,6 +197,10 @@ export default {
}, },
methods: { methods: {
handleImgDelete(targetItem) {
this.$set(this.editForm, 'merchantImg', '')
this.editForm.fileName = ''
},
getAllMerchantList() { getAllMerchantList() {
this.$apis.employee.getAllMerchantListApi({}).then(res => { this.$apis.employee.getAllMerchantListApi({}).then(res => {
this.baseData.allMerchantList = res this.baseData.allMerchantList = res
...@@ -195,38 +208,45 @@ export default { ...@@ -195,38 +208,45 @@ export default {
}, },
getInfo() { getInfo() {
this.$apis.employee.getDetailInfoApi({ id: this.routeInfo.id }).then(res => { this.$apis.employee.getDetailInfoApi({ id: this.routeInfo.id }).then(res => {
this.editForm = res this.editForm = {
this.editForm.roleId = res.roleIds[0] id: res.id,
if (res.merchantFileResponse) { merchantId: res.merchantId,
this.editForm.merhcnatImg = res.merchantFileResponse.fileUrl merchantName: res.merchantName,
this.editForm.fileName = res.merchantFileResponse.fileName staffName: res.staffName,
staffPhone: res.staffPhone,
password: res.password,
staffEmail: res.staffEmail,
staffJob: res.staffJob,
visibleInferiorMer: res.visibleInferiorMer,
roleIds: res.roleIds[0],
merchantImg: res.merchantFileResponse ? res.merchantFileResponse.fileUrl : '',
fileName: res.merchantFileResponse ? res.merchantFileResponse.fileName : ''
} }
console.log(this.editForm)
this.handleChangeMerchant(this.editForm.merchantId, true) this.handleChangeMerchant(this.editForm.merchantId, true)
}) })
}, },
handleChangeMerchant(e, editRecovery = false) { handleChangeMerchant(e, editRecovery = false) {
// console.log(e) // console.log(e)
if (!editRecovery) { if (!editRecovery) {
this.editForm.roleId = '' this.editForm.roleIds = ''
this.editForm.visibleInferiorMer = '' this.editForm.visibleInferiorMer = String(e)
} }
if (!e) { if (!e) {
this.baseData.merchantTree = [] this.baseData.merchantTree = []
this.baseData.roleList = [] this.baseData.roleList = []
this.getOptionsList('editFormData', false, 'roleId') this.getOptionsList('editFormData', false, 'roleIds')
} }
this.getRoleList(e) this.getRoleList(e)
this.getMerchantTree(e, editRecovery) this.getMerchantTree(e)
}, },
setCheckedTree() { setCheckedTree() {
var checkedList = this.editForm.visibleInferiorMer.split(',').map(item => +item) var checkedList = this.editForm.visibleInferiorMer.split(',').map(item => +item)
this.$refs.tree.setCheckedKeys(checkedList) this.$refs.tree.setCheckedKeys(checkedList)
}, },
getMerchantTree(value, editRecovery) { getMerchantTree(value) {
this.$apis.employee.getMerchantTreeApi({ id: value }).then(res => { this.$apis.employee.getMerchantTreeApi({ id: value }).then(res => {
this.baseData.merchantTree = res this.baseData.merchantTree = res
editRecovery && this.setCheckedTree() this.setCheckedTree()
}) })
}, },
filterNode(value, data) { filterNode(value, data) {
...@@ -236,7 +256,7 @@ export default { ...@@ -236,7 +256,7 @@ export default {
getRoleList(value) { getRoleList(value) {
this.$apis.employee.getRoleListApi({ id: value }).then(res => { this.$apis.employee.getRoleListApi({ id: value }).then(res => {
this.baseData.roleList = res this.baseData.roleList = res
this.getOptionsList('editFormData', false, 'roleId') this.getOptionsList('editFormData', false, 'roleIds')
}) })
}, },
getOptionsList(formName, hasAll = true, refreshSigle) { getOptionsList(formName, hasAll = true, refreshSigle) {
...@@ -267,25 +287,35 @@ export default { ...@@ -267,25 +287,35 @@ export default {
}, },
handleClickNode(data, node) { handleClickNode(data, node) {
// console.log(node.checkedNodes) // console.log(node.checkedNodes)
this.editForm.visibleInferiorMer = node.checkedNodes.map(item => item.id) this.editForm.visibleInferiorMer = node.checkedNodes.map(item => item.id).join(',')
this.$refs.editFormRef.$refs[this.editChildRef].validateField('visibleInferiorMer') this.$refs.editFormRef.$refs[this.editChildRef].validateField('visibleInferiorMer')
}, },
handleConfirm() { handleConfirm() {
// console.log(this.$refs.tree.getCheckedNodes()) // console.log(this.$refs.tree.getCheckedNodes())
console.log(this.editForm)
this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => { this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) { if (valid) {
var params = this.$common.utils.deepClone(this.editForm) var params = this.$common.utils.deepClone(this.editForm)
// merchantFileRequest if (this.editForm.merchantImg) {
params.roleIds = [this.editForm.roleId] params.merchantFileRequest = JSON.stringify({
params.merchantFileRequest = {
fileName: this.editForm.fileName, fileName: this.editForm.fileName,
fileUrl: this.editForm.merhcnatImg fileUrl: this.editForm.merchantImg
})
delete params.merchantImg
delete params.fileName
} }
console.log(this.editForm) console.log(params)
var apiName = this.routeInfo.addOrEdit == 1 ? 'addEmployeeApi' : 'updateEmployeeApi'
this.$apis.employee[apiName](params).then(res => {
this.$message({
message: res.code == '0' ? '操作成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
if (res.code == '0') {
this.handleCancel() this.handleCancel()
} }
}) })
}
})
}, },
handleCancel() { handleCancel() {
this.$router.push({ this.$router.push({
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
{{ item.label ? ':' : '' }} {{ item.label ? ':' : '' }}
</span> </span>
<slot v-if="item.addHtml" :name="item.addHtml" :scope="item"></slot> <slot v-if="item.addHtml" :name="item.addHtml" :scope="item"></slot>
<el-input v-else-if="item.type === 'input'" :placeholder="item.placeholder || '请输入' + item.label" v-model.trim="formObj[item.name]" :disabled="item.isDisabled" :maxlength="item.maxlength" :clearable="item.isClear || false" :type="item.inputType || 'text'" :style="{ width: item.width || 'auto' }" :show-word-limit="item.showLimit || false" @keydown.native="e => handleInputDown(e, item)"></el-input> <el-input v-else-if="item.type === 'input'" :placeholder="item.placeholder || '请输入' + item.label" v-model.trim="formObj[item.name]" :disabled="item.isDisabled" :maxlength="item.maxlength" :clearable="item.isClear || false" :type="item.inputType || 'text'" :style="{ width: item.width || 'auto' }" :show-word-limit="item.showLimit || false" :show-password="item.showPass || false" @keydown.native="e => handleInputDown(e, item)"></el-input>
<!-- 选择-输入框 --> <!-- 选择-输入框 -->
<el-input v-else-if="item.type === 'selectInput'" :placeholder="'请输入' + item.selectOption.find(k => k.name === searchSelectObj[item.selectName].attr).label" :maxlength="item.maxlength" v-model.trim="searchSelectObj[item.selectName].value" :clearable="item.isClear || false" :style="{ width: item.inputWidth || '130px' }" class="input-with-select"> <el-input v-else-if="item.type === 'selectInput'" :placeholder="'请输入' + item.selectOption.find(k => k.name === searchSelectObj[item.selectName].attr).label" :maxlength="item.maxlength" v-model.trim="searchSelectObj[item.selectName].value" :clearable="item.isClear || false" :style="{ width: item.inputWidth || '130px' }" class="input-with-select">
<el-select v-model="searchSelectObj[item.selectName].attr" :style="{ width: item.selectWidth || '130px' }" slot="prepend" placeholder="请选择" @change="item.handleSelectChange"> <el-select v-model="searchSelectObj[item.selectName].attr" :style="{ width: item.selectWidth || '130px' }" slot="prepend" placeholder="请选择" @change="item.handleSelectChange">
...@@ -187,6 +187,7 @@ export default { ...@@ -187,6 +187,7 @@ export default {
this.$message.error('图片尺寸最大为' + wdithLt + '像素*' + heightLt + '像素') this.$message.error('图片尺寸最大为' + wdithLt + '像素*' + heightLt + '像素')
} else { } else {
targetItem.handleUpload(e, file, targetItem) targetItem.handleUpload(e, file, targetItem)
// this.$emit('handleUpload', { e: e, file: file, targetItem: targetItem })
} }
} }
} }
...@@ -194,6 +195,7 @@ export default { ...@@ -194,6 +195,7 @@ export default {
// 图片删除 // 图片删除
handleImgDelete(targetItem, subIndex = -1) { handleImgDelete(targetItem, subIndex = -1) {
Array.isArray(this.formObj[targetItem.name]) ? this.formObj[targetItem.name].splice(subIndex, 1) : (this.formObj[targetItem.name] = '') Array.isArray(this.formObj[targetItem.name]) ? this.formObj[targetItem.name].splice(subIndex, 1) : (this.formObj[targetItem.name] = '')
this.$emit('handleImgDelete', targetItem)
}, },
// 图片查看 // 图片查看
handleImgLook(src) { handleImgLook(src) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!