admin_goods-execl_729
This commit is contained in:
@@ -277,7 +277,7 @@ class Goods extends HD_Controller
|
||||
|
||||
}
|
||||
|
||||
public function edit_excel()
|
||||
public function add_excel()
|
||||
{
|
||||
require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php';
|
||||
$res = $this->upload();
|
||||
@@ -322,6 +322,7 @@ class Goods extends HD_Controller
|
||||
$cor_id = $re_a0 ? $re_a0['id'] : 0;
|
||||
$re_a2 = $this->mdAutoAttr->get(array('s_id' => $s_id, 'type' => 2, 'title' => $incor_id));
|
||||
$incor_id = $re_a2 ? $re_a2['id'] : 0;
|
||||
$pro_time = $pro_time ? gmdate("Y/m/d H:i:s", PHPExcel_Shared_Date::ExcelToPHP($pro_time)) : '';
|
||||
$addData = array('brand_id' => $brand_id, 's_id' => $s_id, 'v_id' => $v_id, 'cor_id' => $cor_id, 'incor_id' => $incor_id
|
||||
, 'ori_price' => $ori_price, 'vin' => $vin, 'frame_num' => $frame_num, 'stdard_num' => $stdard_num, 'pro_time' => $pro_time, 'c_time' => time());
|
||||
$id = $this->mdItems->add($addData);
|
||||
@@ -345,7 +346,7 @@ class Goods extends HD_Controller
|
||||
{
|
||||
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/';
|
||||
$config['allowed_types'] = '*';//xls|xlsx
|
||||
$config['max_size'] = 2 * 1024;
|
||||
$config['max_size'] = 5 * 1024;
|
||||
$config['file_name'] = 'items_' . time() . rand(1, 99999);
|
||||
$this->load->library('upload', $config);
|
||||
if (!$this->upload->do_upload('file')) {
|
||||
|
||||
@@ -55,11 +55,8 @@
|
||||
class="am-btn am-btn-success am-btn-sm w100">新增
|
||||
</button>
|
||||
</div>
|
||||
<div class="am-form-group fl am-form-file">
|
||||
<button type="button" class="am-btn am-btn-sm am-btn-success w100 ml20">
|
||||
<i class="am-icon-cloud-upload"></i> 导入
|
||||
</button>
|
||||
<input id="doc-form-file" type="file">
|
||||
<div class="am-form-group fl ml10">
|
||||
<button type="button" id="import" class="am-btn am-btn-success am-btn-sm w100">导入</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -124,6 +121,24 @@
|
||||
<?php page_view($pager) ?>
|
||||
</div>
|
||||
</div>
|
||||
<div id="goods-modal" style="display: none;padding: 10px">
|
||||
<div class="modal-body">
|
||||
<div class="text-center">
|
||||
<h2><i class="fa fa-info-circle"></i> 请上传Excel文件</h2>
|
||||
<p>Excel文件格式必须与模板保持一致,否则无法导入</p>
|
||||
<div class="form-group-action">
|
||||
<a href="/temp/goods.xlsx" target="_blank" class="btn btn-default">查看模板</a>
|
||||
<label href="javascript:" class="btn btn-primary" style="margin-left: 10px;">
|
||||
<form id="import-form">
|
||||
<input type="file" id="goods-file" name="file" accept=".xls,.xlsx"
|
||||
style="left:-9999px;position:absolute;" onchange="load_goods()">
|
||||
</form>
|
||||
<span>上传Excel文件</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$('#bd-auto1-id').change(function () {
|
||||
@@ -134,45 +149,57 @@
|
||||
$('#bd-auto2-id').change(function () {
|
||||
$('#bd-auto3-id').empty();
|
||||
});
|
||||
$(document).ready(function () {
|
||||
$("#doc-form-file").on("change", function (e) {
|
||||
if (this.files.length < 1) {
|
||||
return false;
|
||||
}
|
||||
var formdata = new FormData();
|
||||
formdata.append('file', this.files[0]);
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '/items/goods/goods/edit_excel',
|
||||
dataType: 'json',
|
||||
data: formdata,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
beforeSend: function () {
|
||||
var index = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
|
||||
function load_goods() {
|
||||
var file = $("#goods-file");
|
||||
if (file.val() == '') {
|
||||
layer.msg('文件是空的');
|
||||
return 0;
|
||||
}
|
||||
var loading = layer.load(1, {
|
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
|
||||
var options = {
|
||||
url: "/items/goods/goods/add_excel",
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: {},
|
||||
success: function (res) {
|
||||
if (res['code']) {
|
||||
layer.msg(res.msg, {
|
||||
icon: 1,
|
||||
time: 2000
|
||||
}, function () {
|
||||
location.reload();
|
||||
});
|
||||
},
|
||||
success: function (res) {
|
||||
if (res['code']) {
|
||||
layer.msg(res.msg, {
|
||||
icon: 1,
|
||||
time: 2000
|
||||
}, function () {
|
||||
location.reload();
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2});
|
||||
}
|
||||
console.log(res);
|
||||
},
|
||||
complete: function () {
|
||||
layer.closeAll('loading');
|
||||
},
|
||||
error: function (responseStr) {
|
||||
console.log(responseStr);
|
||||
} else {
|
||||
layer.msg(res.msg, {icon: 2});
|
||||
}
|
||||
},
|
||||
complete: function () {
|
||||
file.val('');
|
||||
layer.closeAll('loading');
|
||||
}
|
||||
};
|
||||
$("#import-form").ajaxSubmit(options);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$("#import").click(function () {
|
||||
$("#goods-file").val('');
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['40%'], //宽高
|
||||
content: $('#goods-modal'),
|
||||
title: '导入线索',
|
||||
shade: false,
|
||||
btn: ['完成'],
|
||||
yes: function (index) {
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user