Commit a33563e7 by cwq0219

员工-新增/编辑

1 parent 9e08eb6c
......@@ -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 @@
</div>
<div class="container">
<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">
<select-page :form="editForm" width="300px" :targetItem="item.scope" @handleChange="handleChangeMerchant"></select-page>
</template>
......@@ -59,18 +59,27 @@ export default {
staffPhone: '',
password: '',
visibleInferiorMer: '',
roleId: '',
merhcnatImg: '',
roleIds: '',
merchantImg: '',
fileName: ''
},
editRule: {
merchantId: [{ 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位
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' }],
roleId: [{ required: true, message: '请选择角色权限', trigger: 'change' }]
roleIds: [{ required: true, message: '请选择角色权限', trigger: 'change' }]
// staffEmail: [{ required: false, validator: (rule, value, callback) => {}, trigger: 'change' }]
},
isBlock: true,
editFormData: [
......@@ -103,6 +112,7 @@ export default {
{
label: '登录密码',
name: 'password',
showPass: true,
width: '360px',
type: 'input',
maxlength: 15
......@@ -114,7 +124,7 @@ export default {
},
{
label: '角色权限',
name: 'roleId',
name: 'roleIds',
type: 'select',
width: '360px',
optionList: [],
......@@ -124,7 +134,7 @@ export default {
},
{
label: '头像',
name: 'merhcnatImg',
name: 'merchantImg',
type: 'upload',
maxPhotoNum: 1,
// wdithLt: 800,
......@@ -133,16 +143,15 @@ export default {
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
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) {
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 {
},
methods: {
handleImgDelete(targetItem) {
this.$set(this.editForm, 'merchantImg', '')
this.editForm.fileName = ''
},
getAllMerchantList() {
this.$apis.employee.getAllMerchantListApi({}).then(res => {
this.baseData.allMerchantList = res
......@@ -195,38 +208,45 @@ export default {
},
getInfo() {
this.$apis.employee.getDetailInfoApi({ id: this.routeInfo.id }).then(res => {
this.editForm = res
this.editForm.roleId = res.roleIds[0]
if (res.merchantFileResponse) {
this.editForm.merhcnatImg = res.merchantFileResponse.fileUrl
this.editForm.fileName = res.merchantFileResponse.fileName
this.editForm = {
id: res.id,
merchantId: res.merchantId,
merchantName: res.merchantName,
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)
})
},
handleChangeMerchant(e, editRecovery = false) {
// console.log(e)
if (!editRecovery) {
this.editForm.roleId = ''
this.editForm.visibleInferiorMer = ''
this.editForm.roleIds = ''
this.editForm.visibleInferiorMer = String(e)
}
if (!e) {
this.baseData.merchantTree = []
this.baseData.roleList = []
this.getOptionsList('editFormData', false, 'roleId')
this.getOptionsList('editFormData', false, 'roleIds')
}
this.getRoleList(e)
this.getMerchantTree(e, editRecovery)
this.getMerchantTree(e)
},
setCheckedTree() {
var checkedList = this.editForm.visibleInferiorMer.split(',').map(item => +item)
this.$refs.tree.setCheckedKeys(checkedList)
},
getMerchantTree(value, editRecovery) {
getMerchantTree(value) {
this.$apis.employee.getMerchantTreeApi({ id: value }).then(res => {
this.baseData.merchantTree = res
editRecovery && this.setCheckedTree()
this.setCheckedTree()
})
},
filterNode(value, data) {
......@@ -236,7 +256,7 @@ export default {
getRoleList(value) {
this.$apis.employee.getRoleListApi({ id: value }).then(res => {
this.baseData.roleList = res
this.getOptionsList('editFormData', false, 'roleId')
this.getOptionsList('editFormData', false, 'roleIds')
})
},
getOptionsList(formName, hasAll = true, refreshSigle) {
......@@ -267,23 +287,33 @@ export default {
},
handleClickNode(data, node) {
// 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')
},
handleConfirm() {
// console.log(this.$refs.tree.getCheckedNodes())
console.log(this.editForm)
this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) {
var params = this.$common.utils.deepClone(this.editForm)
// merchantFileRequest
params.roleIds = [this.editForm.roleId]
params.merchantFileRequest = {
fileName: this.editForm.fileName,
fileUrl: this.editForm.merhcnatImg
if (this.editForm.merchantImg) {
params.merchantFileRequest = JSON.stringify({
fileName: this.editForm.fileName,
fileUrl: this.editForm.merchantImg
})
delete params.merchantImg
delete params.fileName
}
console.log(this.editForm)
this.handleCancel()
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()
}
})
}
})
},
......
......@@ -12,7 +12,7 @@
{{ item.label ? ':' : '' }}
</span>
<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-select v-model="searchSelectObj[item.selectName].attr" :style="{ width: item.selectWidth || '130px' }" slot="prepend" placeholder="请选择" @change="item.handleSelectChange">
......@@ -187,6 +187,7 @@ export default {
this.$message.error('图片尺寸最大为' + wdithLt + '像素*' + heightLt + '像素')
} else {
targetItem.handleUpload(e, file, targetItem)
// this.$emit('handleUpload', { e: e, file: file, targetItem: targetItem })
}
}
}
......@@ -194,6 +195,7 @@ export default {
// 图片删除
handleImgDelete(targetItem, subIndex = -1) {
Array.isArray(this.formObj[targetItem.name]) ? this.formObj[targetItem.name].splice(subIndex, 1) : (this.formObj[targetItem.name] = '')
this.$emit('handleImgDelete', targetItem)
},
// 图片查看
handleImgLook(src) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!