123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- 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(`<div class="break-words" style="display:flex;align-items:center;">`)
- if(mobile.logo) {
- let logo=mobile.logo.split(',')[0]
- arr.push(`<div><img src="${logo}" class="view-image" alt="" style="width: 50px;height: 50px;object-fit: cover"/></div>`)
- }
- arr.push(`<div>${a}</div>`)
- arr.push(`</div>`)
- 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 `<input class="flow-change-sort" value="${a}" style="width: 100px;" onfocus="$(this).select()" data-id="${mobile.id}">`
- }},
- {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;
- });
|