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 = '' + (val || '-') + '';
if (Number(row.urgent) === 1) {
html += ' 急';
}
if (row.merchant_name) {
// 企业工单标签:直接输出企业名(不可用 formatter.normal,其内部会以 row[this.field] 即订单号覆盖显示值)
var mName = String(row.merchant_name).replace(/[&<>"']/g, function (c) {
return {'&': '&', '<': '<', '>': '>', '"': '"', "'": '''}[c];
});
html += '
' + mName + '
';
}
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 '' + (val || '-') + '
' + spec + '
';
}
},
{
field: 'contact',
title: '现场客户 / 区域',
operate: 'LIKE',
align: 'left',
formatter: function (val, row) {
var region = [row.city || '', row.district || ''].join('');
return '' + (val || '-') + ' ' + (row.mobile || '') + '
' +
' ' + (region || row.address || '-') + '
';
}
},
{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 '待指派';
}
var mMobile = (row.master && row.master.mobile) ? row.master.mobile : '';
return '' + val + '
' + mMobile + '
';
}
},
{
field: 'pay_amount',
title: '实付金额',
operate: 'BETWEEN',
sortable: true,
formatter: function (val, row) {
var pType = row.price_type === 'quote' ? '报价' : (row.price_type === 'custom' ? '自定' : '一口价');
return '¥' + Number(val || 0).toFixed(2) + '' + pType + '
';
}
},
{
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 '' + item.text + '';
}
},
{
field: 'pay_status',
title: '支付状态',
searchList: {"0": "未支付", "1": "已支付", "2": "已退款"},
formatter: function (val) {
var v = Number(val);
if (v === 1) return '已支付';
if (v === 2) return '已退款';
return '未支付';
}
},
{
field: 'appoint_time',
title: '预约上门',
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter: function (val, row, index) {
if (!val || Number(val) <= 0) {
return '尽快上门';
}
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;
}
},
{
name: 'aftersale',
text: '售后退款',
title: function (row) {
return '售后退款工作台 - ' + row.order_no;
},
icon: 'fa fa-undo',
classname: 'btn btn-xs btn-danger btn-dialog btn-aftersale-ord',
url: 'order/aftersale',
visible: function (row) {
// 已支付且未完成师傅结算的订单可进入售后退款工作台(含已完成/售后中/待验收等状态)
return Number(row.pay_status) === 1 && Number(row.settle_status) !== 1;
}
}
]
}
]
]
});
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();
},
aftersale: function () {
// 售后退款工作台:表单提交由通用 Form.api.bindevent 处理(成功后自动刷新父页工单列表)
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('确认向微信支付发起(或重试)原路退款?
商户单号:' + escapeHtml(outNo) + '', {
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;
});