258 行
13 KiB
JavaScript
258 行
13 KiB
JavaScript
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||
|
||
var statusBadgeMap = {
|
||
0: {text: '待支付', cls: 'default'},
|
||
1: {text: '待接单', cls: 'warning'},
|
||
2: {text: '报价中', cls: 'info'},
|
||
3: {text: '已接单', cls: 'primary'},
|
||
4: {text: '待上门', cls: 'primary'},
|
||
5: {text: '已到达', cls: 'info'},
|
||
6: {text: '服务中', cls: 'primary'},
|
||
7: {text: '待验收', cls: 'warning'},
|
||
8: {text: '已完成', cls: 'success'},
|
||
9: {text: '已取消', cls: 'default'},
|
||
10: {text: '售后中', cls: 'danger'}
|
||
};
|
||
|
||
var Controller = {
|
||
index: function () {
|
||
Table.api.init({
|
||
extend: {
|
||
index_url: 'order/index' + location.search,
|
||
add_url: '',
|
||
edit_url: 'order/edit',
|
||
del_url: '',
|
||
detail_url: 'order/detail',
|
||
multi_url: 'order/multi',
|
||
table: 'order',
|
||
}
|
||
});
|
||
|
||
var table = $("#table");
|
||
|
||
table.on('post-body.bs.table', function () {
|
||
$(".btn-detail-ord, .btn-editone", this).data("area", ["1040px", "88%"]);
|
||
$(".btn-dispatch-ord", this).data("area", ["780px", "78%"]);
|
||
});
|
||
$(".btn-edit").data("area", ["1040px", "88%"]);
|
||
|
||
table.bootstrapTable({
|
||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||
pk: 'id',
|
||
sortName: 'id',
|
||
sortOrder: 'desc',
|
||
fixedColumns: false,
|
||
columns: [
|
||
[
|
||
{checkbox: true},
|
||
{field: 'index', title: '序号', operate: false, formatter: Table.api.formatter.index, width: '55px'},
|
||
{
|
||
field: 'order_no',
|
||
title: '工单编号',
|
||
operate: 'LIKE',
|
||
align: 'left',
|
||
formatter: function (val, row) {
|
||
var html = '<span style="font-family:monospace;font-weight:700;color:#0f172a;">' + (val || '-') + '</span>';
|
||
if (Number(row.urgent) === 1) {
|
||
html += ' <span class="label label-danger">急</span>';
|
||
}
|
||
if (row.merchant_name) {
|
||
html += '<div style="margin-top:2px;"><span class="label label-info" style="font-size:10px;"><i class="fa fa-building-o"></i> ' + Table.api.formatter.normal.call(this, row.merchant_name, row) + '</span></div>';
|
||
}
|
||
return html;
|
||
}
|
||
},
|
||
{
|
||
field: 'service_name',
|
||
title: '服务项目 / 规格',
|
||
operate: 'LIKE',
|
||
align: 'left',
|
||
formatter: function (val, row) {
|
||
var spec = row.goods_model ? (row.goods_model + ' ×' + (row.goods_num || 1)) : ('数量 ×' + (row.goods_num || 1));
|
||
return '<div><strong>' + (val || '-') + '</strong></div><div class="text-muted" style="font-size:11.5px;">' + spec + '</div>';
|
||
}
|
||
},
|
||
{
|
||
field: 'contact',
|
||
title: '现场客户 / 区域',
|
||
operate: 'LIKE',
|
||
align: 'left',
|
||
formatter: function (val, row) {
|
||
var region = [row.city || '', row.district || ''].join('');
|
||
return '<div><strong>' + (val || '-') + '</strong> <span class="text-muted">' + (row.mobile || '') + '</span></div>' +
|
||
'<div class="text-muted" style="font-size:11.5px;"><i class="fa fa-map-marker"></i> ' + (region || row.address || '-') + '</div>';
|
||
}
|
||
},
|
||
{field: 'mobile', title: '联系电话', operate: 'LIKE', visible: false},
|
||
{field: 'user.nickname', title: '下单账号', operate: 'LIKE', visible: false},
|
||
{
|
||
field: 'master.realname',
|
||
title: '承接师傅',
|
||
operate: 'LIKE',
|
||
align: 'left',
|
||
formatter: function (val, row) {
|
||
if (!row.master_id || !val) {
|
||
return '<span class="text-muted">待指派</span>';
|
||
}
|
||
var mMobile = (row.master && row.master.mobile) ? row.master.mobile : '';
|
||
return '<div><strong>' + val + '</strong></div><div class="text-muted" style="font-size:11.5px;">' + mMobile + '</div>';
|
||
}
|
||
},
|
||
{
|
||
field: 'pay_amount',
|
||
title: '实付金额',
|
||
operate: 'BETWEEN',
|
||
sortable: true,
|
||
formatter: function (val, row) {
|
||
var pType = row.price_type === 'quote' ? '报价' : (row.price_type === 'custom' ? '自定' : '一口价');
|
||
return '<strong style="color:#ea580c;">¥' + Number(val || 0).toFixed(2) + '</strong><div class="text-muted" style="font-size:11px;">' + pType + '</div>';
|
||
}
|
||
},
|
||
{
|
||
field: 'status',
|
||
title: '工单状态',
|
||
searchList: {"0": "待支付", "1": "待接单", "2": "报价中", "3": "已接单", "4": "待上门", "5": "已到达", "6": "服务中", "7": "待验收", "8": "已完成", "9": "已取消", "10": "售后中"},
|
||
formatter: function (val) {
|
||
var item = statusBadgeMap[Number(val)] || {text: val, cls: 'default'};
|
||
return '<span class="label label-' + item.cls + '">' + item.text + '</span>';
|
||
}
|
||
},
|
||
{
|
||
field: 'pay_status',
|
||
title: '支付状态',
|
||
searchList: {"0": "未支付", "1": "已支付", "2": "已退款"},
|
||
formatter: function (val) {
|
||
var v = Number(val);
|
||
if (v === 1) return '<span class="label label-success">已支付</span>';
|
||
if (v === 2) return '<span class="label label-danger">已退款</span>';
|
||
return '<span class="label label-default">未支付</span>';
|
||
}
|
||
},
|
||
{
|
||
field: 'appoint_time',
|
||
title: '预约上门',
|
||
operate: 'RANGE',
|
||
addclass: 'datetimerange',
|
||
autocomplete: false,
|
||
formatter: function (val, row, index) {
|
||
if (!val || Number(val) <= 0) {
|
||
return '<span class="text-muted">尽快上门</span>';
|
||
}
|
||
return Table.api.formatter.datetime.call({datetimeFormat: 'MM-DD HH:mm'}, val, row, index);
|
||
}
|
||
},
|
||
{field: 'createtime', title: '下单时间', operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: function (val, row, index) {
|
||
return Table.api.formatter.datetime.call({datetimeFormat: 'MM-DD HH:mm'}, val, row, index);
|
||
}},
|
||
{
|
||
field: 'operate',
|
||
title: __('Operate'),
|
||
table: table,
|
||
events: Table.api.events.operate,
|
||
formatter: Table.api.formatter.operate,
|
||
buttons: [
|
||
{
|
||
name: 'detail',
|
||
text: '详情',
|
||
title: function (row) {
|
||
return '工单详情 - ' + row.order_no;
|
||
},
|
||
icon: 'fa fa-eye',
|
||
classname: 'btn btn-xs btn-info btn-dialog btn-detail-ord',
|
||
url: 'order/detail'
|
||
},
|
||
{
|
||
name: 'dispatch',
|
||
text: function (row) {
|
||
return Number(row.master_id) > 0 ? '改派' : '派单';
|
||
},
|
||
title: function (row) {
|
||
return (Number(row.master_id) > 0 ? '改派承接师傅 - ' : '人工调度派单 - ') + row.order_no;
|
||
},
|
||
icon: 'fa fa-paper-plane',
|
||
classname: 'btn btn-xs btn-warning btn-dialog btn-dispatch-ord',
|
||
url: 'order/dispatch',
|
||
visible: function (row) {
|
||
var st = Number(row.status);
|
||
return Number(row.pay_status) === 1 && st >= 1 && st <= 6;
|
||
}
|
||
}
|
||
]
|
||
}
|
||
]
|
||
]
|
||
});
|
||
|
||
Table.api.bindevent(table);
|
||
},
|
||
dispatch: function () {
|
||
$(document).off('click.dp', '.dp-cand-card').on('click.dp', '.dp-cand-card', function () {
|
||
var id = $(this).data('id');
|
||
$('.dp-cand-card').removeClass('is-picked');
|
||
$(this).addClass('is-picked');
|
||
var $input = $('#c-dispatch-master');
|
||
$input.val(id);
|
||
if ($input.data('selectPageObject')) {
|
||
$input.selectPageRefresh();
|
||
}
|
||
});
|
||
Controller.api.bindevent();
|
||
},
|
||
edit: function () {
|
||
Controller.api.bindevent();
|
||
},
|
||
detail: function () {
|
||
var escapeHtml = function (str) {
|
||
return String(str || '').replace(/[&<>"']/g, function (c) {
|
||
return {'&': '&', '<': '<', '>': '>', '"': '"', "'": '''}[c];
|
||
});
|
||
};
|
||
$(document).off('click', '.js-sync-pay-order').on('click', '.js-sync-pay-order', function () {
|
||
var $btn = $(this);
|
||
var id = $btn.data('id');
|
||
if (!id) return;
|
||
$btn.prop('disabled', true);
|
||
Fast.api.ajax({
|
||
url: 'order/syncpay',
|
||
type: 'post',
|
||
data: { pay_order_id: id }
|
||
}, function () {
|
||
location.reload();
|
||
return false;
|
||
}, function () {
|
||
$btn.prop('disabled', false);
|
||
});
|
||
});
|
||
$(document).off('click', '.js-retry-refund').on('click', '.js-retry-refund', function () {
|
||
var $btn = $(this);
|
||
var id = $btn.data('id');
|
||
var outNo = $btn.data('outno') || '';
|
||
if (!id) return;
|
||
Layer.confirm('确认向微信支付发起(或重试)原路退款?<br><small class="text-muted">商户单号:' + escapeHtml(outNo) + '</small>', {
|
||
title: '确认原路退款',
|
||
icon: 3
|
||
}, function (idx) {
|
||
Layer.close(idx);
|
||
$btn.prop('disabled', true);
|
||
Fast.api.ajax({
|
||
url: 'order/retryrefund',
|
||
type: 'post',
|
||
data: { pay_order_id: id }
|
||
}, function () {
|
||
location.reload();
|
||
return false;
|
||
}, function () {
|
||
$btn.prop('disabled', false);
|
||
});
|
||
});
|
||
});
|
||
},
|
||
api: {
|
||
bindevent: function () {
|
||
Form.api.bindevent($("form[role=form]"));
|
||
}
|
||
}
|
||
};
|
||
return Controller;
|
||
});
|