define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'cars/index' + location.search, add_url: 'cars/add', edit_url: 'cars/edit', del_url: 'cars/del', multi_url: 'cars/multi', import_url: 'cars/import', table: 'cars', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', fixedColumns: true, fixedRightNumber: 1, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, { field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content }, {field: 'car_type', title: '类型', searchList: { "1": '新车', "2": '二手车', "3": '租车', }, formatter: Table.api.formatter.status}, {field: 'brand.name', title: __('Brand_id'), operate: false}, {field: 'series.name', title: __('Series_id'), operate: false}, {field: 'count', title: '库存', operate: false}, {field: 'price', title: __('Price'), operate: 'BETWEEN'}, {field: 're_price', title: '现价(万元)', operate: 'BETWEEN'}, { field: 'cover_image', title: __('Cover_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image }, {field: 'contact.nickname', title: __('Contact_name'), operate: 'LIKE'}, {field: 'contact.mobile', title: __('Contact_phone'), operate: 'LIKE'}, {field: 'active_at', title: '上牌时间', operate: 'RANGE', addclass: 'datetimerange', autocomplete: false}, { field: 'created_at', title: __('Created_at'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false }, { field: 'updated_at', title: __('Updated_at'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false }, {field: 'is_active', title: __('Is_active'), searchList: { "0": '下架', "1": '上架', }, formatter: Table.api.formatter.status}, { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [ { name: 'edit', text: "修改", icon: 'fa fa-pencil', title: __('Edit'), extend: 'data-toggle="tooltip" data-container="body"', classname: 'btn btn-xs btn-info btn-editone', }, { name: 'sale', icon: 'fa fa-sale', text: function (row) { return row.car_type == 3?'出租':'售出' }, url: function (row) { return 'car/sales/add/ids/' + row.id; }, extend: 'data-toggle="tooltip" data-container="body"', classname: 'btn btn-xs btn-info btn-dialog', }, { name: 'del', text: "删除", icon: 'fa fa-trash', title: __('Delete'), extend: 'data-toggle="tooltip"', classname: 'btn btn-xs btn-danger btn-delone', }, ], } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { Controller.api.bindevent(); Controller.api.series(); Controller.api.extend(); }, edit: function () { Controller.api.bindevent(); Controller.api.series(); Controller.api.extend(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); }, series: function () { var _data = series; $('#c-series_id').zdCascader({ data: _data, onChange: function ($this, data, allPathData) { // console.log(data,allPathData); $('#c-series_id_value').val(data.value); } }); $('#c-series_id').val($('#c-series_id').data('value')); }, extend: function () { const id = $('input[name="row[id]"]').val(); let url = "cars/extend"; if (id) { url += '&id=' + id; } Fast.api.ajax({ url: url, // 你的 API 地址 type: "get", contentType: 'application/json', dataType: "json" }, function (data) { var container = $('#add-form'); data.forEach(function (field) { let html = `
`; // ✅ 单选框(radio,替代 checkbox) if (field.type === 'checkbox' || field.type === 'radio') { field.options.forEach(function (opt) { // 是否选中 const checked = String(field.value) === String(opt.value) ? 'checked' : ''; html += ` `; }); } // ✅ 数值范围输入(单 input 版本) else if (field.type === 'range') { const opts = field.options || {}; const val = field.value ?? ''; // 可能是字符串、数字或空 const min = opts.start ?? ''; const max = opts.end ?? ''; const unit = opts.unit ?? ''; html += `
${unit}
`; } html += `
`; container.append(html); }); // ✅ 添加提交按钮区域 container.append(`
`); return false; }) } } }; return Controller; });