thinkphp ajax删除 隐藏与显示

知识点:

1、ajax删除;

2、一个同步实现三个异步的效果。

html 部分

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>招聘管理</title>
<link href="__PUBLIC__/HomeStyle/css/layout_903ac4c.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/HomeStyle/css/widgets_680817d.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/HomeStyle/css/main.html_aio_7fcf01c.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/HomeStyle/css/main.html_aio_b9a55e6.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="__PUBLIC__/HomeStyle/css/main.html_aio_2_f8a294e.css"> </head>
<style type="text/css">
.delivery_tabs li.current_2 { color: #00b38a!important; border-bottom: 3px solid #00b38a; } </style>
<body> <!--首页 用户 公司 标题栏-->
<include file="Public/header" nav="Recruitment_manage" /> <!-- 页面主体START -->
<div class="container clearfix" id="container"> <!--左侧菜单栏-->
<div class="user_bindSidebar">
<dl class="user_sideBarmenu">
<dt class="title">帐号设置 </dt>
<dd>
<a href="{:U('Home/Company/bind_account')}">帐号绑定</a>
</dd>
<dd>
<a href="{:U('Home/Company/updatePwd')}">修改密码</a>
</dd>
<dd>
<a href="{:U('Home/Company/index')}">公司资料</a>
</dd> <dt class="title">招聘管理</dt>
<dd>
<a class="hover" href="{:U('Home/Recruit/Recruitment_manage')}">我的招聘</a>
</dd>
<dd>
<a href="{:U('Home/Wallet/apply_invoice')}">申请发票</a>
</dd>
<dd>
<a href="{:U('Home/Wallet/recharge')}">我的钱包</a>
</dd>
</dl> </div> <input type="hidden" value="1" id="hasSidebar"/>
<div class="user_userinfo_content">
<dl class="c_section">
<dt id="autofiletitle">
<h1>
招聘管理
<!--<select name=""style=" color:#999; margin-left:10px;"><option value="0" >2个月内投递</option></select>-->
<a href="">刷新</a>
</h1> </dt>
<dd class="recharge">
<!--用户基本信息栏-->
<include file="Public/company_header_user" nav=""/>
</dd>
<dd class="bullet_out">
<div class="delivery_tabs">
<ul class="reset" style="cursor:pointer">
<li class="current_2" onclick="navheader(this)">
<a id="job_state_li" >职位列表</a>
</li>
<li onclick="navheader(this)" >
<a id="received_resume" >收到简历</a>
</li >
<li onclick="navheader(this)">
<a id="download_resume" >已下载的简历</a>
</li>
<li class="current">
<a href="{:U('Home/CompanyJob/create')}" class="all_border current_checked ">新增职位</a>
</li>
</ul>
</div> <form id="receivedForm" style="display: none;">
<ul class="reset my_delivery" id="ullist">
<foreach name="received_resume" item="vo" >
<li >
<div class="d_item clearfix" >
<div class="d_job">
<a class="d_job_link" href="{:U('Home/UserShow/index',array('uid'=>$vo['user_id']))}" data-index="0" target="_blank" >
应聘: <em class="d_job_name">{$vo.job_name}</em>
</a>
<a class="received_resume_del d_time" href="javascript:void(0)" data-id="{$vo.id}" >
删除
</a>
</div>
<div class="d_resume"><span class="d_resume_type">{$vo.name}/{$vo.sex}/{$vo.work_year}</span>
<span class="d_time">{$vo.create_time|date='Y-m-d H:i',###}</span>
</div>
</div>
</li>
</foreach> </ul>
</form> <form id="downloadForm" style="display: none;">
<ul class="reset my_delivery">
<foreach name="download_resume" item="vo">
<li id="lilist_download">
<div class="d_item clearfix">
<div class="d_job">
<a class="d_job_link" href="{:U('Home/UserShow/index',array('uid'=>$vo['user_id']))}" data-index="0" target="_blank" >
简历: <em class="d_job_name">{$vo.resume_name}</em>
</a>
<a class="Resume_download_del d_time" href="javascript:void(0)" data-id="{$vo.id}" >
删除
</a>
</div>
<div class="d_resume"><span class="d_resume_type">{$vo.name}/{$vo.sex}/{$vo.work_year}</span>
<span class="d_time">{$vo.create_time|date='Y-m-d H:i',###}</span>
</div>
</div>
</li>
</foreach>
</ul>
</form> <form id="jobForm" style="display: block;">
<ul class="reset my_delivery" >
<foreach name="job_state" item="vo">
<li >
<div class="d_item clearfix">
<div class="d_job">
<a class="d_job_link" href="{:U('Home/JobShow/index/',array('jid'=>$vo['id']))}" data-index="0" target="_blank" >
职位:<em class="d_job_name">{$vo.name}</em>
</a>
<a href="{:U('Home/CompanyJob/jobedit/',array('jid'=>$vo['id']))}" class="d_time">编辑</a>
<!--<a href="{:U('Home/RecruitmentManage/del_job/',array('id'=>$vo['id']))}" class="d_time">删除</a>-->
<a class="job_del d_time" href="javascript:void(0)" data-id="{$vo.id}" >
删除
</a>
</div>
<div class="d_resume"><span class="d_resume_type">部门:{$vo.branch}</span>
<span class="d_time">{$vo.create_time|date='Y-m-d H:i',###}</span>
</div>
</div>
</li>
</foreach>
</ul>
</form> </dd>
</dl>
</div>
</div>
<include file="Public/footer" nav='index'/>
</body>
<script src="__PUBLIC__/HomeStyle/js/jquery.1.10.1.min.js"></script>
<script src="__PUBLIC__/HomeStyle/layer_mobile/layer.js"></script>
<script type="text/javascript"> function navheader(obj) { //点击后,去掉ul中除了index=3以外的所有li的class,li从0开始计算
$(".delivery_tabs ul li:lt(3)").attr("class", "");
//给当前选中的li加current_2样式
$(obj).attr("class","current_2");
} $(document).ready(function(){ //1点击收到简历
$("#received_resume").click(function() {
//收到简历form显示
$("#receivedForm").css('display','block');
//已下载简历form隐藏
$("#downloadForm").css('display','none');
//职位状态form隐藏
$("#jobForm").css('display','none'); }); //2点击已下载简历
$("#download_resume").click(function () {
//收到简历form隐藏
$("#receivedForm").css('display','none');
//已下载简历form显示
$("#downloadForm").css('display','block');
//职位状态form隐藏
$("#jobForm").css('display','none'); }); //3点击职位状态
$("#job_state_li").click(function () {
//收到简历form隐藏
$("#receivedForm").css('display','none');
//已下载简历form隐藏
$("#downloadForm").css('display','none');
//职位状态form显示
$("#jobForm").css('display','block'); }); //删除职位
$('.job_del').click(function(){
var obj=$(this); //指当前被点击的带有job_del类别的对象
if(confirm('你确定要删除该职位吗?')){
$.ajax({
url:"/Home/Recruit/del_job",
data:{id:obj.attr('data-id')},
type:'post',
success:function(data){
// alert(data.msg);
if(data.msg=="删除成功"){
obj.parents('li').remove();
}else{
layer.open({
content:'删除失败',
btn:'我知道了'
})
} //跟新当前职位数
//$('#job_number').html(data.num)
}
})
} }); //删除已下载的简历
$('.Resume_download_del').click(function(){
var obj=$(this);
if(confirm('你确定要删除该职位吗?')){
$.ajax({
url:"/Home/Recruit/del_resume_download",
data:{id:obj.attr('data-id')},
type:'post',
success:function(data){
// alert(data.msg);
if(data.msg=="删除成功"){
obj.parents('li').remove();
}else{
layer.open({
content:'删除失败',
btn:'我知道了'
})
}
}
})
}
}); //删除已收到的简历
$('.received_resume_del').click(function(){
var obj=$(this);
if(confirm('你确定要删除该职位吗?')){
$.ajax({
url:"/Home/Recruit/del_received_resume",
data:{id:obj.attr('data-id')},
type:'post',
success:function(data){
// alert(data.msg);
if(data.msg=="删除成功"){
obj.parents('li').remove();
}else{
layer.open({
content:'删除失败',
btn:'我知道了'
})
}
}
})
}
}); }); </script> </html>

  

后台thinkphp部分

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/6/9
* Time: 17:14
*/ namespace Home\Controller;
class RecruitController extends CompanyBaseController { public function __construct()
{
parent::__construct(); }
//我的招聘
public function Recruitment_manage()
{
if (!session('?user.id')) {
$this->redirect('User/login');
} else {
$name = $_SESSION['user']['username'];
$user = M("Users");
$usermodel = $user->where("username=" . $name)->find(); $this->assign("user", $usermodel);
}
//1显示 收到的简历
$received_resume=$this->received_resume();
//2显示 已下载的简历
$download_resume=$this->download_resume();
//3显示 职位状态
$job_state=$this->job_state();
//输出到模板
$this->assign('received_resume',$received_resume);
$this->assign('download_resume',$download_resume);
$this->assign('job_state',$job_state);
$this->display(); } //收到简历
public function received_resume(){
$sendObj=M("Send");
$jobObj=M("Job");
$resumeObj=M("Resume");
$basicConfig= M('BasicConfigCategory');
$array=array('女','男');//0代表女,1代表男
//查询send表中包含company_id的信息 存入res
//send表中的company_id 等于企业类型的用户id
$res=$sendObj->where(array('company_id'=>$this->uid))->order('create_time desc')->select();
//重新组合res对象的内容,用于输出到前台.相当于新建了一个model
foreach($res as &$val ) {
//循环查询res对象val在job_id 对应的job表信息 存入res2
$res2 = $jobObj->where(array('id' => $val['job_id']))->find();
//查询res中user_id对应的resume表信息
//用户id和简历id相同,简历表id不是自增长的。????那么只能创建一份简历。
$res3 = $resumeObj->where(array('id' => $val['user_id']))->find();
$res4= $basicConfig->where(array('id'=>$res3['work_year']))->find();
// 在res2取与job_id对应的职位名称
$val['job_name'] = $res2['name'];
//res3中取与user_id对应的用户名
$val['name'] = $res3['name'];
//时间前台方法做
// $val['create_time'] = date("Y-m-d H:i", $val['create_time']);
//性别
$val['sex'] = $array[$res3['sex']];
//工作经验
$val['work_year']= $res4['name'];
}
return $res;
} //已下载的简历
public function download_resume(){
$resume_download=M("Resume_download");
//$jobObj=M("Job");
$basicConfig= M('BasicConfigCategory');
//var_dump($basicConfig);
$resumeObj=M("Resume");
$array=array('女','男');
//表中的company_id 其实是用户(企业)的id
$res=$resume_download->where(array('company_id'=>$this->uid))->order('create_time desc')->select();
//重新组合res对象的内容,用于输出到前台.相当于新建了一个model
foreach($res as &$val ) {
// $res2 = $jobObj->where(array('id' => $val['job_id']))->find();
//用户id和简历id相同,简历表id不是自增长的。
$res3 = $resumeObj->where(array('id' => $val['user_id']))->find();
$res4= $basicConfig->where(array('id'=>$res3['work_year']))->find();
//职位名称
//$val['job_name'] = $res2['name'];
//简历名称
$val['resume_name']=$res3['resume_name'];
//用户名
$val['name'] = $res3['name'];
//性别
$val['sex'] = $array[$res3['sex']];
//工作经验
$val['work_year']= $res4['name'];
//时间前台方法做
// $val['create_time'] = date("Y-m-d H:i", $val['create_time']);
}
return $res;
} /*
职位状态列表
显示companyid当前登录发布的 职位名称(链接到详情)、 发布时间、发布状态
company表的id==用户id==company_id==user_id
*/
public function job_state(){
$jobObj=M('Job');
//找出这个企业一共发布的所有职位
//compan_id 是企业类型用户的id
$res=$jobObj->where(array('company_id'=>$this->uid))->order('create_time desc')->select();
//循环遍历职位
// foreach ($res as &$val){
// $res2=$jobObj->where(array('id'=>$val['job_id']))->find();
// //职位名称
// $val['job_name']=$res2['name'];
// }
return $res; } //删除职位
public function del_job(){ $id=I('post.id');
$re=M('Job')->where('id='.$id)->delete();
// $jobnum = M('Job')->where(array('state' => 1))->count(); //审核通过的职位数
//$re=1; 测试
//delete方法的返回值是删除的记录数,如果返回值是false则表示SQL出错,返回值如果为0表示没有删除任何数据。
if($re>0){
$msg['code'] = 1;
$msg['msg'] = '删除成功';
}else{
$msg['code'] = 0;
$msg['msg'] = '删除失败';
}
return $this->ajaxReturn($msg); } //删除收到的简历
public function del_received_resume(){ $id=I('post.id');
$re=M('Send')->where('id='.$id)->delete();
// $re=0; //测试
//delete方法的返回值是删除的记录数,如果返回值是false则表示SQL出错,返回值如果为0表示没有删除任何数据。
if($re>0){
$msg['code'] = 1;
$msg['msg'] = '删除成功';
}else{
$msg['code'] = 0;
$msg['msg'] = '删除失败';
}
return $this->ajaxReturn($msg); } //删除已下载的简历
public function del_resume_download(){
$id=I('post.id');
$re=M('Resume_download')->where('id='.$id)->delete();
// $re=0; //测试
//delete方法的返回值是删除的记录数,如果返回值是false则表示SQL出错,返回值如果为0表示没有删除任何数据。
if($re>0){
$msg['code'] = 1;
$msg['msg'] = '删除成功';
}else{
$msg['code'] = 0;
$msg['msg'] = '删除失败';
}
return $this->ajaxReturn($msg);
} }

  

上一篇:Linux 文件描述符详解


下一篇:Nodejs学习笔记(十六)--- Pomelo介绍&入门