123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数
- Table.api.init({
- extend: {
- index_url: 'commission/apply/index',
- detail_url: 'commission/apply/detail',
- approve_url: 'commission/apply/approve',
- reject_url: 'commission/apply/reject',
- table: 'shop_commission_apply',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- sortOrder: 'desc',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id'), sortable: true},
- {field: 'user.nickname', title: __('User'), operate: 'LIKE', formatter: Table.api.formatter.search},
- {field: 'apply_type_text', title: __('Apply type'), searchList: {"personal": "个人申请", "company": "企业申请"}, formatter: function(value, row, index) {
- if (row.apply_type === 'personal') {
- return '<span class="label label-primary">' + value + '</span>';
- } else {
- return '<span class="label label-info">' + value + '</span>';
- }
- }},
- {field: 'agent_type_text', title: __('Agent type'), searchList: {"normal": "普通代理商", "province": "省级代理商", "city": "市级代理商", "district": "区域代理商"}, formatter: function(value, row, index) {
- var colorMap = {
- 'province': 'danger', // 省级-红色
- 'city': 'warning', // 市级-橙色
- 'district': 'info', // 区域-蓝色
- 'normal': 'default' // 普通-默认
- };
- var color = colorMap[row.agent_type] || 'default';
- return '<span class="label label-' + color + '">' + value + '</span>';
- }},
- {field: 'identity.name', title: __('Identity'), operate: false},
- {field: 'real_name', title: __('Real name'), visible: false},
- {field: 'company_name', title: __('Company name'), visible: false},
- {field: 'province_name', title: __('Area'), operate: false, formatter: function(value, row, index) {
- return (row.province_name || '') + '-' + (row.city_name || '') + '-' + (row.district_name || '');
- }},
- {field: 'status_text', title: __('Status'), searchList: {"pending": "待审核", "approved": "已通过", "rejected": "已拒绝"}, formatter: function(value, row, index) {
- var colorMap = {
- 'pending': 'warning',
- 'approved': 'success',
- 'rejected': 'danger'
- };
- var color = colorMap[row.status] || 'default';
- return '<span class="label label-' + color + '">' + value + '</span>';
- }},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
- formatter: function (value, row, index) {
- var html = [];
-
- // 详情按钮
- html.push('<a href="' + Fast.api.fixurl("commission/apply/detail/ids/" + row.id) + '" class="btn btn-xs btn-info btn-dialog" data-area=\'["80%","80%"]\' title="' + __('Detail') + '"><i class="fa fa-list"></i></a>');
-
- // 审核按钮 - 只在待审核状态显示
- if (row.status === 'pending') {
- html.push('<a href="javascript:;" class="btn btn-xs btn-success btn-approve-one" data-id="' + row.id + '" title="' + __('Approve') + '"><i class="fa fa-check"></i></a>');
- html.push('<a href="javascript:;" class="btn btn-xs btn-danger btn-reject-one" data-id="' + row.id + '" title="' + __('Reject') + '"><i class="fa fa-times"></i></a>');
- }
-
- return html.join(' ');
- }}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
-
- // 批量审核按钮
- $(document).on('click', '.btn-approve', function () {
- var ids = Table.api.selectedids(table);
- if (ids.length === 0) {
- Toastr.warning("请至少选择一条记录");
- return false;
- }
- Layer.confirm(__('Are you sure you want to approve %s selected item?', ids.length), {
- icon: 3,
- title: __('Warning'),
- shadeClose: true,
- }, function (index) {
- Table.api.multi("approve", ids, table, this);
- Layer.close(index);
- });
- });
-
- // 单个审核通过
- $(document).on('click', '.btn-approve-one', function () {
- var id = $(this).data('id');
- Layer.confirm('确定要通过该申请吗?', {title: '提示'}, function(index) {
- Fast.api.ajax({
- url: 'commission/apply/approve',
- data: {ids: id}
- }, function(data, ret) {
- Layer.close(index);
- table.bootstrapTable('refresh');
- Toastr.success(ret.msg || '操作成功');
- });
- });
- });
-
- // 单个审核拒绝
- $(document).on('click', '.btn-reject-one', function () {
- var id = $(this).data('id');
- Layer.prompt({
- title: '请输入拒绝原因',
- formType: 2
- }, function(value, index) {
- if (!value || !value.trim()) {
- Layer.msg('请输入拒绝原因');
- return false;
- }
- Fast.api.ajax({
- url: 'commission/apply/reject',
- data: {ids: id, reason: value}
- }, function(data, ret) {
- Layer.close(index);
- table.bootstrapTable('refresh');
- Toastr.success(ret.msg || '操作成功');
- });
- });
- });
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|