<table class="table table-bordered" style="margin-bottom: 0;">
<tr>
<th class="text-center" style="width: 50px;">选择</th>
<th>店铺</th>
<th class="text-center">产品主图</th>
<th>产品名称</th>
<th class="text-center">价格</th>
<th class="text-center" style="width: 80px;">是否上架</th>
<th class="text-center" style="width: 80px;">是否新品</th>
<th class="text-center" style="width: 80px;">是否推荐</th>
<th class="text-center" style="width: 80px;">是否锁定</th>
<th class="text-center" style="width: 130px;">上架时间</th>
<th class="text-center" style="width: 100px;">操作</th>
</tr>
{% for product in recList %}
<tr>
<td class="text-center">
<input type="checkbox" product_id="{{ product.id }}">
</td>
<td><a href="/super_manage/show_shop/?shop_id={{ product.shop_company.id }}" target="_blank">{{ product.shop_company.name }}</a></td>
<td class="text-center">
<img src="{{ MEDIA_URL }}{{ product.cover_img }}!p3" alt="{{ product.name }}" style="height: 50px;">
</td>
<td>{{ product.name }}</td>
{# {% if product.price_range %}#}
<td class="text-center">{{ product.get_price_range }}</td>
<td class="text-center">
{% if product.is_listing %}
<span style="color: green;">是</span>
{% else %}
<span style="color: grey;">否</span>
{% endif %}
</td>
<td class="text-center">
{% if product.is_new %}
<span style="color: green;">是</span>
{% else %}
<span style="color: grey;">否</span>
{% endif %}
</td>
<td class="text-center">
{% if product.is_recommend %}
<span style="color: green;">是</span>
{% else %}
<span style="color: grey;">否</span>
{% endif %}
</td>
<td class="text-center">
{% if product.is_locked %}
<span style="color: red;">是</span>
{% else %}
<span style="color: grey;">否</span>
{% endif %}
</td>
<td class="text-center">
{{ product.create_time|date:'Y-m-d H:i' }}
</td>
<td class="text-center">
<a href="/super_manage/product_view/{{ product.id }}/" target="_blank">详情</a>
</td>
</tr>
{% endfor %}
</table>
div style="margin-top: 10px;float: left;">
<label for="chk_all">
<input type="checkbox" id="chk_all"> 全选
</label>
<a href="javascript:;" class="btn btn-success" onclick="batch_product_listing(1)">批量上架</a>
<a href="javascript:;" class="btn btn-success" onclick="batch_product_listing(0)">批量下架</a>
<span class="split-line">|</span>
<a href="javascript:;" class="btn btn-success" onclick="batch_product_lock(1)">锁定</a>
<a href="javascript:;" class="btn btn-success" onclick="batch_product_lock(0)">取消锁定</a>
<span class="split-line">|</span>
<div style="width: auto;display: inline-block;">
<input type="text" class="form-control" id="id_global_category_name" style="width: auto;display: inline-block;" readonly
value="{{ product.global_category.name }}" placeholder="达卡类目">
<input type="hidden" class="form-control" id="id_global_category_id" name="global_category_id"
value="{{ product.global_category_id|default_if_none:'' }}">
<div id="treeDemo" class="ztree" style="width: 163px;"></div>
<a href="javascript:;" id="id_a_choose" onclick='$("#treeDemo").show();'>选择</a>
</div>
<a href="javascript:;" class="btn btn-success" onclick="batch_update_global_category()">更改类目</a>
</div>
$(function () {
$("#nav_order_manage").addClass("active");
$("#nav_productslist").addClass("active");
$("#chk_all").click(function () {
$("input[type=checkbox][product_id]").prop("checked", $(this).prop("checked"));
});
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
$.fn.zTree.getZTreeObj("treeDemo").expandAll(true);
{% if product.global_category_id %}
var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
var node = treeObj.getNodeByParam("id", {{ product.global_category_id }}, null);
treeObj.selectNode(node);
{% endif %}
$("#id_global_category_name").focus(function () {
$("#treeDemo").show();
});
$(document).click(function (event) {
if (event.target.id != "id_global_category_name" && event.target.id != "treeDemo"
&& event.target.id != "id_a_choose" && $(event.target).parents("#treeDemo").length == 0) {
$("#treeDemo").hide();
}
});
});
unction get_select_product_ids() {
var product_ids = [];
$("input[type=checkbox][product_id]:checked").each(function () {
product_ids.push($(this).attr("product_id"));
});
return product_ids;
}
function batch_product_listing(is_listing) {
var product_ids = get_select_product_ids();
if (product_ids.length == 0) {
alert("请选选择产品");
return;
}
var msg = is_listing ? '批量上架' : '批量下架';
var ok = confirm("您确定要" + msg + "选择的产品吗?");
if (ok) {
$.ajax({
url: "/super_manage/batch_product_listing/",
data: {
csrfmiddlewaretoken: "{{csrf_token}}",
product_ids: product_ids,
is_listing: is_listing
},
type: "POST",
dataType: "json",
success: function (result) {
if (result['is_success']) {
alert(msg + "成功!");
window.location.href = "/super_manage/product_list/";
} else {
alert(msg + "失败!" + result['error_msg']);
}
}
});
}
}