define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { var vue = new Vue({ el: '#vue', data: { contentType: 'one', varietiesType: 'one', varietiesList: { one: ['菜籽油', '大豆油'], two: ['稻谷', '小麦', '玉米'], }, contentFields: { "one": { "tankCapacity": "", "tankType": "", "varieties": "", "nature": "", "storageNum": "", "productArea": "", "addr": "", "machiningYear": "", "enterTime": "", "level": "", "color": "", "odorAndTaste": "", "waterVolatileCompounds": "", "insolubleImpurities": "", "acidValue": "", "peroxideValue": "", "heating": "", "residualSolventContent": "", "TankDiameter": "", "oilLoadingHeight": "", "volume": "", "oilVolume": "", "managementForm": "", "custodian": "" }, "two": { "code": "", "warehouseType": "", "capacity": "", "varieties": "", "nature": "", "addr": "", "harvestYear": "", "enterTime": "", "storageNum": "", "level": "", "roughnessRate": "", "impurity": "", "water": "", "volume": "", "decVolume": "", "riceGrains": "", "managementForm": "", "length": "", "width": "", "diam": "", "height": "", "storageMethod": "", "custodian": "" }, "three": { "code": "", "warehouseType": "", "capacity": "", "varieties": "", "nature": "", "addr": "", "harvestYear": "", "enterTime": "", "storageNum": "", "level": "", "weight": "", "impurity": "", "water": "", "volume": "", "decVolume": "", "imperfect": "", "managementForm": "", "length": "", "width": "", "diam": "", "height": "", "storageMethod": "", "custodian": "" } }, contentNewFields: { "one": { "tankCapacity": "", "tankType": "", "varieties": "", "nature": "", "storageNum": "", "productArea": "", "addr": "", "machiningYear": "", "enterTime": "", "level": "", "color": "", "odorAndTaste": "", "waterVolatileCompounds": "", "insolubleImpurities": "", "acidValue": "", "peroxideValue": "", "heating": "", "residualSolventContent": "", "TankDiameter": "", "oilLoadingHeight": "", "volume": "", "oilVolume": "", "managementForm": "", "custodian": "" }, "two": { "code": "", "warehouseType": "", "capacity": "", "varieties": "", "nature": "", "addr": "", "harvestYear": "", "enterTime": "", "storageNum": "", "level": "", "roughnessRate": "", "impurity": "", "water": "", "volume": "", "decVolume": "", "riceGrains": "", "managementForm": "", "length": "", "width": "", "diam": "", "height": "", "storageMethod": "", "custodian": "" }, "three": { "code": "", "warehouseType": "", "capacity": "", "varieties": "", "nature": "", "addr": "", "harvestYear": "", "enterTime": "", "storageNum": "", "level": "", "weight": "", "impurity": "", "water": "", "volume": "", "decVolume": "", "imperfect": "", "managementForm": "", "length": "", "width": "", "diam": "", "height": "", "storageMethod": "", "custodian": "" } }, typeList: [], chinaList: [], activeName: 'one', // 表格当前页数据 tableData: [], // 多选数组 multipleSelection: [], // 搜索条件 key: '', // 默认每页数据量 pageSize: 50, // 当前页码 currentPage: 1, // 默认数据总数 totalCount: 0, // 列表加载遮罩 listLoading: false, formData: {}, addDialog: false, submitLoading: false, title: '', // 类型:rapeseed=菜籽油、bean=大豆油、wheat=小麦、paddy=稻谷、corn=玉米 typeOptList: [{ id: '', name: '全部' }, { id: 'rapeseed', name: '菜籽油' }, { id: 'bean', name: '大豆油' }, { id: 'wheat', name: '小麦' }, { id: 'paddy', name: '稻谷' }, { id: 'corn', name: '玉米' }], // 搜索字段 search: { startTime: '', endTime: '', keyword: '', china: [], granary_type: 0, varieties: '全部', type: '', sort: 'id', }, searchOpt: [{ id: 1, value: '粮仓名称' }, { id: 2, value: '仓库储存点' }, { id: 3, value: '仓号' }], numList: [10, 11, 12, 13, 14, 15, 16, 17, 18, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], // 表单验证规则 rules: { name: [{ required: true, message: '请您输入粮仓名称', trigger: 'blur' }], storage: [{ required: true, message: '请您输入仓库储存点', trigger: 'blur' }], num: [{ required: true, message: '请您选择仓号', trigger: 'blur' }], }, // 时间格式化 dateFormat: function (row, column) { var date = row[column.property]; if (date === undefined || date === 0) { return ''; } return moment(date * 1000).format("YYYY-MM-DD HH:mm:ss"); } }, created() { this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); }, methods: { // 刷新页面 refreshPage() { this.search = { startTime: '', endTime: '', keyword: '', type: '', granary_type: 0, varieties: '全部', china: [], }; this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); }, // 仓号选择 handleSelectNum(e) { if (e > 18) { this.varietiesType = 'two'; this.contentType = 'two'; this.formData.varieties = '稻谷'; this.contentFields[this.contentType]['varieties'] = '稻谷'; } else { this.varietiesType = 'one'; this.contentType = 'one'; this.formData.varieties = '菜籽油'; this.contentFields[this.contentType]['varieties'] = '菜籽油'; } }, varietiesChange(e) { if (e === '菜籽油' || e === '大豆油') { this.contentType = 'one'; } else if (e === '小麦' || e === '玉米') { this.contentType = 'three'; } else { this.contentType = 'two'; } this.contentFields[this.contentType]['varieties'] = e; }, // 选择图片 selectImage() { Fast.api.open("general/attachment/select?multiple=false", '选择图片', { callback: res => { this.$set(this.formData, 'image', res.url); } }); }, handleClearDate(field) { if (!this.search[field]) { // 重新加载 this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); } }, handleChinaChange(e) { if (e.length === 0) { // 重新加载 this.$set(this.search, 'china', ''); this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); } }, handleTableClick(tab, event) { }, // 添加/编辑 openAddDialog(type, item) { this.addDialog = true; if (type === 'add') { this.title = '添加'; this.contentFields = this.contentNewFields; this.formData = { id: 0, name: '', image: '', storage: '', num: '', varieties: '菜籽油', content: [] }; } else { this.title = '编辑'; this.formData = { id: item.id, name: item.name, image: item.image, storage: item.storage, num: item.num, old_num: item.num, varieties: item.varieties, content: [] }; if (item.varieties === '菜籽油' || item.varieties === '大豆油') { this.contentType = 'one'; } else if (item.varieties === '小麦' || item.varieties === '玉米') { this.contentType = 'three'; } else { this.contentType = 'two'; } if (item.num > 18) { this.varietiesType = 'two'; } else { this.varietiesType = 'one'; } this.contentFields[this.contentType]= item.content; } }, // 查看详情 openDetail(item) { layer.open({ type: 2, title: item.name, shadeClose: false, scrollbar: false, maxmin: true, shade: 0.2, area: ['80%', '60%'], content: 'detail?id=' + item.id }); }, handelTypeRadio(e) { this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); }, // 从服务器读取数据 loadData(key, currentPage, pageSize, sort) { this.listLoading = true; $.getJSON('granary/index', { keyword: key, type: this.search.type, start_time: this.search.startTime, end_time: this.search.endTime, granary_type: this.search.granary_type, varieties: this.search.varieties, page: currentPage, rows: pageSize, sort: sort, china: this.search.china }, data => { this.totalCount = data.total; this.tableData = data.list; this.chinaList = data.chinaList; this.typeList = data.typeList; this.contentFields = data.contentFields; this.listLoading = false; }); }, submit() { this.$refs.form.validate(valid => { if (!valid) { this._sweetMsg({ type: 'warning', content: '请您完善仓库信息' }); return false; } let fields = this.contentFields[this.contentType]; for (let key in fields) { if (fields[key] === '') { this._sweetMsg({ type: 'warning', content: '请您完善仓库内容信息' }); return false; } } // 提交 let loading = this.$loading({ lock: true, text: '正在提交中...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.3)' }); this.formData.content = fields; $.ajax({ url: 'granary/add', type: 'POST', data: this.formData, success: res => { loading.close(); if (res.code === 200) { this.$message.success(res.msg); this.addDialog = false; this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); } else { this.$message.warning(res.msg); } } }) }); }, // 排序 sortChange(e) { }, // 搜索 searchData() { this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); }, // 每页显示数据量变更 handleSizeChange(val) { this.pageSize = val; this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); }, // 页码变更 handleCurrentChange(val) { this.currentPage = val; this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); }, // 多选响应 handleSelectionChange(val) { this.multipleSelection = val; }, // 批量删除 del() { if (this.multipleSelection.length === 0) { this.$message.warning('请选择至少一条粮仓进行删除!'); return; } var array = []; this.multipleSelection.forEach((row) => { array.push(row.id); }); this.$confirm('您确定要删除所选的粮仓吗?, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { $.ajax({ url: 'granary/dell', data: "id=" + array, type: "POST", dataType: 'json', success: res => { if (res.code === 200) { this.$message.success(res.msg); this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); } else { this.$message.warning(res.msg); } }, error: function (er) { } }); }).catch(() => { }); }, // 单条删除 dell(id) { this.$confirm('您确定要删除此粮仓吗?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { $.ajax({ url: 'granary/dell', data: { id }, type: "POST", dataType: 'json', success: res => { if (res.code === 200) { this.$message.success(res.msg); this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); } else { this.$message.warning(res.msg); } }, error: function (er) { } }); }).catch(() => { }); }, handleClearSelect(field) { // 重新加载 this.$set(this.search, field, ''); this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); }, handleClearSearchInp() { if (this.search.type) { // 重新加载 this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort); } }, // 弹窗提示框 _sweetMsg(obj) { swal({ title: obj.title || '温馨提示', text: obj.content, type: obj.type || 'success', confirmButtonColor: "#7367f0", confirmButtonText: '确定' }); }, // 询问框 _sweetConfirm(obj, confirmCallBack = () => { }, cancelCallBck = () => { }) { swal({ title: obj.title, text: obj.content || '温馨提示', type: 'info', showCancelButton: true, confirmButtonColor: '#7367f0', confirmButtonText: '', cancelButtonText: '取消', closeOnConfirm: false }, function (confirm) { if (confirm) { confirmCallBack(); } else { cancelCallBck(); } }); } } }); }, detail: function () { }, edit: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });