;(function () { if (window.Basic_job) { return } window.Basic_job = function (id, listArr) { this.id = (id || '').replace('u', '') this.listArr = listArr this.resumeColumn = null this.pxid = getUrlQuery('pxid') this.formDialogId = 'resume-dialog-' + this.id this.init() } Basic_job.prototype = { init: function () { this.bind() }, bind: function () { var self = this if (Number(this.listArr.module_style) === 1) { $('#u' + this.id + ' .job-table-row').on('click', function (e) { self.onClickExpandIcon(e) }) } $('#u' + this.id + ' .btn-submit').on('click', function (e) { self.onClickSubmitBtn(e); }); }, bindDialog() { var self = this this.$dialog.find('.dialog_close').on('click', function () { self.$dialog.remove() }) this.$dialog.find('.form_submit').on('click', function () { if (jobForm.checkForm(self.form, self.formDialogId)) { self.submit() } }) this.$dialog.find('.validateCode_img').on('click', function () { var random = Math.random() $(this).attr('src', '/login-verify.html?width=121&height=44&app=mb&' + random + '') }) }, onClickExpandIcon(e) { var $icon = $(e.currentTarget).find('.fa'); if ($icon.hasClass('fa-angle-right')) { $icon.removeClass('fa-angle-right') $icon.addClass('fa-angle-down') $icon.parents('.el-table__row').next().show() } else { $icon.removeClass('fa-angle-down') $icon.addClass('fa-angle-right') $icon.parents('.el-table__row').next().hide() } }, onClickSubmitBtn(e) { var self = this var styleType = $(e.target).data('style') var jobId = $(e.target).data('id') var jobTitle = $(e.target).parents('.job-detail-wrapper').find('.job-title').html() if (this.isExpired(e)) { return myTip.showExpireTip() } var option = { styleType: styleType, jobId: jobId, jobTitle: jobTitle } if (this.resumeColumn) { this.showDialog(option) } else { self.getResumeData({ styleType: styleType }, function () { self.showDialog(option) }) } }, submit() { var self = this var data = {} this.form.fields.contentList.forEach(function (item) { data[item.name] = ($('#' + self.formDialogId).find('.input-' + item.name).val() || '').trim() }) data.verify = ($('#' + this.formDialogId).find('.validateCode_input').val() || '').trim() data.id = this.form.id $.ajax({ type: 'POST', url: '/?app=mb&m=contact&a=resume&pxid=' + this.pxid, data, success: function (res) { if (typeof res === 'string') { try { res = JSON.parse(res) } catch (e) { console.error('鑾峰彇鏁版嵁鏈夎') } } if (!res.isSuccess) { return myTip.showErrorTip(res.msg) } else { myTip.showSuccessTip('鎻愪氦鎴愬姛') setTimeout(function () { self.$dialog.remove() }, 3000) } } }) }, getResumeData(option, cb) { var self = this $.ajax({ type: "GET", url: '/?app=mb&m=contact&a=resumeColumn&pxid=' + this.pxid, success: function (res) { if (typeof res === 'string') { res = JSON.parse(res) } self.resumeColumn = res cb && cb() } }); }, showDialog(option) { var self = this option = option || {} var styleType = option.styleType var jobId = option.jobId var jobTitle = option.jobTitle var map = this.resumeColumn[Number(styleType) - 1] var textName = map.name || "濮撳悕" var textPhone = map.phone || '鎵嬫満鍙? var textEmail = map.email || '閭' var form = { id: jobId, fields: { contentList: [{ "title": textName, "name": "name", "placeholder": "璇疯緭鍏? + removeTrailingColon(textName), "require": true }, { "title": textPhone, "name": "phone", "placeholder": "璇疯緭鍏? + removeTrailingColon(textPhone), "require": true }, { "title": textEmail, "name": "email", "placeholder": "璇疯緭鍏? + removeTrailingColon(textEmail), "require": true }], "buttonName": "绔嬪嵆鎻愪氦", "popupName": jobTitle, } } Object.keys(map).forEach(function (key, index) { if (!map[key]) { return; } var excludeKeys = ['name', 'phone', 'email', 'img', 'title_first_1', 'title_first_2', 'title_first_3', 'title_first_4', 'title_first_5', 'title_first_6', 'title_first_7', 'title_first_8', 'title_second_1'] if (excludeKeys.indexOf(key) >= 0 || key.indexOf('title_') === 0) { return } form.fields.contentList.push({ "title": map[key], "name": key, "placeholder": "璇疯緭鍏? + removeTrailingColon(map[key]), }) }) this.form = form var $dialog = this.getDialogEl(jobTitle) var dom = $dialog dom.find('.my_form .form_content').empty() dom.css({display: 'block'}); dom.find('.loading_img').css({display: 'inline-block'}) dom.find('.form_warp').css({display: 'none'}) this.insertFormItem($dialog, form) this.insertVerifyCode($dialog) this.insertSublimeBtn($dialog) this.$dialog = $dialog $('.move_Frame').append($dialog) this.bindDialog() dom.find('.form_content').prepend('
搴旇仒鑱屼綅锛? + jobTitle + '
') dom.find('#resume').parent().addClass('form-content-resume') dom.find('#resume').parents('.form_item_wrap').addClass('form_item_wrap-resume') dom.find('#resume').remove() dom.find('.form-content-resume').append($('.resume-table-u' + self.id + '.table-' + styleType).prop('outerHTML')) dom.find('.resume-table-u' + self.id + '.table-' + styleType).show() // hide loading and show content dom.find('.loading_img').hide() dom.find('.form_warp').show() dom.find('.form_warp').scrollTop(0); dom.show() }, isExpired(e) { var $time = $(e.target).parents('.job-detail-wrapper').find('.item-content-time') if ($time.hasClass('no-endtime')) { return false } var time = $time.html() return new Date(time).getTime() < new Date().getTime() }, showExpireTip() { var title = '宸茶秴鍑烘埅姝㈡椂闂? myTip.showErrorTip(title) }, getDialogEl(jobTitle) { var html = '
\
\
\
\ \
\
\ ' + jobTitle + '\ \
\
\
\
\
\
\
\
\
\
\
\
' return $(html) }, insertFormItem($dialog, form) { var html = '' form.fields.contentList.forEach(function (item) { html = html + '
\
\

' + item.title + '' + (item.require ? '*' : '') + '

\ \
\
' }) $dialog.find('.form_content').append(html) }, insertVerifyCode($dialog) { var html = '\
\
\
\ \ verify-code \
\
\
' $dialog.find('.form_content').append(html) }, insertSublimeBtn($dialog) { var html = '\
\
\ \
\
' $dialog.find('.form_content').append(html) } } window.jobForm = { rules: { name: { required: true, }, phone: { required: true, validator: function (value) { var reg = /^1[3456789]\d{9}$/; var re = new RegExp(reg); return re.test(value) }, message: '鎵嬫満鍙锋牸寮忎笉姝g‘' }, email: { required: true, validator: function (value) { var reg = /^([A-Za-z0-9_\-\.\u4e00-\u9fa5])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/ var re = new RegExp(reg); return re.test(value) }, message: '閭鏍煎紡涓嶆纭? }, IDCard: { validator: function (value) { var reg = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/; var re = new RegExp(reg); return re.test(value) }, message: '韬唤璇佸彿鐮佹牸寮忎笉姝g‘' }, verify: { required: true } }, checkForm: function (form, formDialogId) { var list = form.fields.contentList.slice() list.push({ name: 'verify', title: '楠岃瘉鐮? }) for (var i = 0; i < list.length; i++) { var item = list[i] var rule = this.rules[item.name] var value = ($('#' + formDialogId + ' .input-' + item.name).val() || '').trim() if (rule) { if (rule.required && (!value && value !== 0)) { myTip.showErrorTip('璇疯緭鍏? + removeTrailingColon(item.title)) this.scrollToErrorFormItem(item.name, formDialogId) return false } if (rule.validator && !rule.validator(value)) { myTip.showErrorTip(rule.message) this.scrollToErrorFormItem(item.name, formDialogId) return false } } } return true }, scrollToErrorFormItem: function (name, formDialogId) { $('#' + formDialogId + ' .input-' + name)[0].scrollIntoViewIfNeeded() }, } window.myTip = { showErrorTip(title) { this.showTip(title, true) }, showSuccessTip(title) { this.showTip(title) }, showTip(title, isError) { var tips_dialog = $('.tips_dialog'); tips_dialog.css({display: 'block'}); tips_dialog.find('.tips_error').css({display: 'block'}) if (isError) { tips_dialog.find('.tips_error_img').css({display: 'inline-block'}) tips_dialog.find('.tips_success_img').css({display: 'none'}) } else { tips_dialog.find('.tips_error_img').css({display: 'none'}) tips_dialog.find('.tips_success_img').css({display: 'inline-block'}) } tips_dialog.find('.tips_dialog_content').text(title) setTimeout(function () { tips_dialog.fadeOut(500, function () { tips_dialog.find('.tips_error').css({display: 'none'}); }); }, 3000) }, } function getUrlQuery(key) { var search = window.location.search.replace('?', '') var list = search.split('&') var query = {} list.forEach(function (item) { var q = item.split('=') query[q[0]] = q[1] }) return query[key] } function removeTrailingColon(str) { return (str || '').replace(/(:|锛?\s*$/, '') } })();