员工增加页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>XXXX系统</title>
    <link rel="stylesheet" href="../../plugins/element-ui/index.css">
    <link rel="stylesheet" href="../../styles/common.css">
    <link rel="stylesheet" href="../../styles/page.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.3/axios.js"></script>
</head>
<body>
    <div class="addBrand-container" id="employee-add-app">
        <div class="container">
            <el-form
                ref="ruleForm"
                :model="ruleForm"
                :rules="rules"
                :inline="false"
                label-width="180px"
                class="demo-ruleForm"
            >
                <div>
                    <el-form-item
                        label="员工姓名:"
                        prop="name"
                    >
                        <el-input 
                            v-model="ruleForm.name"
                            placeholder="请输入员工姓名"
                            maxlength="20"
                        />
                    </el-form-item>

                    <el-form-item
                        label="电话:"
                        prop="phone"
                    >
                        <el-input 
                            v-model="ruleForm.phone"
                            placeholder="请输入手机号"
                            maxlength="20"
                        />
                    </el-form-item>

                    <el-form-item
                        label="电邮:"
                        prop="email"
                    >
                        <el-input 
                            v-model="ruleForm.email"
                            placeholder="请输入电子邮件地址"
                            maxlength="20"
                        />
                    </el-form-item>

                    <el-form-item
                        label="职位:"
                        prop="jobId"
                    >
                        <el-select
                            v-model="ruleForm.jobId"
                            placeholder="请选择职位"
                        >
                            <el-option v-for="(item,index) in jobList" :key="index" :label="item.name" :value="item.id"></el-option>
                        </el-select>   
                    </el-form-item>
                    <el-form-item
                        label="工作门店:"
                        prop="storeId"
                    >
                        <el-select
                            v-model="ruleForm.storeId"
                            placeholder="请选择工作门店"
                        >
                            <el-option v-for="(item,index) in storeList" :key="index" :label="item.name" :value="item.id"></el-option>
                        </el-select>   
                    </el-form-item>
                </div>
<!--                偏好-->
                    <el-form-item label="工作日偏好:">
                        <el-checkbox
                            class="all_t"
                            :indeterminate="isIndeterminate"
                            v-model="checkAll"
                            @change="handleCheckAllChangeWorkdays"
                        >全选</el-checkbox>
                        <el-checkbox-group v-model="checkedWorkday" @change="handleCheckColumnChangeWorkdays">
                            <el-checkbox
                                    v-for="item in workdayOption"
                                    :key="item.id"
                                    :label="item.id"
                            >{{item.value}}</el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="工作时间偏好:">
                        <el-time-select
                                v-model="ruleForm.startTime"
                                :picker-options="{start: '07:00',step: '01:00',end: '22:00'}"
                                placeholder="开始工作时间"
                        ></el-time-select>
                        -
                        <el-time-select
                                v-model="ruleForm.endTime"
                                :picker-options="{start: '09:00',step: '01:00',end: '23:00',minTime:ruleForm.startTime}"
                                placeholder="结束工作时间"
                        ></el-time-select>
                    </el-form-item>
                    <el-form-item label="班次时长偏好(小时):">
                        <el-radio-group v-model="ruleForm.checkDuration">
                            <el-radio-button label="2">2小时</el-radio-button>
                            <el-radio-button label="3">3小时</el-radio-button>
                            <el-radio-button label="4">4小时</el-radio-button>
                        </el-radio-group>
                    </el-form-item>

                <div class="subBox prefer">
                    <el-form-item>
                        <el-button @click="goBack()">
                            取消
                        </el-button>
                        <el-button
                            type="primary"
                            @click="submitForm('ruleForm')"
                        >
                            保存
                        </el-button>
                        <el-button
                            v-if="actionType == 'add'"
                            type="primary"
                            class="continue"
                            @click="submitForm('ruleForm','goAnd')"
                        >
                            保存并继续添加员工
                        </el-button>
                    </el-form-item>
                </div>
            </el-form>
        </div>
    </div>
    <script src="../../plugins/vue/vue.js"></script>
    <script src="../../plugins/element-ui/index.js"></script>
    <script src="../../plugins/axios/axios.min.js"></script>
    <script src="../../js/request.js"></script>
    <script src="../../js/validate.js"></script>
    <script src="../../js/index.js"></script>
    <script src="../../api/employee.js"></script>
</body>
    <script>
        new Vue({
            el:'#employee-add-app',
            data(){
                return{
                    id:'',
                    restKey:0,
                    textarea:'',
                    value:'',
                    actionType:'',
                    jobList:[],
                    storeList:[],
                    workdayOption:[
                        {id:1,value:'星期一'},
                        {id:2,value:'星期二'},
                        {id:3,value:'星期三'},
                        {id:4,value:'星期四'},
                        {id:5,value:'星期五'},
                        {id:6,value:'星期六'},
                        {id:7,value:'星期日'},
                    ],
                    isIndeterminate:true,
                    checkAll:false,
                    vueRest:'1',
                    index:0,
                    inputStyle:{'flex':1},
                    ruleForm:{
                        'name':'',
                        'phone':'',
                        'email':'',
                        'status':true,
                        jobId:'',
                        storeId:'',
                        checkWorkday:[],
                        checkDuration:'',
                        startTime:'',
                        endTime:'',
                    },
                    checkedWorkday:[],
                    mak:false
                }
            },
            computed:{
                rules(){
                    const validateEmail = (rule,value,callback) => {
                        if (value.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/)) {
                            callback()
                        } else {
                            callback(new Error('邮箱格式错误!'))
                        }
                    }
                    const validatePhone = (rule,value,callback) =>{
                        if(value.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/)){
                            callback()
                        }else{
                            callback(new Error('手机格式错误!'))
                        }
                    }
                    return{
                        'name':[
                            {'required':true,'message':'请填写员工名称','trigger':'blur'}
                        ],
                        'phone':[
                            {'required':true,'message':'请填写手机号码','trigger':'blur'},
                            { validator:validatePhone,trigger:'blur'}
                        ],
                        'jobId':[
                            {'required':true,'message':'请选择职位','trigger':'change'}
                        ],
                        'storeId':[
                            {'required':true,'message':'请选择所属门店','trigger':'change'}
                        ],
                        'email':[
                            {'required':true,'message':'请填写电子邮件地址','trigger':'blur'},
                            { validator:validateEmail,trigger: 'blur'}
                        ],
                    }
                }
            },
            created(){
                this.id=requestUrlParam('id')
                this.getJobsList()
                this.getStoresList()
                this.names=this.workdayOption
                this.actionType=this.id ? 'edit' : 'add'
                if(this.id){
                    this.init();
                }
            },
            mounted(){
            },
            methods: {
                async init(){
                    queryEmployeeById(this.id).then(res => {
                        console.log(res)
                        if(String(res.code) === '1'){
                            this.ruleForm = {...res.data}
                            let strCheckWorkday =(this.ruleForm.checkWorkday || '').split(',')
                            this.checkedWorkday = strCheckWorkday.map(Number)
                            console.log(this.checkedWorkday)
                        }else{
                            this.$message.error(res.msg || '操作失败')
                        }
                    })
                },

                //获取职位
                getJobsList(){
                    getJobList().then(res => {
                        if(res.code === 1){
                            this.jobList=res.data
                        }else{
                            this.$message.error(res.msg || '操作失败')
                        }
                    })
                },
                //获取门店
                getStoresList(){
                    getStoreList().then(res => {
                        if(res.code === 1){
                            this.storeList=res.data
                        }else{
                            this.$message.error(res.msg || '操作失败')
                        }
                    })
                },

                handleCheckAllChangeWorkdays(val) {
                    let checkedsItem = val ? this.workdayOption : []
                    if (checkedsItem.length > 0) {
                        checkedsItem.map(item => {
                            this.ruleForm.checkWorkday.push(item.id)
                        })
                    } else {
                        this.ruleForm.checkWorkday = []
                    }
                    this.isIndeterminate = false
                },
                handleCheckColumnChangeWorkdays(value) {
                    let checkedCount = value.length
                    this.checkAll = checkedCount === this.names.length
                    this.ruleForm.checkWorkday = value
                    this.isIndeterminate = checkedCount > 0 && checkedCount < this.names.length
                },
                inputHandle(val,index){},
                submitForm(formName,st){
                    this.$refs[formName].validate((valid)=>{
                        if(valid){
                            let params = {...this.ruleForm}
                            params.status = this.ruleForm ? 1:0
                            params.jobId=this.ruleForm.jobId
                            params.storeId=this.ruleForm.storeId
                            params.checkDuration=this.ruleForm.checkDuration
                            params.checkWorkday=this.ruleForm.checkWorkday.toString()
                            params.startTime=this.ruleForm.startTime
                            params.endTime=this.ruleForm.endTime
                            console.log(params)
                            if(this.actionType == 'add'){
                                delete params.id
                                addEmployee(params).then(res=>{
                                    if(res.code === 1){
                                        this.$message.success('员工添加成功!')
                                        if(!st){
                                            this.goBack()
                                        }else{
                                            this.checkWorkday=[].toString()
                                            this.ruleForm={
                                                'name':'',
                                                'phone':'',
                                                'email':'',
                                                'status':true,
                                                jobId:'',
                                                storeId:'',
                                                checkWorkday:[],
                                                checkDuration:'',
                                                startTime:'',
                                                endTime:'',
                                            }
                                        }
                                    }else{
                                        this.$message.error(res.msg || '操作失败')
                                    }
                                }).catch(err=>{
                                    this.$message.error('请求出错了:'+err)
                                })
                            }else{
                                delete params.updateTime
                                editEmployee(params).then(res=>{
                                    if(res.code == 1){
                                        this.$message.success('员工信息修改成功!')
                                        this.goBack()
                                    }else{
                                        this.$message.error(res.msg || '操作失败')
                                    }
                                }).catch(err=>{
                                    this.$message.error('请求出错了:'+err)
                                })
                            }
                        }else{
                            return false
                        }
                    })
                },

                handleAvatarSuccess (response, file, fileList) {
                    // 拼接down接口预览
                    if(response.code === 0 && response.msg === '未登录'){
                      window.top.location.href = '../../page/login.html'
                    }else{
                       this.ruleForm.image = response.data
                    }
                },
                goBack(){
                    window.parent.menuHandle({
                        id:'2',
                        url:'../../page/employee/list.html',
                        name:'员工管理'
                    },false)
                }
            },
        });
    </script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值