自此home.html首页内容基本结束,market商城页面开始编写
1、新建数据表axf_foodtype
App/models.py
class FoodType(models.Model):
typeid = models.IntegerField(default=1)
typenames = models.CharField(max_length=32)
childtypenames = models.CharField(max_length=255)
typesort =models.IntegerField(default=1)
class meta:
db_table = 'axf_foodtype'
迁移:
#生成迁移文件:
python manage.py makemigrations
#执行迁移文件:
python manage.py migrate
插入数据:
INSERT INTO `axf`.`app_foodtype`(`id`, `typeid`, `typenames`, `childtypenames`, `typesort`) VALUES (1, 1001, '热销榜', '全部分类:0', 1);
INSERT INTO `axf`.`app_foodtype`(`id`, `typeid`, `typenames`, `childtypenames`, `typesort`) VALUES (2, 1002, '新品尝鲜', '全部分类:0', 2);
INSERT INTO `axf`.`app_foodtype`(`id`, `typeid`, `typenames`, `childtypenames`, `typesort`) VALUES (3, 1003, '优选水果', '全部分类:0#进口水果:1004#国产水果:1005', 3);
INSERT INTO `axf`.`app_foodtype`(`id`, `typeid`, `typenames`, `childtypenames`, `typesort`) VALUES (4, 1006, '卤味熟食', '全部分类:0', 4);
INSERT INTO `axf`.`app_foodtype`(`id`, `typeid`, `typenames`, `childtypenames`, `typesort`) VALUES (5, 1007, '水', '全部分类:0#饮料:1008#冷热饮:1009', 5);
INSERT INTO `axf`.`app_foodtype`(`id`, `typeid`, `typenames`, `childtypenames`, `typesort`) VALUES (6, 1010, '鲜花', '全部分类:0', 6);
2、新建数据表axf_goods
App/models.py
class Goods(models.Model):
productid = models.IntegerField(default=1)
productimg = models.CharField(max_length=255)
productname = models.CharField(max_length=128)
productlongname = models.CharField(max_length=255)
isxf = models.BooleanField(default=False)
esc =models.BooleanField(default=False)
isc=models.CharField(max_length=64)
price =models.FloatField(default=0)
marketprice =models.FloatField(default=1)
categoryid = models.IntegerField(default=1)
childcid =models.IntegerField(default=1)
childcidname =models.CharField(max_length=128)
dealerid = models.IntegerField(default=1)
storenums =models.IntegerField(default=1)
productnum =models.IntegerField(default=1)
class meta:
db_table = 'axf_goods'
迁移:
python manage.py makemigrations
python manage.py migrate
插入数据:
INSERT INTO `axf`.`app_goods`(`id`, `productid`, `productimg`, `productname`, `productlongname`, `isxf`, `esc`, `isc`, `price`, `marketprice`, `categoryid`, `childcid`, `childcidname`, `dealerid`, `storenums`, `productnum`) VALUES (1, 2001, '/static/axf/img/market/冰棍.png', '冰棍,老冰棍', '好吃的冰棍', 0, 0, '20g', 1.5, 2, 2001, 2001, '饮料', 4858, 200, 4);
INSERT INTO `axf`.`app_goods`(`id`, `productid`, `productimg`, `productname`, `productlongname`, `isxf`, `esc`, `isc`, `price`, `marketprice`, `categoryid`, `childcid`, `childcidname`, `dealerid`, `storenums`, `productnum`) VALUES (2, 3001, '/static/axf/img/market/卤味猪心.png', '卤味猪心', '当天的卤味猪心', 0, 0, '1kg', 35, 38, 3001, 3001, '卤味熟食', 4858, 300, 4);
INSERT INTO `axf`.`app_goods`(`id`, `productid`, `productimg`, `productname`, `productlongname`, `isxf`, `esc`, `isc`, `price`, `marketprice`, `categoryid`, `childcid`, `childcidname`, `dealerid`, `storenums`, `productnum`) VALUES (3, 3002, '/static/axf/img/market/卤味鸡腿.png', '卤味鸡腿', '手拿着就可以吃', 0, 0, '0.5kg', 10, 15, 4001, 4001, '卤味熟食', 4858, 300, 4);
3、商城页面搭建
路由:
视图:
def market(request):
return redirect(reverse('axf:market_with_paprams',kwargs={
"typeid": 1001
}))
def market_with_paprams(request,typeid):
foodtypes =FoodType.objects.all()
goods_list=Goods.objects.filter(categoryid=typeid)
data = {
"title": "商城",
"foodtypes":foodtypes,
"goods_list":goods_list,
"typeid":int(typeid),
}
return render(request, 'main/market.html', context=data)
market.html
{% extends 'base_main.html' %}
{% load static %}
{% block ext_css %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'axf/main/css/market.css' %}">
{% endblock %}
{% block content %}
<div id="market">
{#左边的导航#}
<aside>
<ul>
{% for foodtype in foodtypes %}
<li>
<a href="{% url 'axf:market_with_paprams' typeid=foodtype.typeid %}">{{ foodtype.typenames }}</a>
{% ifequal foodtype.typeid typeid %}
<span class="yellowSlide"></span>
{% endifequal %}
</li>
{% endfor %}
</ul>
</aside>
<section>
<nav>
<ul>
<li>
<div></div>
<span>全部分类<span class="glyphicon glyphicon-chevron-down"></span></span></li>
<li>
<div></div>
<span>综合排序<span class="glyphicon glyphicon-chevron-down"></span></span></li>
</ul>
</nav>
<menu>
<ul>
{% for goods in goods_list %}
<li><a href="#">
<img src="{{ goods.productimg }}" alt="{{ goods.productlongname }}">
<div class="shoppingInfo">
<h6>{{ goods.productlongname }}</h6>
<p class="detailTag"><span>精选</span><span></span></p>
<p class="unit">{{ goods.isc }}</p>
<p class="price"><span>{{ goods.price }}</span><s>{{ goods.marketprice }}</s></p>
</div>
</a></li>
{% endfor %}
</ul>
</menu>
</section>
</div>
{% endblock %}
market.css
/*底部图标和文字控制*/
footer .market span {
background: url(/static/img/market_selected.png) no-repeat;
background-size: 0.513889rem;
}
footer .market dd {
color: orange;
}
/*商城页面的数据容器*/
#market {
padding: 1.5rem 0;
overflow: auto;
height: 100%;
width: 100%;
position: fixed;
}
/*左边的导航*/
aside {
width: 2.5rem;
float: left;
position: relative;
background: #fafafa;
overflow: auto;
height: 100%;
}
aside ul {
background: #fafafa;
}
aside ul li {
list-style: none;
text-align: center;
border-bottom: 0.04rem solid #e0e0e0;
line-height: 1.35rem;
width: 2.25rem;
position: relative;
z-index: +1;
}
aside ul li a {
display: block;
font-size: 0.35rem;
color: grey;
z-index: +1;
}
.yellowSlide {
background: yellow;
width: 0.1rem;
height: 0.7rem;
position: absolute;
left: 0;
top: 0.3rem;
display: block;
}
/*右侧商品数据内容*/
div > section {
background-color: #fafafa;
width: 7.5rem;
float: right;
position: relative;
height: 100%;
overflow: auto;
padding: 1rem 0 0;
clear: none;
}
/*右侧顶部导航*/
nav {
top: 1.58rem;
right: 0;
position: fixed;
z-index: +1;
background: white;
border-bottom: 0.04rem solid #e0e0e0;
}
nav ul {
display: flex;
background: white;
height: 0.7rem;
}
/*.asss {*/
/* display: table-cell;*/
/* vertical-align: middle;*/
/* width: 100%;*/
/*}*/
nav ul li {
text-align: center;
width: 3.75rem;
line-height: 0.475em;
font-size: 0.35rem;
border-right: 0.04rem solid #e0e0e0;
height: 0.5rem;
}
nav ul li:last-child {
border: none;
}
nav ul li div {
height: 0.1rem;
}
/*分类按钮 全部分类 综合安排*/
nav ul li > span {
width: 100%;
height: 1rem;
display: block;
text-align: center;
}
/*商品数据*/
section menu {
height: 100%;
position: relative;
overflow: auto;
}
section menu ul {
position: relative;
}
section menu ul li {
background: white;
border-bottom: 0.04rem solid #e0e0e0;
position: relative;
}
section menu ul li a {
display: block;
height: 3rem;
}
section menu ul li a img {
display: block;
width: 2.8rem;
float: left;
}
/*商品详细信息*/
.shoppingInfo {
width: 4.6rem;
float: right;
font-size: 0.35rem;
}
.shoppingInfo h6 {
margin: 0.1rem 0 0;
overflow: hidden;
text-overflow: ellipsis;
height: 0.5rem;
white-space: normal;
font-weight: 500;
font-size: 0.38rem;
line-height: normal;
color: black;
}
.detailTag {
margin: 0.2rem 0;
}
.detailTag span {
border: 0.05rem solid red;
border-radius: 0.15rem;
padding: 0 0.1rem;
color: white;
background: red;
margin-right: 0.3rem;
}
.detailTag span:first-child {
color: red;
background: white;
}
.unit {
color: grey;
position: absolute;
bottom: 1rem;
}
.price {
position: absolute;
bottom: 0.15rem;
font-weight: 200;
margin: 0.2rem 0;
}
.price > span {
padding: 0 0.35rem 0 0;
color: red;
}
.price > span:before {
content: "¥";
color: red;
}
.price > s {
color: grey;
}
.price > s:before {
content: "¥";
color: grey;
}
li > section {
position: absolute;
right: 0.4rem;
}
访问:
4、“全部分类、综合排序”的点击事件
market.html添加内容
<div id="all_cer">
<div>
<a href="#">
<button class="btn btn-success">全部分类</button>
</a>
<a href="#">
<button class="btn btn-default">优选水果</button>
</a>
</div>
</div>
<div id="sort_cer">
<div>
<a href="#">
<button class="btn btn-success">综合排序</button>
</a>
<a href="#">
<button class="btn btn-default">价格降序</button>
</a>
</div>
</div>
market.css添加内容
/*添加到购物车*/
li > section {
position: absolute;
right: 0.4rem;
bottom: 0.4rem;
height: 0.75rem;
border-radius: 1rem;
}
section > button {
background: white;
border: 1px solid orange;
border-radius: 1111px;
color: red;
display: inline-block;
text-align: center;
line-height: 0.5rem;
font-weight: 900;
width: 0.5rem;
height: 0.5rem;
}
li > section > span {
display: inline-block;
width: 0.4rem;
text-align: center;
line-height: 0.4rem;
}
.subShopping {
font-size: 0.8rem;
font-weight: 100;
}
section menu > div {
position: fixed;
top: 2.3rem;
left: 2.55rem;
width: 7.45rem;
height: 100%;
background: rgba(0, 0, 0, 0.5);
color: grey;
display: none;
}
section menu > div > div {
background: white;
padding-bottom: 0.3rem;
}
section menu > div > div > a > button {
border: 0.04rem solid #e0e0e0;
padding: 0.1rem 0.2rem;
margin-left: 0.3rem;
border-radius: 0.2rem;
font-size: 0.375rem;
display: inline-block;
margin-top: 0.3rem;
}
maiket.js
// 点击事件的绑定
$(function () {
$("#all_types").click(function () {
// “所有类型” 点击事件
var $all_cer = $("#all_cer");
$all_cer.show();
})
$("#sort_rule").click(function () {
// “综合排序” 点击事件
var $sort_cer = $("#sort_cer");
$sort_cer.slideDown(0);
})
})
访问: