* Finish task#43905.

This commit is contained in:
xieqiyu
2021-11-09 19:46:08 +08:00
parent c14d00e710
commit 0a3dc10f4a
4 changed files with 37 additions and 15 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ class branch extends control
* @access public
* @return void
*/
public function manage($productID, $browseType = 'active', $orderBy = 'order_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
public function manage($productID, $browseType = 'active', $orderBy = 'order', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->loadModel('product')->setMenu($productID);
$this->session->set('branchManage', $this->app->getURI(true), 'product');
+17 -6
View File
@@ -13,16 +13,27 @@ function deleteItem(obj)
$(function()
{
$('#branches').sortable(
$('#branchTableList').addClass('sortable').sortable(
{
selector: '.input-group',
reverse: orderBy === 'order_desc',
selector: 'tr',
dragCssClass: 'drag-row',
trigger: $('#branches').find('.sort-handler').length ? '.sort-handler' : null,
trigger: $('#branchTableList').find('.sort-handler').length ? '.sort-handler' : null,
canMoveHere: function($ele, $target)
{
return $target.data('id') != 0;
},
finish: function(e)
{
var list = '';
$('#branches').find('.input-group').each(function(){list += $(this).attr('data-id') + ',';});
$.post(createLink('branch', 'sort'), {'branches' : list});
var branches = '';
e.list.each(function()
{
branches += $(this.item).data('id') + ',';
});
$.post(createLink('branch', 'sort'), {'branches': branches, 'orderBy': orderBy});
}
});
+11 -4
View File
@@ -345,11 +345,18 @@ class branchModel extends model
*/
public function sort()
{
$data = fixer::input('post')->get();
$branches = trim($data->branches, ',');
foreach(explode(',', $branches) as $order => $branchID)
$orderBy = $this->post->orderBy;
$branchIDList = explode(',', trim($this->post->branches, ','));
if(strpos($orderBy, 'order') === false) return false;
if(in_array(BRANCH_MAIN, $branchIDList)) unset($branchIDList[array_search(BRANCH_MAIN, $branchIDList)]);
$branches = $this->dao->select('id,`order`')->from(TABLE_BRANCH)->where('id')->in($branchIDList)->orderBy($orderBy)->fetchPairs('order', 'id');
foreach($branches as $order => $id)
{
$this->dao->update(TABLE_BRANCH)->set('`order`')->eq($order)->where('id')->eq($branchID)->exec();
$newID = array_shift($branchIDList);
if($id == $newID) continue;
$this->dao->update(TABLE_BRANCH)->set('`order`')->eq($order)->where('id')->eq($newID)->exec();
}
}
+8 -4
View File
@@ -12,6 +12,7 @@
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/sortable.html.php';?>
<?php js::set('orderBy', $orderBy)?>
<?php $canCreate = common::hasPriv('branch', 'create');?>
<?php $canBatchEdit = common::hasPriv('branch', 'batchEdit');?>
<?php $canMergeBranch = common::hasPriv('branch', 'mergeBranch');?>
@@ -58,15 +59,18 @@
<th class='c-actions-2'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody class="sortable">
<tbody id='branchTableList'>
<?php foreach($branchList as $branch):?>
<tr>
<?php $isMain = $branch->id == BRANCH_MAIN;?>
<tr data-id='<?php echo $branch->id;?>'>
<?php if($canBatchAction):?>
<td class='cell-id'>
<?php echo html::checkbox('branchIDList', array($branch->id => ''));?>
</td>
<?php endif;?>
<td class='c-actions sort-handler'><i class="icon icon-move"></i></td>
<td class='c-actions <?php echo $isMain ? '' : 'sort-handler';?>'>
<?php echo $isMain ? '' : '<i class="icon icon-move"></i>';?>
</td>
<td class='c-name flex' title='<?php echo $branch->name;?>'>
<span class="text-ellipsis"><?php echo $branch->name;?></span>
<?php
@@ -90,7 +94,7 @@
<td class='c-name' title='<?php echo $branch->desc;?>'><?php echo $branch->desc;?></td>
<td class='c-actions'>
<?php
$disabled = $branch->id == BRANCH_MAIN ? 'disabled' : '';
$disabled = $isMain ? 'disabled' : '';
common::printIcon('branch', 'edit', "branchID=$branch->id", $branch, 'list', '', '', "$disabled iframe", true);
if($branch->status == 'active')
{