123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'supplier/index/index' + location.search,
- add_url: 'supplier/index/add',
- edit_url: 'supplier/index/edit',
- del_url: 'supplier/index/del',
- multi_url: 'supplier/index/multi',
- import_url: 'supplier/index/import',
- table: 'shop_goods_supplier',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'weigh',
- fixedColumns: true,
- fixedRightNumber: 1,
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'name', title: __('Name'), operate: 'LIKE'},
- // {field: 'code', title: __('Code'), operate: 'LIKE'},
- {field: 'category.name', title: __('Supplier_category_id')},
- {field: 'contact', title: __('Contact'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
- {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
- {field: 'landline', title: __('Landline'), operate: 'LIKE'},
- // {field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
- // {field: 'province_id', title: __('Province_id')},
- // {field: 'city_id', title: __('City_id')},
- // {field: 'district_id', title: __('District_id')},
- // {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
- // {field: 'bank_account', title: __('Bank_account'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
- // {field: 'bank', title: __('Bank'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
- // {field: 'cardholder_name', title: __('Cardholder_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
- // {field: 'tax_id', title: __('Tax_id'), operate: 'LIKE'},
- {field: 'weigh', title: __('Weigh'), operate: false},
- {field: 'status', title: __('Status'), searchList: Controller.api.parseConfigJson('statusList'), formatter: Table.api.formatter.status},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- recyclebin: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- 'dragsort_url': ''
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: 'supplier/index/recyclebin' + location.search,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'name', title: __('Name'), align: 'left'},
- {
- field: 'deletetime',
- title: __('Deletetime'),
- operate: 'RANGE',
- addclass: 'datetimerange',
- formatter: Table.api.formatter.datetime
- },
- {
- field: 'operate',
- width: '140px',
- 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: 'supplier/index/restore',
- refresh: true
- },
- {
- name: 'Destroy',
- text: __('Destroy'),
- classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
- icon: 'fa fa-times',
- url: 'supplier/index/destroy',
- refresh: true
- }
- ],
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- // 解析Config中的JSON字符串的辅助函数
- parseConfigJson: function(configKey, defaultValue) {
- var configValue = Config[configKey] || defaultValue || {};
-
- // 如果是字符串,尝试解析JSON
- if (typeof configValue === 'string') {
- try {
- return JSON.parse(configValue);
- } catch (e) {
- return defaultValue || {};
- }
- }
-
- return configValue;
- },
- bindevent: function () {
- // 省市区联动同步
- $(document).on('change', 'select[name="province"]', function() {
- $('#province_id_hidden').val($(this).val());
- });
- $(document).on('change', 'select[name="city"]', function() {
- $('#city_id_hidden').val($(this).val());
- });
- $(document).on('change', 'select[name="area"]', function() {
- $('#district_id_hidden').val($(this).val());
- });
-
- // 编辑页面初始化省市区选中状态
- // if ($('#province_id_hidden').length > 0) {
- // var provinceId = $('#province_id_hidden').val();
- // var cityId = $('#city_id_hidden').val();
- // var districtId = $('#district_id_hidden').val();
-
- // if (provinceId) {
- // // 设置省份选中状态
- // setTimeout(function() {
- // $('select[name="province"]').val(provinceId).trigger('change');
-
- // // 如果有城市ID,等待省份联动完成后设置城市
- // if (cityId) {
- // setTimeout(function() {
- // $('select[name="city"]').val(cityId).trigger('change');
-
- // // 如果有区县ID,等待城市联动完成后设置区县
- // if (districtId) {
- // setTimeout(function() {
- // $('select[name="area"]').val(districtId);
- // }, 500);
- // }
- // }, 500);
- // }
- // }, 500);
- // }
- // }
-
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|