文件
xionggeshop/public/assets/js/report.js

511 行
22 KiB
JavaScript

define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
// 检查手机号码是否输入正确
let checkMobile = (rule, value, callback) => {
if (!/^1[3|4|5|6|7|8|9][\d]{9}$/.test(value)) {
callback(new Error('请您输入正确的手机号码'));
} else {
callback()
}
};
var Controller = {
index: function () {
let vue = new Vue({
el: '#vue',
data: {
showSearchBox: false,
chinaList: [],
loadingText: '拼命加载中...',
// 添加编辑
title: '',
addDialog: false,
// 表格当前页数据
tableData: [],
// 多选数组
multipleSelection: [],
// 搜索条件
key: '',
// 默认每页数据量
pageSize: 20,
// 当前页码
currentPage: 1,
// 默认数据总数
totalCount: 0,
// 列表加载遮罩
listLoading: false,
// 搜索字段
search: {
dateTime: '',
nickname: '',
mobile: '',
sort: 'id',
status: '',
gender: '',
china: ''
},
// 字段信息
formData: {},
statusOpt: [{
id: 1,
value: '启用'
}, {
id: 2,
value: '禁用'
}],
// 表单验证规则
rules: {
nickname: [{
required: true,
message: '请您输入微信昵称',
trigger: 'blur'
}],
avatar: [{
required: true,
message: '请您上传头像',
trigger: 'blur'
}],
// mobile: [{
// required: true,
// message: '请您输入手机号码',
// trigger: 'blur'
// }, {
// validator: checkMobile
// }],
},
pickerOptions: {
shortcuts: [{
text: '昨日',
onClick(picker) {
const start = moment().subtract(1, 'days').startOf('day').toDate();
const end = moment().subtract(1, 'days').endOf('day').toDate();
picker.$emit('pick', [start, end]);
}
}, {
text: '今日',
onClick(picker) {
const start = moment().startOf('day').toDate();
const end = moment()
.endOf('day')
.seconds(59)
.minutes(59)
.hours(23)
.toDate();
picker.$emit('pick', [start, end]);
}
}, {
text: '近7天',
onClick(picker) {
const start = moment().subtract(7, 'days').startOf('day').toDate();
const end = moment()
.endOf('day')
.seconds(59)
.minutes(59)
.hours(23)
.toDate();
picker.$emit('pick', [start, end]);
}
}, {
text: '本月',
onClick(picker) {
const start = moment().startOf('month').startOf('day').toDate();
const end = moment().endOf('month').endOf('day').toDate();
picker.$emit('pick', [start, end]);
}
}, {
text: '今年',
onClick(picker) {
const start = moment().startOf('year').startOf('day').toDate();
const end = moment().endOf('year').endOf('day').toDate();
picker.$emit('pick', [start, end]);
}
}]
},
pickerOptionsOrder: {
shortcuts: [{
text: '最近一周',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近半年',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一年',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
picker.$emit('pick', [start, end]);
}
}]
},
// 时间格式化
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.currentPage, this.pageSize, this.search.sort);
},
methods: {
// 刷新页面
refreshPage() {
this.search = {
dateTime: '',
nickname: '',
mobile: '',
sort: 'id',
status: '',
gender: '',
china: ''
};
this.loadData(this.currentPage, this.pageSize, this.search.sort);
},
// 显示隐藏搜索模块
handleClickSearchBox() {
this.showSearchBox = !this.showSearchBox;
},
handleClearSelect(field) {
// 重新加载
this.$set(this.search, field, '');
this.loadData(this.currentPage, this.pageSize, this.search.sort);
},
handleClearSearchInp() {
// 重新加载
this.loadData(this.currentPage, this.pageSize, this.search.sort);
},
// 选择图片
selectImage() {
Fast.api.open("general/attachment/select?multiple=false", '选择图片', {
callback: res => {
this.$set(this.formData, 'avatar', res.url);
}
});
},
// 提交
submit() {
this.$refs.form.validate(valid => {
if (!valid) {
return false;
}
// 提交
let loading = this.$loading({
lock: true,
text: '正在提交中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
});
$.ajax({
url: 'report/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.currentPage, this.pageSize, this.search.sort);
} else {
this.$message.warning(res.msg);
}
}
})
});
},
// 添加/编辑
openAddDialog(type, item) {
this.addDialog = true;
if (type === 'add') {
this.title = '添加';
this.formData = {
id: 0,
nickname: '',
avatar: '',
mobile: '',
status: 'normal',
gender: 1,
china: ''
};
} else {
this.title = '编辑';
this.formData = {
id: item.id,
nickname: item.nickname,
avatar: item.avatar,
mobile: item.mobile,
old_mobile: item.mobile,
status: item.status,
gender: item.gender,
money: item.money,
china: [item.province_id, item.city_id, item.area_id]
};
}
},
handleChinaChange(e) {
if (e.length === 0) {
// 重新加载
this.$set(this.search, 'china', '');
this.loadData(this.currentPage, this.pageSize, this.search.sort);
}
},
// 从服务器读取数据
loadData(currentPage, pageSize, sort) {
this.listLoading = true;
$.getJSON('report/index', {
page: currentPage,
rows: pageSize,
sort,
search: this.search,
}, data => {
this.totalCount = data.total;
this.tableData = data.list;
this.listLoading = false;
});
},
// 排序
sortChange(e) {
},
// 批量更改状态
handelBatchStatus(status) {
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(() => {
let loading = this.$loading({
lock: true,
text: '正在更改中..',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
});
$.ajax({
url: 'report/batchStatus',
data: {
id: array.join(','),
status
},
type: 'POST',
success: res => {
loading.close();
if (res.code === 200) {
this.$message.success(res.msg);
this.loadData(this.currentPage, this.pageSize, this.search.sort);
} else {
this.$message.warning(res.msg);
}
},
error: function (er) {
}
});
}).catch(() => {
});
},
// 搜索
searchData() {
this.loadData(this.currentPage, this.pageSize, this.search.sort);
},
// 每页显示数据量变更
handleSizeChange(val) {
this.pageSize = val;
this.loadData(this.currentPage, this.pageSize, this.search.sort);
},
// 页码变更
handleCurrentChange(val) {
this.currentPage = val;
this.loadData(this.currentPage, this.pageSize, this.search.sort);
},
// 多选响应
handleSelectionChange(val) {
this.multipleSelection = val;
},
// 状态改变
statusChange(row) {
// 提交
let loading = this.$loading({
lock: true,
text: '正在更改中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
});
$.ajax({
url: 'report/status',
data: {
id: row.id,
status: row.status
},
type: 'GET',
success: res => {
loading.close();
if (res.code === 200) {
this.$message.success(res.msg);
let index = this.tableData.findIndex(v => v.id == row.id);
} else {
this.$message.warning(res.msg);
}
},
error: function (er) {
}
});
},
// 批量删除
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(() => {
let loading = this.$loading({
lock: true,
text: '正在删除中..',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
});
$.ajax({
url: 'report/dell',
data: "id=" + array,
type: "POST",
dataType: 'json',
success: res => {
loading.close();
if (res.code === 200) {
this.$message.success(res.msg);
this.loadData(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(() => {
let loading = this.$loading({
lock: true,
text: '正在删除中..',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
});
$.ajax({
url: 'report/dell',
data: {
id
},
type: "POST",
dataType: 'json',
success: res => {
loading.close();
if (res.code === 200) {
this.$message.success(res.msg);
this.loadData(this.currentPage, this.pageSize, this.search.sort);
} else {
this.$message.warning(res.msg);
}
},
error: function (er) {
}
});
}).catch(() => {
});
},
handleChangeDateTime(e) {
if (!e) {
// 重新加载
this.loadData(this.currentPage, this.pageSize, this.search.sort);
} else if (e[0] === e[1]) {
this.search.dateTime = [
e[0],
e[0].split(' ')[0] + ' 23:59:59'
];
}
},
handleChangeDate(e) {
if (!e) {
// 重新加载
this.loadData(this.currentPage, this.pageSize, this.search.sort);
}
}
}
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});