123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- <meta name="renderer" content="webkit">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
- <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
- <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
- <link rel="stylesheet" type="text/css" href="../../layuiadmin/style/formSelects-v4.css"/>
- <style type="text/css">
- .table-overlay .layui-table-view,
- .table-overlay .layui-table-header,
- .table-overlay .layui-table-box,
- .table-overlay .layui-table-body{overflow: visible;}
- .table-overlay .layui-table-cell{height: auto; overflow: visible;}
- #department_employee_selecter dl{max-height: 250px;}
- </style>
- </head>
- <body>
- <div class="layui-fluid">
- <div class="layui-card">
- <div class="layui-card-body" pad15>
- <div class="layui-row layui-col-space15">
- <div class="layui-col-md12">
- <form class="layui-form" action="" lay-filter="component-form-element">
- <div class="layui-row layui-col-space10">
- <div class="layui-col-sm6">
- <label class="layui-form-label"><font color='red' size="4">*</font>仓别:</label>
- <div class="layui-input-block">
- <select id="id_warehouse" name="warehouse" lay-filter="onWarehouseChange"
- lay-verify="required">
- <option value=""></option>
- </select>
- </div>
- </div>
- <div class="layui-col-sm6">
- <label class="layui-form-label"><font color='red' size="4">*</font>经办人:</label>
- <div class="layui-input-block" id="department_employee_selecter">
- <select name="agent_user" xm-select="selectDepartment" xm-select-radio lay-verify="required">
- </select>
- </div>
- </div>
- </div>
- <div class="layui-row layui-col-space10">
- <div class="layui-col-md6">
- <label class="layui-form-label">客户:</label>
- <div class="layui-input-block">
- <div>
- <div class="layui-col-xs8">
- <input id='id_customer' name="customer_text" type="text" autocomplete="off" class="layui-input"/>
- </div>
- <div class="layui-col-xs4">
- <button id="btn_add_customer" class="layui-btn layui-btn-warm" type="button" data-permission="customer.add_customer"><i class="layui-icon layui-icon-add-circle"></i>新建</button>
- </div>
- <div style="clear: both;"></div>
- </div>
- <div style="line-height: 37px;">
- <label id="customer_name" style="margin-left: 10px;">姓名</label>
- <label id="mobile" style="margin-left: 10px;">电话</label>
- </div>
- <div style="clear: both;"></div>
- </div>
- </div>
- <div class="layui-col-md6">
- <label class="layui-form-label">销售单:</label>
- <div class="layui-input-block">
- <div>
- <input id='id_sale_order' name="sale_order_no" type="text" autocomplete="off" class="layui-input"/>
- </div>
- <div class="layui-col-xs12 layui-col-sm7" style="line-height: 37px;">
- <label id="no" style="margin-left: 10px;">单号</label>
- </div>
- </div>
- </div>
- </div>
- <div class="layui-row layui-col-space10">
- <div class="layui-col-xs12 layui-col-sm12">
- <label class="layui-form-label">备注:</label>
- <div class="layui-input-block">
- <input id="notes" type="text" name="notes" autocomplete="off" class="layui-input">
- </div>
- </div>
- </div>
- <fieldset class="layui-elem-field layui-field-title">
- <legend>成品明细<button type="button" id="goods-btn-add" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button></legend>
- </fieldset>
- <div class="layui-row layui-col-space10">
- <div id="goodsDataTable" class="table-overlay">
- <table id="goods_layTable" lay-filter="goods_layTable" class="layui-hide"></table>
- </div>
- </div>
- <button class="layui-btn" id="goods-deliver-submit" lay-submit lay-filter="component-form-element" style="display: none">确定</button>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- <script src="../../layuiadmin/layui/layui.js"></script>
- <script>
- layui.link('../../../layuiadmin/style/autocomplete.css');
- layui.config({
- base: '../../../layuiadmin/' //静态资源所在路径
- }).extend({
- index: 'lib/index', //主入口模块
- utils: 'utils',
- formSelects: 'formSelects-v4'
- }).use(['index', 'form', 'table', 'utils', 'laydate', 'autocomplete','formSelects'], function() {
- var $ = layui.$;
- var admin = layui.admin;
- var utils = layui.utils;
- var autocomplete = layui.autocomplete;
- var form = layui.form;
- var table = layui.table;
- var formSelects = layui.formSelects;
- var id = layui.view.getParameterByName('id');
- var order_id = layui.view.getParameterByName('order_id');
- var _customer_id = '';
- var _sale_order_id = '';
- var warehouse_isload = false;
- var other_isload = false;
- var data_isload = false;
- autocomplete.render({
- elem:$('#id_customer'),
- url:'/customer/customer/select/',
- template_val:'{{d.name}}-{{d.mobile}}',
- template_txt:'{{d.name}} <span class=\'layui-badge layui-bg-gray\'>{{d.mobile}}</span>',
- onselect: function (resp) {
- fillCustomerData(resp);
- }
- });
- autocomplete.render({
- elem:$('#id_sale_order'),
- url:'/order/sale_order/select/',
- template_val:'{{d.no}}',
- template_txt:'{{d.no}}',
- onselect: function (resp) {
- resp.customer_id = resp.customer;
- resp.name = resp.customer_name;
- resp.mobile = resp.customer_tel;
- fillSaleOrderData(resp);
- }
- });
- function fillSaleOrderData(data) {
- fillCustomerData(data);
- _customer_id = data.customer_id;
- $('#no').html('单号:' + data.no);
- $('#id_sale_order').val(data.no);
- _sale_order_id = data.id;
- loadSaleData(data.id);
- }
- function fillCustomerData(data){
- $('#customer_name').html('姓名:' + data.name);
- $('#mobile').html('电话:' + data.mobile);
- $('#id_customer').val(data.name + '-' + data.mobile);
- _customer_id = data.id;
- }
- admin.req({
- url: '/warehouse/select/?type=2',
- done: function(res){
- var data = res.data;
- var warehouse_node = $('#id_warehouse');
- for (var i in data) {
- var pid = data[i].id;
- var value = data[i].value;
- warehouse_node.append("<option value='"+pid+"'>"+value+"</option>");
- }
- form.render();
- warehouse_isload = true;
- loadData();// 赋值完成后调用传值
- }
- });
- formSelects.render('selectDepartment',{
- template:function(id, item) {
- if (item.value.split('_')[0] == 'employee') {
- return "<span style='color:red;'>"+item.name+"</span>";
- }
- return item.name;
- }
- });
- formSelects.value('selectDepartment', []);
- admin.req({
- url: '/account/employee/tree/'
- ,done: function(res){
- formSelects.data('selectDepartment', 'local', {
- arr: res.data,
- tree: {
- //在点击节点的时候, 如果没有子级数据, 会触发此事件
- nextClick: function(id, item, callback){
- return false;
- },
- }
- });
- other_isload = true;
- loadData();
- }
- });
- var loadData = function () {
- if (!(warehouse_isload && other_isload)) { // 要等下拉框渲染完成后才能赋值
- return;
- }
- if (data_isload) {
- return;
- }
- data_isload = true;
- if(id){
- loadeidtData()
- }
- if(order_id) {
- var data = JSON.parse(JSON.stringify(parent.layui.table.editdata));
- data.customer_id = data.customer;
- data.name = data.customer_name;
- data.mobile = data.customer_tel;
- fillSaleOrderData(data);
- }
- };
- var loadSaleData = function (sale_id) {
- var warehouse = $('#id_warehouse').val();
- admin.req({
- url: '/order/sale_order/detail/?id=' + sale_id + '&warehouse_id=' + warehouse,
- done: function (res) {
- var items_data = res.data.items_data;
- var roldData = [];
- var k=0;
- if (roldData.length > 0){
- k = roldData[roldData.length-1].num;
- }
- for (var n in items_data) {
- var item_data = items_data[n];
- k = k + 1;
- if (!warehouse) {
- item_data.record_data = ''
- }
- var newRow = {
- id: item_data.product_id,
- product_base: item_data.product_id,
- name: item_data.name,
- model: item_data.model,
- price: item_data.price,
- total_cost: '',
- count: item_data.count,
- unit: item_data.unit,
- notes: '',
- record_data: item_data.record_data,
- entry_no: '',
- num: k
- };
- roldData.push(newRow);
- }
- goods_tableIns.reload({
- data: roldData
- });
- updateCost();
- }
- });
- };
- var loadeidtData = function () {
- var agent_user = '';
- if (id) {
- var data = JSON.parse(JSON.stringify(parent.layui.table.editdata));
- agent_user = data.agent_user;
- form.val("component-form-element", data);
- admin.req({
- url: '/order/deliver/detail/?id=' + id,
- done: function (res) {
- var main_data = res.data.main_data;
- var items_data = res.data.items_data;
- var roldData = table.cache[goods_layTable];
- if (main_data.customer_id){
- var customer_data = {
- 'name':main_data.customer_name,
- 'id':main_data.customer_id,
- 'mobile':main_data.customer_tel
- };
- fillCustomerData(customer_data);
- }
- if(data.sale_order_no){
- $('#id_sale_order').val(data.sale_order_no);
- $('#no').html('单号:' + data.sale_order_no);
- }
- var k=0;
- if (roldData.length > 0){
- k = roldData[roldData.length-1].num;
- }
- _sale_order_id = res.data.main_data.sale_order_id;
- for (var i in items_data) {
- k = k + 1;
- var newRow = {
- id: items_data[i].id,
- product_base: items_data[i].product_base,
- name: items_data[i].name,
- model: items_data[i].model,
- price: items_data[i].price,
- total_cost: items_data[i].total_cost,
- count: items_data[i].count,
- unit: items_data[i].unit,
- notes: items_data[i].notes,
- record_data: items_data[i].record_data,
- entry_no: items_data[i].entry_no,
- num: k
- };
- roldData.push(newRow);
- }
- goods_tableIns.reload({
- data: roldData
- });
- updateCost();
- }
- })
- }
- if (agent_user) {
- agent_user = 'employee_'+agent_user;
- }
- formSelects.value('selectDepartment', [agent_user]);
- };
- var goods_tbWidth = $("#goodsDataTable").width();
- var goods_layTable = "goods_layTable";
- var goods_tableIns = table.render({
- elem: '#goods_layTable',
- id: goods_layTable,
- data: [],
- width: goods_tbWidth,
- page: false,
- limit: 1000,
- loading: true,
- even: true, //不开启隔行背景
- cols: [[
- {title: '序号', type: 'numbers'},
- {field: 'name', title: '名称', width: 100},
- {field: 'model', title: '代码', width: 100},
- {field: 'unit', title: '单位', width: 120},
- {field: 'count', title: '数量', width: 100, templet: function (d) {
- return '<input id="count' + d.num + '" value="' + d.count + '" type="text" onchange="onCountChange('+ d.id +','+ d.num +')" lay-verify="required|numberGtZ" autocomplete="off" class="layui-input">';
- }},
- {field: 'price', title: '单价', width: 100, templet: function (d) {
- return '<input id="price' + d.num + '" value="' + d.price + '" type="text" lay-verify="required|numberGeZ" autocomplete="off" class="layui-input">';
- }},
- {field: 'total_cost', title: '成本合计', width: 100, templet: function (d) {
- return '<span id="total_cost' + d.num + '">'+ d.total_cost +'</span>';
- }},
- {field: 'notes', title: '备注', width: 200, templet: function (d) {
- return '<input id="notes' + d.num + '" value="' + d.notes + '" type="text" autocomplete="off" class="layui-input">';
- }},
- {field: 'entry_no', title: '入库单号', width: 200,templet: function (d) {
- var options = utils.renderSelectOptions(d.record_data, {
- valueField: "stock_id",
- textField: "no",
- selectedValue: d.entry_no
- });
- return '<select id="no'+d.num+'" lay-filter="entryno" lay-verify="required"><option value="">请选择入库单</option>' + options + '</select>';
- }
- },
- {field: 'surplus_count', title: '库存数量', width: 100, templet: function (d) {
- return '<span id="surplus_count' + d.num + '"></span>';
- }},
- {field: 'entry_price', title: '成本价', width: 100, templet: function (d) {
- return '<span id="entry_price' + d.num + '"></span>';
- }},
- {field: 'entry_notes', title: '入库单备注', width: 100, templet: function (d) {
- return '<span id="entry_notes' + d.num + '"></span>';
- }},
- {
- field: 'id', title: '操作', minWidth: 120, templet: function (d) {
- return '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" lay-id="' + d.num + '"><i class="layui-icon layui-icon-delete"></i>删除</a>';
- }
- }
- ]],
- done: function (res, curr, count) {
- //viewObj.tbData = res.data;
- }
- });
- table.on('tool(goods_layTable)', function (obj) {
- var data = obj.data;
- var event = obj.event;
- switch (event) {
- case "del":
- obj.del();
- layer.msg('删除成功', {icon: 6});
- break;
- }
- });
- form.on('select(entryno)', function (data) {
- var num = data.elem.id;
- num = num.match(/\d+/g)[0];
- var stock_id = data.value;
- updateTotalCost(num, stock_id);
- updateEntry(num, stock_id)
- });
- function updateEntry(num, stock_id){
- if(!stock_id || !num || isNaN(num) || isNaN(stock_id) ){
- $('#entry_notes' + num).html('');
- $('#surplus_count' + num).html('');
- $('#entry_price' + num).html('');
- return;
- }
- var items = getgoodsData();
- for (var n in items){
- if (items[n].num == num){
- var record_data = items[n].record_data;
- for (var i in record_data){
- if(record_data[i].stock_id == stock_id){
- $('#entry_notes' + num).html(record_data[i].notes);
- $('#surplus_count' + num).html(record_data[i].surplus_count);
- $('#entry_price' + num).html(record_data[i].entry_price);
- break;
- }
- }
- break;
- }
- }
- }
- function updateTotalCost(num, stock_id){
- if(!stock_id || !num || isNaN(num) || isNaN(stock_id) ){
- $("#total_cost" + num).html('');
- return;
- }
- var items = getgoodsData();
- for (var n in items){
- if (items[n].num == num){
- num = items[n].num;
- var count = items[n].count;
- if(!count || isNaN(count)){
- return;
- }
- var record_data = items[n].record_data;
- for (var i in record_data){
- if(record_data[i].stock_id == stock_id){
- var total_cost = record_data[i].entry_price * count;
- $('#total_cost' + num).html(total_cost.toFixed(4));
- break;
- }
- }
- break;
- }
- }
- }
- var getgoodsData = function () {
- var rows = table.cache[goods_layTable];
- var data = [];
- for (var n in rows) {
- if (rows[n] == false) {
- continue;
- }
- var count = $('#count'+rows[n].num).val();
- var price = $('#price'+rows[n].num).val();
- var notes = $('#notes'+rows[n].num).val();
- var warehouse_stockrecord = $('#no'+rows[n].num).val();
- var total_cost = $('#total_cost'+rows[n].num).html();
- var item = {
- product_base: rows[n].product_base,
- id: rows[n].id,
- name: rows[n].name,
- model: rows[n].model,
- unit: rows[n].unit,
- count: count,
- price: price,
- notes: notes,
- num: rows[n].num,
- entry_no:warehouse_stockrecord,
- record_data: rows[n].record_data,
- warehouse_stockrecord: warehouse_stockrecord,
- total_cost: total_cost
- };
- data.push(item);
- }
- return data;
- };
- $('#btn_add_customer').on('click', function(){
- layer.open({
- type: 2,
- title: '添加客户',
- shadeClose: false,
- area: ['95%', '95%'],
- btn: ['保存', '取消'],
- yes: function(index, dom){
- layui.onSubmitChild = function (data) {
- layer.close(index);
- fillCustomerData(data)
- };
- layui.submitChild();
- },
- btn2: function(index, layero){
- layer.close(index);//关闭当前按钮
- },
- content:'../customer/customer_edit.html?add=true'
- });
- });
- form.on('submit(component-form-element)', function (data) {
- var items = getgoodsData();
- if (items.length == 0) {
- layer.msg('请添加成品!', {icon: 5});
- return false;
- }
- var agent_user = formSelects.value('selectDepartment', 'val')[0];
- if (agent_user.split('_')[0] == 'employee') {
- agent_user = agent_user.split('_')[1];
- } else {
- layer.msg('经办人只能选择红色的人员项!', {icon: 5});
- return false;
- }
- data.field.agent_user = agent_user;
- if (order_id){
- data.field.sale_order = order_id;
- }
- data.field.customer = _customer_id;
- data.field.sale_order = _sale_order_id;
- admin.req({
- url: '/order/deliver/save/?id=' + id
- , data: {main: JSON.stringify(data.field), item: JSON.stringify(items)}
- , type: 'post'
- , done: function (res) {
- parent.layui.onSubmitChild(res.data);
- }
- });
- return false;
- });
- $('#goods-btn-add').on('click', function () {
- warehouse = $('#id_warehouse').val();
- layer.open({
- type: 2,
- title: '添加成品',
- area: ['90%', '98%'],
- btn: ['确定', '取消'],
- yes: function (index, dom) {
- layui.onSubmitChild = function (data) {
- if(data.length > 0) {
- layer.msg('添加成功!', {icon: 6});
- } else {
- layer.msg('请先选择记录!');
- }
- // layer.close(index);
- var oldData = getgoodsData();
- var k=0;
- if (oldData.length > 0){
- k = oldData[oldData.length-1].num;
- }
- for (var i in data) {
- k = k + 1;
- var newRow = {
- id: data[i].product_id,
- product_base:data[i].product_id,
- name: data[i].name,
- model: data[i].model,
- unit: data[i].unit,
- record_data: data[i].record_data,
- num: k,
- count:'',
- price:'',
- total_cost:'',
- notes:''
- };
- oldData.push(newRow);
- }
- goods_tableIns.reload({
- data: oldData
- });
- updateCost();
- };
- layui.submitChild();
- },
- btn2: function (index, layero) {
- layer.close(index);//关闭当前按钮
- },
- content: '../goods/search_goods_item.html?warehouse=' + warehouse
- });
- });
- form.on('select(onWarehouseChange)',function(){
- updateCost();
- updateEnryno();
- });
- function updateEnryno(){
- var warehouse = $("#id_warehouse").val();
- var data = getgoodsData();
- var products = [];
- for(var i in data) {
- data[i].record_data = [];
- }
- goods_tableIns.reload({data: data});
- if (data.length == 0){
- return;
- }
- for(var i in data){
- $('#total_cost' + data[i].num).html('');
- var product_id = data[i].id;
- var num = data[i].num;
- var item = {
- product_id: product_id,
- index: num
- };
- products.push(item);
- }
- if(!warehouse){
- return;
- }
- admin.req({
- url: '/warehouse/select/stocks/?warehouse=' + warehouse
- , data: {products:JSON.stringify(products)}
- , type: 'post'
- ,done: function(res){
- var result_data = res.data;
- var table_data = getgoodsData();
- for (var i in table_data) {
- var record_data = [];
- for (var m in result_data){
- if (table_data[i].num == result_data[m].index && table_data[i].product_base == result_data[m].product_id) {
- record_data = result_data[m].items;
- table_data[i].record_data = record_data;
- break;
- }
- }
- }
- goods_tableIns.reload({
- data: table_data
- });
- }
- });
- }
- function updateCost() {
- var data = getgoodsData();
- if (data.length == 0){
- return;
- }
- for(var i in data){
- var num = data[i].num;
- var stock_id = data[i].warehouse_stockrecord;
- updateTotalCost(num, stock_id);
- updateEntry(num, stock_id)
- }
- }
- parent.layui.submitChild = function () {
- $("#goods-deliver-submit").click();
- };
- });
- function onCountChange(id, num){
- var $ = layui.$;
- var warehouse = $("#id_warehouse").val();
- var stock_id = $("#no" + num).val();
- var count = $("#count" + num).val();
- count = parseFloat(count);
- if(!warehouse){
- $("#total_cost" + num).html('');
- return;
- }
- if(!stock_id || !num || isNaN(num) || isNaN(stock_id) ){
- $("#total_cost" + num).html('');
- return;
- }
- if(!count || isNaN(count)){
- $("#total_cost" + num).html('');
- return;
- }
- var admin = layui.admin;
- admin.req({
- url: '/warehouse/select/stock/?warehouse=' + warehouse + '&product=' + id
- ,done: function(res){
- var result_data = res.data;
- for (var i in result_data) {
- if (result_data[i].stock_id == stock_id){
- var total_cost = count * result_data[i].entry_price;
- $('#total_cost' + num).html(total_cost.toFixed(4))
- }
- }
- }
- })
- }
- </script>
- </body>
- </html>
|