thinkphp之日报项目中——的Project表中的add页面实现自动计算实时显示

本文介绍了在ThinkPHP的日报项目中,如何在Project表的添加(add)页面实现实时计算并显示数据。通过利用前端技术与后端API交互,实现了数据的动态更新,提高了用户体验。
摘要由CSDN通过智能技术生成
1.D:\PHPTutorial\WWW\week\application\admin\controller\Project.php
<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
    class Project extends Controller  // 项目控制器
    {
        public function lst()
        {
            $projectres = \think\Db::name('project')->paginate(3);
            $this->assign('projectres', $projectres);
            return $this->fetch('Project/lst');
        }
        public function add()
        {
            if (request()->isPost()){
                if (isset($_POST['fro_sco']) && isset($_POST['bac_sco']) && isset($_POST['dui_sco'])) { //isset判断post过来,有没有post这个字段;
                    if ($_POST['fro_sco'] != "" && $_POST['bac_sco'] != "" && $_POST['dui_sco'] != "") { //如果有post这个字段判断字段为不为空,如果不为空就把它们加起来
                        $tot_sco = $_POST["fro_sco"] + $_POST["bac_sco"] + $_POST["dui_sco"];
                    } else {
                        $tot_sco = 0;
                    }
                } else {
                    $tot_sco = 0;
                }
                $data = [
                    'procode'=>input('procode'), 
                    'proname'=>input('proname'),
                    'prm_name'=>input('prm_name'),
                    'tem_name'=>input('tem_name'),
                    'procrea'=>input('procrea'),
                    'prostart'=>input('prostart'),
                    'proend'=>input('proend'),
                    'fro_sco'=>input('fro_sco'),
                    'bac_sco'=>input('bac_sco'),
                    'dui_sco'=>input('dui_sco'),
                    'tot_sco'=>$tot_sco,
                    'remark'=>input('remark'),
                ];
                $validate = \think\Loader::validate('Project');
                if (!$validate->scene('project')->check($data)){
                    $this->error($validate->getError());
                    die;
                }
                if (db('project')->insert($data)) {
                    return $this->success('添加项目成功!', 'lst');
                }else{
                    return $this->error('添加项目失败!');
                }
                return;
            }
   <!-- Page Body -->
            <div class="page-body">

                <div class="row">
                    <div class="col-lg-12 col-sm-12 col-xs-12">
                        <div class="widget">
                            <div class="widget-header bordered-bottom bordered-blue">
                                <span class="widget-caption">添加项目</span>
                            </div>
                            <div class="widget-body">
                                <div id="horizontal-form">
                                    <form class="form-horizontal" role="form" action="" method="post">
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">项目编号:</label>
                                            <div class="col-sm-6">
                                                <input class="form-control" id="procode" placeholder="" name="procode" required="" type="text">
                                            </div>
                                            <p class="help-block col-sm-4 red">* 必填</p>
                                        </div>
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">项目名称:</label>
                                            <div class="col-sm-6">
                                                <input class="form-control" id="proname" placeholder="" name="proname" required="" type="text">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">产品经理姓名:</label>
                                            <div class="col-sm-6">
                                                <input class="form-control" id="prm_name" placeholder="" name="prm_name" required="" type="text">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">开发经理姓名:</label>
                                            <div class="col-sm-6">
                                                <input class="form-control" id="tem_name" placeholder="" name="tem_name" required="" type="text">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">立项日期:</label>
                                            <div class="col-sm-6">
                                                <!--<input class="form-control" id="username" placeholder="" name="username" required="" type="text">-->
                                                <input type="date" class="input-text" value="" placeholder="" id="procrea" name="procrea">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">项目开始日期:</label>
                                            <div class="col-sm-6">
                                                <input type="date" class="input-text" value="" placeholder="" id="prostart" name="prostart">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">项目结束日期:</label>
                                            <div class="col-sm-6">
                                                <input type="date" class="input-text" value="" placeholder="" id="proend" name="proend">
                                            </div>
                                        </div>
  <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">前端积分:</label>
                                            <div class="col-sm-6">
                                                <input type="text" class="input-text" value="" placeholder="" id="fro_sco" name="dui_sco" onkeyup="sum(this);this.value=this.value.replace(/[^0-9.]/g,'');">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">后端积分:</label>
                                            <div class="col-sm-6">
                                                <input type="text" class="input-text" value="" placeholder="" id="bac_sco" name="dui_sco" onkeyup="sum(this);this.value=this.value.replace(/[^0-9.]/g,'');">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">UI设计积分:</label>
                                            <div class="col-sm-6">
                                                <input type="text" class="input-text" value="" placeholder="" id="dui_sco" name="dui_sco" onkeyup="sum(this);this.value=this.value.replace(/[^0-9.]/g,'');">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="group_id" class="col-sm-2 control-label no-padding-right">总积分:</label>
                                            <div class="col-sm-6">
                                                <input class="form-control" id="tot_sco" placeholder="" name="tot_sco" required="" type="text" readonly="readonly">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label for="username" class="col-sm-2 control-label no-padding-right">备注:</label>
                                            <div class="col-sm-6">
                                                <input class="form-control" id="remark" placeholder="" name="remark" required="" type="text">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <div class="col-sm-offset-2 col-sm-10">
                                                <button type="submit" class="btn btn-default">保存信息</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->
    </div>
</div>

<!--Basic Scripts-->
<script src="__PUBLIC__/style/jquery_002.js"></script>
<script src="__PUBLIC__/style/bootstrap.js"></script>
<script src="__PUBLIC__/style/jquery.js"></script>
<!--Beyond Scripts-->
<script src="__PUBLIC__/style/beyond.js"></script>

<script type="text/javascript">
    function sum(obj) {
        var fro_sco = document.getElementById("fro_sco");
        var bac_sco = document.getElementById("bac_sco");
        var dui_sco = document.getElementById("dui_sco");
        tot_sco.value = parseInt(fro_sco.value)+ parseInt(bac_sco.value)+ parseInt(dui_sco.value);
    }
</script>

</body></html>
http://www.iheyud.com/week/public/index.php/admin/project/add.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值