From 10b7cf2a1d122470c7003363d7fdbf86b138254e Mon Sep 17 00:00:00 2001 From: guoxing <1369478551@qq.com> Date: Tue, 28 Nov 2023 11:25:58 +0800 Subject: [PATCH] 2023-11-28 --- src/api/order/order.js | 38 +++++ src/utils/index.js | 262 +++++++++++++++++++++++----------- src/views/order/index.vue | 260 ++++++++++++++++++++++++++++++++- src/views/order/indexInfo.vue | 194 +++++++++++++++++++++++++ 4 files changed, 665 insertions(+), 89 deletions(-) create mode 100644 src/api/order/order.js create mode 100644 src/views/order/indexInfo.vue diff --git a/src/api/order/order.js b/src/api/order/order.js new file mode 100644 index 0000000..39973ea --- /dev/null +++ b/src/api/order/order.js @@ -0,0 +1,38 @@ +import request from '@/utils/request' + +export default { + + // 获取订单列表 + orderList: function(data) { + return request({ + url: '/lpksreservoorder/orderList', + method: 'post', + data: data + }); + }, + + // 获取所有门店 + getAllStore: function(data) { + return request({ + url: '/lpkstore/getAllStore', + method: 'delete', + data: data + }); + }, + + // 导出报表 + exportExcel: function(data) { + return request({ + url: '/lpksreservoorder/exportExcel', + method: 'post', + responseType: 'blob', // 表明返回服务器返回的数据类型 + data: data, + headers: { + 'Content-Type': 'application/json' + } + }); + }, + + + +} \ No newline at end of file diff --git a/src/utils/index.js b/src/utils/index.js index 4830c04..40d3448 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -9,46 +9,48 @@ * @returns {string | null} */ export function parseTime(time, cFormat) { - if (arguments.length === 0 || !time) { - return null - } - const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}' - let date - if (typeof time === 'object') { - date = time - } else { - if ((typeof time === 'string')) { - if ((/^[0-9]+$/.test(time))) { - // support "1548221490638" - time = parseInt(time) - } else { - // support safari - // https://stackoverflow.com/questions/4310953/invalid-date-in-safari - time = time.replace(new RegExp(/-/gm), '/') - } - } + if (arguments.length === 0 || !time) { + return null + } + const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}' + let date + if (typeof time === 'object') { + date = time + } else { + if ((typeof time === 'string')) { + if ((/^[0-9]+$/.test(time))) { + // support "1548221490638" + time = parseInt(time) + } else { + // support safari + // https://stackoverflow.com/questions/4310953/invalid-date-in-safari + time = time.replace(new RegExp(/-/gm), '/') + } + } - if ((typeof time === 'number') && (time.toString().length === 10)) { - time = time * 1000 - } - date = new Date(time) - } - const formatObj = { - y: date.getFullYear(), - m: date.getMonth() + 1, - d: date.getDate(), - h: date.getHours(), - i: date.getMinutes(), - s: date.getSeconds(), - a: date.getDay() - } - const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => { - const value = formatObj[key] - // Note: getDay() returns 0 on Sunday - if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] } - return value.toString().padStart(2, '0') - }) - return time_str + if ((typeof time === 'number') && (time.toString().length === 10)) { + time = time * 1000 + } + date = new Date(time) + } + const formatObj = { + y: date.getFullYear(), + m: date.getMonth() + 1, + d: date.getDate(), + h: date.getHours(), + i: date.getMinutes(), + s: date.getSeconds(), + a: date.getDay() + } + const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => { + const value = formatObj[key] + // Note: getDay() returns 0 on Sunday + if (key === 'a') { + return ['日', '一', '二', '三', '四', '五', '六'][value] + } + return value.toString().padStart(2, '0') + }) + return time_str } /** @@ -57,41 +59,41 @@ export function parseTime(time, cFormat) { * @returns {string} */ export function formatTime(time, option) { - if (('' + time).length === 10) { - time = parseInt(time) * 1000 - } else { - time = +time - } - const d = new Date(time) - const now = Date.now() + if (('' + time).length === 10) { + time = parseInt(time) * 1000 + } else { + time = +time + } + const d = new Date(time) + const now = Date.now() - const diff = (now - d) / 1000 + const diff = (now - d) / 1000 - if (diff < 30) { - return '刚刚' - } else if (diff < 3600) { - // less 1 hour - return Math.ceil(diff / 60) + '分钟前' - } else if (diff < 3600 * 24) { - return Math.ceil(diff / 3600) + '小时前' - } else if (diff < 3600 * 24 * 2) { - return '1天前' - } - if (option) { - return parseTime(time, option) - } else { - return ( - d.getMonth() + - 1 + - '月' + - d.getDate() + - '日' + - d.getHours() + - '时' + - d.getMinutes() + - '分' - ) - } + if (diff < 30) { + return '刚刚' + } else if (diff < 3600) { + // less 1 hour + return Math.ceil(diff / 60) + '分钟前' + } else if (diff < 3600 * 24) { + return Math.ceil(diff / 3600) + '小时前' + } else if (diff < 3600 * 24 * 2) { + return '1天前' + } + if (option) { + return parseTime(time, option) + } else { + return ( + d.getMonth() + + 1 + + '月' + + d.getDate() + + '日' + + d.getHours() + + '时' + + d.getMinutes() + + '分' + ) + } } /** @@ -99,19 +101,105 @@ export function formatTime(time, option) { * @returns {Object} */ export function param2Obj(url) { - const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') - if (!search) { - return {} - } - const obj = {} - const searchArr = search.split('&') - searchArr.forEach(v => { - const index = v.indexOf('=') - if (index !== -1) { - const name = v.substring(0, index) - const val = v.substring(index + 1, v.length) - obj[name] = val - } - }) - return obj + const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') + if (!search) { + return {} + } + const obj = {} + const searchArr = search.split('&') + searchArr.forEach(v => { + const index = v.indexOf('=') + if (index !== -1) { + const name = v.substring(0, index) + const val = v.substring(index + 1, v.length) + obj[name] = val + } + }) + return obj } + + +export function getDateRang(val) { + const now = new Date(); // 当前日期 + const nowDayOfWeek = now.getDay(); // 今天本周的第几天 + const nowDay = now.getDate(); // 当前日 + const nowMonth = now.getMonth(); // 当前月 + const nowYear = now.getFullYear(); // 当前年 + const jd = Math.ceil((nowMonth + 1) / 3); + let startTime; + let endTime; + let customTime = []; + switch (val) { + case 'yesterday': // 昨日 + startTime = new Date(nowYear, nowMonth, nowDay - 1); + endTime = new Date(nowYear, nowMonth, nowDay - 1); + break; + case 'week': // 本周 + startTime = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek); + endTime = new Date(nowYear, nowMonth, nowDay + 6 - nowDayOfWeek); + break; + case 'pastWeek': // 近 7 日 + startTime = new Date(nowYear, nowMonth, nowDay - 6); + endTime = new Date(nowYear, nowMonth, nowDay); + break; + case 'month': // 本月 + startTime = new Date(nowYear, nowMonth, 1); + endTime = new Date(nowYear, nowMonth + 1, 0); + break; + case 'pastMonth': // 近 31 日 + startTime = new Date(nowYear, nowMonth, nowDay - 30); + endTime = new Date(nowYear, nowMonth, nowDay); + break; + case 'quarter': // 本季度 + startTime = new Date(nowYear, (jd - 1) * 3, 1); + endTime = new Date(nowYear, jd * 3, 0); + break; + case 'year': // 今年 + startTime = new Date(nowYear, 0, 1); + endTime = new Date(nowYear, 11, 31); + break; + default: // 自定义时间 + customTime = val.split(' - '); + break; + } + return customTime.length ? customTime : [formatDate(startTime), formatDate(endTime)]; + // return formatDate(startTime) +} + +export function formatDate(date) { + const y = date.getFullYear(); + let m = date.getMonth() + 1; + m = m < 10 ? `0${m}` : m; + let d = date.getDate(); + d = d < 10 ? `0${d}` : d; + return `${y}-${m}-${d}`; +} + +// 获取当前日期前后多少天的日期,多少天前传正数,多少天后传负数,今天传0, +// num为传入的数字, time为传入的指定日期,如果time不传,则默认为当前时间 +export function getBeforeDate(num, time) { + let n = num; + let d = ''; + if (time) { + d = new Date(time); + } else { + d = new Date(); + } + let year = d.getFullYear(); + let mon = d.getMonth() + 1; + let day = d.getDate(); + if (day <= n) { + if (mon > 1) { + mon = mon - 1; + } else { + year = year - 1; + mon = 12; + } + } + d.setDate(d.getDate() - n); + year = d.getFullYear(); + mon = d.getMonth() + 1; + day = d.getDate(); + let s = year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day); + return s; +} \ No newline at end of file diff --git a/src/views/order/index.vue b/src/views/order/index.vue index 02409e3..959a0bc 100644 --- a/src/views/order/index.vue +++ b/src/views/order/index.vue @@ -1,8 +1,264 @@ + import req from '@/api/order/order.js' + import ButtonBar from '@/components/ButtonBar' + import Pagination from '@/components/pagination' + import pageye from '@/components/pagination/pageye' + import divAdd from './indexInfo.vue' + import { + getBeforeDate + } from '@/utils/index' + export default { + name: 'SupplierBankInfoIndex', + components: { + ButtonBar, + Pagination, + pageye, + divAdd, + }, + data() { + return { + btndisabled: false, + viewState: 1, // 1、列表 2、添加 3、修改 4、查看 + isSearchShow: false, + searchxianshitit: '显示查询条件', + tableLoading: false, + dataList: [], + btnList: [{ + type: 'success', + size: 'small', + icon: 'export', + btnKey: 'build', + btnLabel: '导出' + }, + { + type: 'info', + size: 'small', + icon: 'cross', + btnKey: 'doClose', + btnLabel: '关闭' + } + ], + page: { + total: 0, // 默认数据总数 + current: 1, // 默认开始页面 + size: 10, // 每页的数据条数 + params: { + startDate:getBeforeDate(-2), + store: "" + }, + }, + giftPackList: [] + } + }, + mounted() { + this.$refs['btnbar'].setButtonList(this.btnList) + }, + created() { + this.getAllStore() + this.loadList() + }, + methods: { + // 搜索条件效果 + clicksearchShow() { + this.isSearchShow = !this.isSearchShow + if (this.isSearchShow) { + this.searchxianshitit = '隐藏查询条件' + } else { + this.searchxianshitit = '显示查询条件' + } + }, + btnHandle(btnKey) { + switch (btnKey) { + case 'build': // 导出 + this.doBuild() + break + case 'doClose': + this.doClose() + break + default: + break + } + }, + selectTime1(val) { + + console.log('selectTime1:', val) + this.page.params.startDate = val + + }, + + giftPackSelect(val) { + console.log('>>>>>>>>>giftPackSelect', val) + this.page.params.store = val + }, + + getAllStore() { + req.getAllStore().then((resp) => { + if (resp.success) { + this.giftPackList = resp.data + } + }).catch(() => {}) + }, - \ No newline at end of file diff --git a/src/views/order/indexInfo.vue b/src/views/order/indexInfo.vue new file mode 100644 index 0000000..70f6ee7 --- /dev/null +++ b/src/views/order/indexInfo.vue @@ -0,0 +1,194 @@ + + + + \ No newline at end of file