123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
- <meta name="author" content="siweiyong 2602812659@qq.com"/>
- <title>设置商品</title>
- <link rel="stylesheet" href="../script/lib/miniui/themes/default/miniui.css">
- <link rel="stylesheet" href="../script/lib/layui/css/layui.css" />
- <link rel="stylesheet" href="../script/lib/cashier/common.css">
- <link rel="stylesheet" href="../script/lib/layui/admin/modules/plugin/formselects/formselects.css" media="all" />
- <script src="../script/lib/jquery/jquery.min.js"></script>
- <script src="../script/lib/miniui/miniui.js"></script>
- <script src="../script/lib/layui/layui.js"></script>
- <script><{Dever::script()}></script>
- <script src="../script/dever/core.js"></script>
- </head>
- <body style="background: #F6F7F9;">
- <div class="main">
- <form class="layui-form" lay-filter="form">
- <div class="layui-row">
- <div class="main_left layui-col-xs12 layui-col-md3">
- <div class="layui-row">
- <div class="top">
- <i class="layui-icon layui-icon-app"></i>商品列表
- </div>
- <div class="left_main">
- <input id="key" class="mini-textbox" onenter="onKeyEnter" value="请输入商品名称" onclick="setVal('key')"/>
- <a class="mini-button" onclick="search()">查询</a>
- <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="addGoods()">一键添加</button>
- <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="delGoods()">一键删除</button>
- <ul id="tree1" class="mini-tree" url="<{$url}>" showTreeIcon="true" textField="name" idField="id" expandOnLoad="true" onNodeClick="onNodeClick">
- </ul>
- </div>
- </div>
- </div>
- <div class="main_right layui-col-xs12 layui-col-md9">
- <div class="layui-row">
- <div class="top">
- <label>选择门店:</label>
- <div class="layui-input-inline">
- <div><select xm-select="shop_id" xm-select-skin="normal" xm-select-search="<{$search}>" xm-select-search-type="dl" xm-select-radio="" class="update_value form-control layui-input layui-select" name="shop_id" id="shop_id" ></select></div>
- </div>
- <div class="layui-input-inline">
- <button class="layui-btn layui-btn-button" type="button" style="vertical-align: middle;margin-bottom: 2px;" onclick="setShop()">确认选择</button>
- </div>
- <div class="layui-input-inline" style="margin-left:20px">
- <input id="search_key" class="mini-textbox" value="请输入商品名称" onclick="setVal('search_key')"/>
- <a class="mini-button" onclick="searchGoods()">搜索</a>
- </div>
- </div>
- <div class="goods_list" style="height:645px;">
- <table class="layui-table">
- <thead>
- <tr>
- <th lay-data="{field:'id'}">商品编码</th>
- <th lay-data="{field:'name'}">商品名称</th>
- <th lay-data="{field:'price', edit: 'text'}">销售价(元)</th>
- <th lay-data="{field:'total', edit: 'text'}">当前库存</th>
- <th lay-data="{field:'number', edit: 'text'}">新增库存</th>
- <th lay-data="{field:'number', edit: 'text'}">起订数</th>
- <th lay-data="{field:'operation'}">操作</th>
- </tr>
- </thead>
- <tbody id="goods">
-
- </tbody>
- </table>
- </div>
- <div class="total ft16">
- 合计:【<span> 当前总库存:<i class="totalNum">0</i> </span>】【<span> 新增总库存:<i class="totalQuantity">0</i> </span>】
- </div>
- <div class="towbtn">
- <input type="button" id="settlement" value="确认设置">
- </div>
- </div>
- </div>
- </div>
- </div>
- </form>
- </div>
- <script>
- var form;
- var goods = {};
- var del_goods = {};
- var tree = {};
- layui.config(
- {
- base: '../script/lib/layui/admin/' //静态资源所在路径
- ,version: true
- }).extend(
- {
- index: 'lib/index', //主入口模块
- formSelects: 'plugin/formselects/formselects'
- }).use(['index', 'contlist', 'table', 'form', 'formSelects','layer'], function()
- {
- var table = layui.table;
- form = layui.form;
- var formSelects = layui.formSelects;
- mini.parse();
- tree = mini.get("tree1");
- for (var i in tree.data) {
- if (typeof(tree.data[i].children) == 'object') {
- if (tree.data[i].children.length > 0) {
- for (var j in tree.data[i].children) {
- if(tree.data[i].children[j].select == 1) {
- setGoods(tree.data[i].children[j]);
- }
- }
- } else if(tree.data[i].select == 1) {
- setGoods(tree.data[i]);
- }
- }
- }
- });
- $(function()
- {
- $("#settlement").click(function(){
- var url = '<{$submit}>';
- var shop_id = '<{$shop_id}>';
- layui.layer.confirm('确定进行此项设置吗?', function() {
- var goods_string = JSON.stringify(goods);
- var data = {};
- data = {shop_id:shop_id, goods:goods_string};
- $.post(url, data, function(t) {
- t = JSON.parse(t);
- if (t.status == 1) {
- layui.layer.alert('商品设置成功', function(index){
- if (t.data == 'refer') {
- history.back();
- } else {
- location.href = t.data;
- }
- layer.close(index);
- });
- } else {
- layui.layer.alert(t.msg);
- }
- });
- });
- })
- $("#goods").on("keyup", ".goods_num", function() {
- var num = parseFloat($(this).val());
- if (num < 0) {
- num = 0;
- $(this).val(0);
- }
- var id = $(this).parent().attr('value');
- goods[id].num = num;
- setTotal();
- });
- $("#goods").on("keyup", ".goods_min", function() {
- var min = parseFloat($(this).val());
- if (min < 0) {
- min = 1;
- $(this).val(1);
- }
- var id = $(this).parent().attr('value');
- goods[id].min = min;
- setTotal();
- });
- })
- function search()
- {
- var key = mini.get("key").getValue();
- if (key == "") {
- tree.clearFilter();
- } else {
- key = key.toLowerCase();
- tree.filter(function (node) {
- var name = node.name ? node.name.toLowerCase() : "";
- if (name.indexOf(key) != -1) {
- return true;
- }
- });
- }
- }
- function onKeyEnter(e)
- {
- search();
- }
- function onNodeClick()
- {
- var tree=mini.get("tree1");
- node=tree.getSelectedNode();
- if(node.end) {
- setGoods(node);
- }
- }
- function setVal(e)
- {
- mini.get(e).setValue('');
- }
- function searchGoods()
- {
- var key = mini.get("search_key").getValue();
- if (key == "") {
- $(".mytr").show();
- } else {
- key = key.toLowerCase();
- $(".mytr").show();
- $(".goods_name").each(function(t) {
- var name = $(this).html();
- name = name.toLowerCase();
- if (name.indexOf(key) == -1) {
- $(this).parent().hide();
- }
- });
- }
- }
- // 一键添加
- function addGoods()
- {
- var key = mini.get("key").getValue();
- if (key == '请输入商品名称') {
- key = '';
- }
- if (key) {
- key = key.toLowerCase();
- }
- for (var i in tree.data) {
- if (typeof(tree.data[i].children) == 'object') {
- if (tree.data[i].children.length > 0) {
- for (var j in tree.data[i].children) {
- if (key) {
- var name = tree.data[i].children[j].name;
- if (name.indexOf(key) != -1) {
- setGoods(tree.data[i].children[j]);
- }
- } else {
- setGoods(tree.data[i].children[j]);
- }
- }
- } else {
- if (key) {
- var name = tree.data[i].name;
- if (name.indexOf(key) != -1) {
- setGoods(tree.data[i]);
- }
- } else {
- setGoods(tree.data[i]);
- }
- }
- }
- }
- }
- // 一键删除
- function delGoods()
- {
- if (confirm('确定删除吗?')) {
- var key = mini.get("key").getValue();
- if (key == '请输入商品名称') {
- key = '';
- }
- if (key) {
- key = key.toLowerCase();
- }
- for (var i in tree.data) {
- if (typeof(tree.data[i].children) == 'object') {
- if (tree.data[i].children.length > 0) {
- for (var j in tree.data[i].children) {
- if (key) {
- var name = tree.data[i].children[j].name;
- if (name.indexOf(key) != -1) {
- unsetGoods(tree.data[i].children[j]);
- }
- } else {
- unsetGoods(tree.data[i].children[j]);
- }
- }
- } else {
- if (key) {
- var name = tree.data[i].name;
- if (name.indexOf(key) != -1) {
- unsetGoods(tree.data[i]);
- }
- } else {
- unsetGoods(tree.data[i]);
- }
- }
- }
- }
- setTotal();
- }
- }
- function unsetGoods(node)
- {
- if (node.id) {
- if (goods[node.id]) {
- goods[node.id].del = 2;
- goods[node.id].num = 0;
- goods[node.id].total = 0;
- get(node.id).remove();
- }
- }
- }
- function setGoods(node)
- {
- if (node.id) {
- var key = node.id;
- if (!goods[key] || (goods[key] && goods[key].del == 2)) {
- goods[key] = node;
- goods[key].price = parseFloat(goods[key].price);
- goods[key].price_type = parseInt(goods[key].price_type);
- goods[key].total = parseFloat(goods[key].total);
- goods[key].min = goods[key].min ? parseFloat(goods[key].min) : 1;
- goods[key].num = 0;
- goods[key].del = 1;
- create(node);
- setTotal();
- } else if(node.price_type < 4) {
- add(key);
- }
- }
- }
- function get(key)
- {
- return $('#goods_' + key);
- }
- function create(node)
- {
- if (!get(node.id).length) {
- var select = '';
- if (node.price_type < 3) {
- select = '<select name="goods_price_template[]" class="goods_price_template" style="width: 120px;margin: 10px;" onchange="setPrice($(this), \''+node.id+'\')" lay-ignore>';
- var l = node.price_template.length;
- var i = 0;
- select += '<option value="0_'+node.price+'_1" selected>默认价格模板</option>';
- var selected = '';
- for (i = 0; i < l; i=i+1) {
- var id = node.price_template[i].id;
- var price = node.price_template[i].price_sell;
- var price_num = node.price_template[i].price_num;
- if (node.price_template_sku && node.price_template_sku[id]) {
- price = node.price_template_sku[id].price_sell;
- price_num = node.price_template_sku[id].price_num;
- }
- if (price == 'null' || price == null || !price) {
- price = node.price;
- }
- selected = '';
- if (node.price_template_id == id) {
- selected = 'selected';
- }
- select += '<option value="'+id+'_'+price+'_'+price_num+'" '+selected+'>'+node.price_template[i].name+'</option>';
- }
- select += '</select>';
- }
- var addtr = '<tr class="mytr" id="goods_'+node.id+'">';
- addtr += '<td class="goods_id">'+node.id+'</td>';
- addtr += '<td class="goods_name">'+node.name+'</td>';
- addtr += '<td class="goods_price"><span>'+node.price+'元</span>'+select+'</td>';
- addtr += '<td class="goods_total">'+node.total+'</td>';
- if (node.price_type == 4) {
- addtr += '<td>组合商品无法设置库存</td>';
- } else {
- addtr += '<td><div class="jiajian" value='+node.id+'><span class="jian" onclick="dec(\''+node.id+'\')">-</span><input type="text" value="'+node.num+'" class="goods_num"><span class="jia" onclick="add(\''+node.id+'\')">+</span></div></td>';
- }
- addtr += '<td><div class="jiajian" value='+node.id+'><span class="jian" onclick="decMin(\''+node.id+'\')">-</span><input type="text" value="'+node.min+'" class="goods_min"><span class="jia" onclick="addMin(\''+node.id+'\')">+</span></div></td>';
-
- var shop_id = '<{$shop_id}>';
- if (node.total <= 0 || shop_id == 3) {
- addtr += '<td><a class="delete_btn" onclick="del(\''+node.id+'\')">删除</a></td>';
- } else {
- addtr += '<td></td>';
- }
-
- addtr += '</tr>';
- $("#goods").append(addtr);
- form.render();
- $('.goods_price_template').change();
- }
- }
- function setPrice(e, id)
- {
- var val = e.val().split('_');
- goods[id].price_template_id = val[0];
- e.parent().find('span').html(val[1] + '元');
- //goods[id].min = val[2];
- //e.parent().parent().find('.goods_min').val(val[2]);
- }
- function add(id)
- {
- goods[id].num += 1;
- get(id).find('.goods_num').val(goods[id].num);
- setTotal();
- }
-
- function dec(id)
- {
- goods[id].num -= 1;
- if (goods[id].num < 1) {
- goods[id].num = 0;
- }
- get(id).find('.goods_num').val(goods[id].num);
- setTotal();
- }
- function addMin(id)
- {
- goods[id].min += 1;
- get(id).find('.goods_min').val(goods[id].min);
- setTotal();
- }
-
- function decMin(id)
- {
- goods[id].min -= 1;
- if (goods[id].min < 1) {
- goods[id].min = 0;
- }
- get(id).find('.goods_min').val(goods[id].min);
- setTotal();
- }
- function del(id)
- {
- //if (confirm('确定删除吗?')) {
- goods[id].del = 2;
- goods[id].num = 0;
- get(id).remove();
- setTotal();
- //}
- }
- function setTotal()
- {
- var cash = 0;
- var num = 0;
- var total = 0;
- for (var i in goods) {
- num += goods[i].num;
- total += goods[i].total;
- }
- $(".totalQuantity").html(num);
- $(".totalNum").html(total);
- }
- function setShop()
- {
- var shop_id = $('.xm-select-parent[fs_id="shop_id"] span[fsw="xm-select"]').attr('value');
- if (!shop_id) {
- layui.layer.alert('请选择门店');
- return;
- }
- layui.layer.confirm('确定切换门店吗?切换后现在选择的商品都将清空', function() {
- location.href = '<{$host}>&id=' + shop_id;
- });
- }
- </script>
- </body>
- </html>
|