define(['jquery', 'bootstrap', 'backend', 'table', 'form','clipboard'], function ($, undefined, Backend, Table, Form,clipboard) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile_flow/index' + location.search,
add_url: 'mobile_flow/add',
edit_url: 'mobile_flow/edit',
sort_url: 'mobile_flow/sort',
// del_url: 'mobile_flow/del',
multi_url: 'mobile_flow/multi',
multi_down_url: 'mobile_flow/multi_down',
multi_up_url: 'mobile_flow/multi_up',
import_url: 'mobile_flow/import',
batch: 'mobile_flow/batch',
table: 'mobile',
}
});
let tableData=[]
let clip=new clipboard('.btn-copy-obj',{
text:function (a){
let idx=$(a).data('row-index'),
row=tableData[idx]
return `${location.origin}/build/#/data-traffic-detail/${row.id}`
}
})
clip.on('success',function (){
parent.layer.msg('复制成功')
})
$('.btn-multi_down').click(function (){
parent.layer.confirm('确定要下架吗?',(idx)=>{
let ids=[]
table.bootstrapTable('getSelections').forEach(item=>{
ids.push(item.id)
})
let a=parent.layer.load()
$.ajax($.fn.bootstrapTable.defaults.extend.multi_down_url,{
data:{ids},
type:'post',
success({code,msg}){
if(code){
parent.layer.msg('操作成功')
$('.btn-refresh').trigger('click')
}else{
parent.layer.alert(msg)
}
},
complete(){
parent.layer.close(a)
}
})
parent.layer.close(idx)
})
})
$('.btn-multi_up').click(function (){
parent.layer.confirm('确定要上架吗?',(idx)=>{
let ids=[]
table.bootstrapTable('getSelections').forEach(item=>{
ids.push(item.id)
})
let a=parent.layer.load()
$.ajax($.fn.bootstrapTable.defaults.extend.multi_up_url,{
data:{ids},
type:'post',
success({code,msg}){
if(code){
parent.layer.msg('操作成功')
$('.btn-refresh').trigger('click')
}else{
parent.layer.alert(msg)
}
},
complete(){
parent.layer.close(a)
}
})
parent.layer.close(idx)
})
});
var table = $("#table");
table.on('post-common-search.bs.table', function (event, table) {
var form = $("form", table.$commonsearch);
$("input[name='proxy_id']", form).addClass("selectpage").data("source", "auth/admin/index2").data("params",{"custom[proxy]":"0","custom[sub]":"1"}).data("primaryKey", "nickname").data("field", "nickname").data("orderBy", "id asc");
Form.events.cxselect(form);
Form.events.selectpage(form);
});
$(".btn-add").data("area", ["100%","100%"]);
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
search:false,
searchFormVisible:true,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
//{field: 'proxy_role', title: __('站点选择'),visible:false,searchable:true,operate:false,searchList:{1:"主站", 2:"本店"},defaultValue:1},
{field: 'proxy_id', title: __('代理商')},
{field: 'product_no', title: __('产品编码')},
{field: 'name', title: __('商品名称'),operate: 'like',formatter(a,mobile){
let arr=[]
arr.push(`
`)
if(mobile.logo) {
let logo=mobile.logo.split(',')[0]
arr.push(`
`)
}
arr.push(`
${a}
`)
arr.push(`
`)
return arr.join('')
},align:'left',valign:'top'},
{
field: 'brand',
title: __('运营商'),
formatter: Table.api.formatter.label,
custom:{'flow_limit_yd':'success', 'flow_limit_lt':'danger', 'flow_limit_dx':'info', 'flow_limit_gd':'success'},
searchList:brands,
operate: 'like'
},
{field: 'summary', title: __('商品简介'),operate: "like",formatter: Table.api.formatter.content,width: 200},
{field: 'amount_base', title: __('售价'), operate:'BETWEEN'},
{field: 'stock_num', title: __('库存'), operate:'BETWEEN'},
{field: 'sort', title: __('排序'), operate:'BETWEEN',formatter(a, mobile) {
return ``
}},
{field: 'create_time', title: __('上架时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
{field:'status',title:'系统售卖状态',formatter: Table.api.formatter.label,searchList:flow_status,defaultValue:0,},
// {field:'proxy_status',title:'展示状态',formatter: Table.api.formatter.label,searchList:flow_status,defaultValue:(superAdmin ? null : 0),visible:(superAdmin ? false : true),searchable:(superAdmin ? false : true)},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row, index){
// return Table.api.formatter.operate;
var that = $.extend({}, this);
var table = $(that.table).clone(true);
if(row.editAuth == false){
$(table).data("operate-edit", null);
that.table = table;
}
if(row.delAuth == false){
$(table).data("operate-del", null);
that.table = table;
}
return Table.api.formatter.operate.call(that, value, row, index);
},buttons:[
{
name: 'detail',
title: __('复制链接'),
text: __('复制链接'),
classname: 'btn btn-xs btn-info btn-copy-obj',
click: function (data,row) {
},
visible: function (row) {
return true;
}
},
{
name: 'detail',
text: __('复制商品'),
title: __('复制商品'),
classname: 'btn btn-xs btn-info btn-ajax',
url: 'mobile_flow/copy_goods',
refresh: true,
visible: function (row) {
return true;
}
},
]},
]
],
onLoadSuccess(a){
tableData=a.rows
$(".btn-editone").data("area", ["100%","100%"]);
}
});
$(document).on('blur','.flow-change-sort',function (){
let id=$(this).data('id')
let idx=layer.load()
Fast.api.ajax({
url: $.fn.bootstrapTable.defaults.extend.sort_url,
data:{id,sort:this.value}
},()=>{
// $('.btn-refresh').trigger('click')
layer.close(idx)
},(res)=>{
layer.close(idx)
})
})
$(document).on('click','.view-image',function (){
layer.photos({
photos:{
data:[
{
src:this.src
}
]
}
})
})
$('.tab-first[data-value="0"]').trigger('click')
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
$('#c-logo').change(function (){
let images=this.value?this.value.split(','):[]
if(images.length>5){
$(this).val(images.slice(0,5).join(','))
parent.layer.msg('最多上传5张图片')
}
})
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
},
};
return Controller;
});