car4s/public/assets/js/backend/user4s/goodlog.js

218 lines
9.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { success } = require("toastr");
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'user4s/goodlog/index' + location.search,
add_url: 'user4s/goodlog/add',
//edit_url: 'user4s/goodlog/edit',
del_url: 'user4s/goodlog/del',
multi_url: 'user4s/goodlog/multi',
import_url: 'user4s/goodlog/import',
table: 'user4s_goodlog',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
fixedColumns: true,
fixedRightNumber: 1,
showToggle: false,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id'),operate:false},
//{field: 'admin_id', title: __('Admin_id')},
//{field: 'user4s_id', title: __('User4s_id')},
{field: 'user_name', title: __('User_name'), operate: 'LIKE'},
//{field: 'orderno', title: __('Orderno'), operate: 'LIKE'},
{ field: 'good_name', title: __('兑换的商品') , operate: 'LIKE'},
{field: 'good_num', title: __('兑换的数量'),operate:false},
{field: 'integral', title: __('兑换使用的积分'),operate:false},
{field: 'price', title: __('兑换使用的余额'), operate:false},
{field: 'createtime', title: __('兑换时间'), operate: 'BETWEEN', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD",data-date-use-current="true"', autocomplete: false, formatter: Table.api.formatter.datetime, datetimeFormat: 'YYYY-MM-DD'},
{field: 'description', title: __('Description'), operate: 'LIKE'},
// {field: 'user.balance', title: __('User.balance'), operate:'BETWEEN'},
// {field: 'user.integral', title: __('User.integral')},
// {field: 'user.carno', title: __('User.carno'), operate: 'LIKE'},
// {field: 'user.model', title: __('User.model'), operate: 'LIKE'},
// {field: 'user.color', title: __('User.color'), operate: 'LIKE'},
//{field: 'admin.username', title: __('Admin.username'), operate: 'LIKE'},
{field: 'admin.nickname', title: __('Admin.nickname') ,operate:false},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
],
queryParams: function (params) {
//这里可以追加搜索条件
var filter = JSON.parse(params.filter);
var op = JSON.parse(params.op);
//这里可以动态赋值比如从URL中获取admin_id的值filter.admin_id=Fast.api.query('admin_id');
filter.user4s_id = Fast.api.query('user4s_id');
op.user4s_id = "=";
if (filter.user4s_id == null || filter.user4s_id == "") {
delete filter.user4s_id;
delete op.user4s_id;
}
params.filter = JSON.stringify(filter);
params.op = JSON.stringify(op);
console.log(params);
return params;
},
});
// 为表格绑定事件
Table.api.bindevent(table);
},
recyclebin: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
'dragsort_url': ''
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: 'user4s/goodlog/recyclebin' + location.search,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{
field: 'deletetime',
title: __('Deletetime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
width: '130px',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'Restore',
text: __('Restore'),
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
icon: 'fa fa-rotate-left',
url: 'user4s/goodlog/restore',
refresh: true
},
{
name: 'Destroy',
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
icon: 'fa fa-times',
url: 'user4s/goodlog/destroy',
refresh: true
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
//$('#btn-ok').attr("disabled","true");
var good_id = 0;
var good_jifen = 0;
var good_price = 0;
$("#c-user4s_id").data("eSelect", function(){
var user4s_id = $("#c-user4s_id").val();
console.log(user4s_id, "user4s_id");
$.ajax({
url: "user4s/user/info",
type: "POST", //Use "PUT" for HTTP PUT methods
dataType: 'json',
data: {id: user4s_id},
success: function (data, status, XHR) {
console.log(data);
if (data.code == 0) {
$('#lab_nane').text(data.data.name);
$('#lab_tel').text(data.data.tel);
$('#lab_price').text(data.data.balance+'元');
$('#lab_jifen').text(data.data.integral);
$('#uinfo').show();
} else {
$('#uinfo').hide();
}
},
})
});
$("#c-good_id").data("eSelect", Controller.check);
$(document).on("change", "#c-good_num", Controller.check);
Controller.api.bindevent();
},
check: function () {
var user4s_id = $("#c-user4s_id").val();
var good_id = $("#c-good_id").val();
var good_num = $("#c-good_num").val();
if (user4s_id >= 1 && good_id >= 1 && good_num >= 1) {
$.ajax({
url: "user4s/goods/check",
type: "POST", //Use "PUT" for HTTP PUT methods
dataType: 'json',
data: {id: good_id,num:good_num,user4s_id:user4s_id},
success: function (data, status, XHR) {
console.log(data);
if (data.code != 1) {
$('#need_price').text(data.need_price+'元');
$('#need_jifen').text(data.need_integral);
$('#lab_title').text(data.data.title);
$('#lab_num').text(data.num);
$('#lab_msg').text(data.msg);
if (data.code == 2) {
$('#ginfo').removeClass('panel-success');
$('#ginfo').addClass('panel-danger');
//$('#btn-ok').attr("disabled","false");
}
if (data.code == 0) {
$('#ginfo').removeClass('panel-danger');
$('#ginfo').addClass('panel-success');
//$('#btn-ok').attr("disabled","true");
}
$('#ginfo').show();
}
if (data.code == 1){
$('#ginfo').hide();
//$('#btn-ok').attr("disabled","false");
}
},
})
}
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});