<!DOCTYPE html>
<html lang="en">
<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">
</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">

                    <div class="LAY-btns" style="margin-bottom: 10px;">
                        <button data-permission="purchase.add_purchase_price_plan" class="layui-btn layui-btn-sm" id="btn_add_price"><i class="layui-icon layui-icon-add-1"></i>上报价格</button>
                        <button class="layui-btn layui-btn-sm" id="btn_query"><i class="layui-icon layui-icon-search"></i>查询</button>
                    </div>
                    <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>
                    <script type="text/html" id="datagrid-operate-bar">
                        {{#  if(d.report ==0){ }}
                            <a data-permission="purchase.add_purchase_price_plan" class="layui-btn layui-btn-xs" lay-event="edit">录入价格</a>
                        {{#  } }}
                    </script>

                  </div>
                </div>
            </div>
        </div>
    </div>
    <div id="dlg_query" style="display: none">
        <div class="layui-card-body" pad15>
            <form class="layui-form" lay-filter="query-form-element">
              <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <label class="layui-form-label">代码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="model" class="layui-input" autocomplete="off">
                    </div>
                </div>
               </div>
                    <button class="layui-btn" lay-submit lay-filter="query-form-element" id="query_btn" style="display: none">查询</button>
            </form>
        </div>
    </div>

    <script src="../../layuiadmin/layui/layui.js?t=1"></script>
    <script>
        var _params = ''
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table','laydate', 'form', 'upload'], function () {
            var $ = layui.$;
            var table = layui.table
                ,laydate = layui.laydate
                ,form = layui.form;

            table.render({
                elem: '#datagrid'
                ,url: '/purchase/purchase_price/data/'
              ,cols: [[
                {field:'name', title:'产品名称', width:120}
                ,{field:'model', title:'产品代码', width:100}
                ,{field:'type_text', title:'类别', width:100}
                ,{field:'quality_request_text', title:'质量需求', width:150}
                ,{field:'purchase_count', align:'right', title:'需求数量', width:100}
                ,{field:'unit', title:'单位', width:100}
                ,{field:'demend_user_text', title:'需求人', width: 100}
                ,{field:'product_time', title:'需求时间', width: 150}
                ,{field:'price', align:'right', title:'价格', width:100}
                ,{field:'tax_rate', align:'right', title:'税率', width:100}
                ,{field:'supplier_text', title:'供应商', width:120}
                ,{field:'report_text', title:'上报', width:100}
                ,{field:'notes', title:'备注', minWidth:180}
                ,{width:90, align:'left', fixed: 'right', toolbar: '#datagrid-operate-bar'}
              ]]
              ,page: true
              ,height: 'full-104'
              ,done:function () {
                    layui.index.removeNoPermButtons();
                }
              });
            //监听工具条
            table.on('tool(datagrid-operate)', function(obj){
              var data = obj.data;
              if(obj.event === 'edit'){
                  if (data.report == 1){
                      layer.msg('价格已经上报禁止修改');
                      return false;
                  }
                    table.editdata = data;
                    layer.open({
                      type: 2,
                      title: '录入价格',
                      shadeClose: false,
                      area: ['500px', '380px'],
                      btn: ['确定', '取消'],
                      yes: function(index, dom){
                         layui.onSubmitChild = function () {
                          layer.close(index);
                              table.reload('datagrid',{});
                            };
                            layui.submitChild();
                      },
                      btn2: function(index, layero){
                        layer.close(index);//关闭当前按钮
                      },
                      content: 'purchase_price_edit.html?id='+data.id+'&type='+data.type_id
                    });
                  }
            });
            $('#btn_add_price').on('click', function(){
                layer.open({
                  type: 2,
                  title: '上报价格',
                  area: ['70%', '90%'],
                  btn: ['确定', '取消'],
                  yes: function(index, dom){
                     layui.onSubmitChild = function () {
                          layer.close(index);
                              table.reload('datagrid',{});
                            };
                            layui.submitChild();
                  },
                  btn2: function(index, layero){
                    layer.close(index);//关闭当前按钮
                  },
                  content: 'purchase_price_report.html'
                });
            });
            $('#btn_query').on('click', function(){
                layer.open({
                  type: 1,
                  shadeClose: true,
                  area: ['500px', '250px'],
                  title: '查询',
                  btn: ['查询'],
                  yes: function(index, dom){
                     $('#query_btn').click();
                  },
                  content: $('#dlg_query')
                });
            });
            form.on('submit(query-form-element)', function(data){
              //layer.msg(JSON.stringify(data.field));
              _params = data.field;
              table.reload('datagrid', {
                  where: data.field,
                  page:{curr:1}
              });
              layer.closeAll();
              return false
            });

            laydate.render({
                elem: '#create_time'
                ,range: true
            });
        })
    </script>
</body>
</html>