123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- /**
- * 订单列表业务逻辑
- */
- import { reactive, ref, watch, nextTick, onMounted } from "vue";
- import { request } from "@/utils/network/request.js";
- import { stringToJson } from "@/utils/network/encryption";
- import { onLoad, onUnload, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app";
- import { getItem, StorageKeys, setItem } from "@/utils/storage";
- import { hasLogin, msg, timesDiff } from "@/utils/utils";
- import { orderList, appPage } from "@/utils/network/api";
- import { PageData } from "@/datas/enum";
- const tools = require("../../static/etcUtil/tools.js");
- export default function useOrderListItem(props) {
- //搜索关键字
- const searchKeyWords = ref('');
- const tabName = ref('小程序');
- //订单列表数据
- const ordersList = ref([]);
-
- const config = {
- emptyHint: {
- hint: '~ 暂无订单数据 ~',
- icon: '',
- mode: 'order'
- },
- contentTxt: {
- contentdown: '~上拉加载更多~',
- contentrefresh: '努力加载中...',
- contentnomore: '-- 我是有底线的 --'
- }
- }
-
- //请求参数
- const params = reactive({
- pageNum: PageData.NUM,
- pageSize: PageData.SIZE,
- total: 0,
- status: 'more',
- reload: false,
- })
-
- //搜索
- const doSearch = () => {
- // #ifdef MP-WEIXIN
- if (!searchKeyWords.value) {
- msg('请输入需要搜索的车牌号!');
- return;
- }
- refreshList(true);
- // #endif
- // #ifdef MP-ALIPAY
- tools.showLoadingAlert("加载中");
- refreshList(true);
- tools.hideLoadingAlert();
- // #endif
-
- }
-
- //订单车牌号输入
- const onKeyInput = (event) => {
- searchKeyWords.value = event.target.value;
- if (searchKeyWords.value == '') {
- refreshList(true);
- }
- }
-
- /* 刷新列表 */
- const refreshList = (isLoading) => {
- console.log("========", isLoading)
-
- params.pageNum = 1;
- params.total = 0;
- params.status = 'more';
- params.reload = false;
-
- getList();
- }
-
- const changeTab = (tabOption) => {
- // setItem('tab', tabOption)
- console.log("tabOption", tabOption)
- tabName.value = tabOption
- refreshList(true)
- }
- /* 加载更多 */
- const loadMore = () => {
- if (params.total > ordersList.value.length) {
- params.status = 'loading';
- params.pageNum++;
- getList();
- } else {
- params.status = 'noMore';
- }
- }
-
- /* 获取列表数据 */
- const getList = async () => {
- console.log("props.refresh", props.refresh)
- if (!hasLogin()) {
- uni.stopPullDownRefresh();
- uni.$emit('refreshFinish');
- return;
- }
-
- let res : any = null;
- let newsource = "WECHAT"
- // #ifdef MP-ALIPAY
- newsource = "ALI"
- // #endif
- let options = {}
- console.log("tabName.value", tabName.value)
- if (tabName.value == '线下网点') {
- options = {
- type: 2,
- data: {
- "opId": getItem(StorageKeys.OpenId),
- "vehiclePlate": searchKeyWords.value,
- "tabIndex": props.index + '',
- "pageNo": params.pageNum,
- "pageSize": params.pageSize,
- },
- method: 'POST',
- showLoading: true
- }
- console.log("线下网点", ordersList.value)
- try {
- request(appPage, options).then((res) => {
- uni.hideLoading()
- var data = stringToJson(res.bizContent);
- console.log("ordersList.value", data)
-
- params.total = data.totalCount;
-
- if (params.pageNum === 1) {
- ordersList.value = [];
- }
- if (params.total > 0) {
- const curList = data.data || [];
- ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
- params.reload = false;
- }
-
- if (params.total === ordersList.value.length) {
- params.reload = false;
- params.status = 'noMore';
- }
-
- if (params.pageNum === 1) {
- uni.stopPullDownRefresh();
- }
- // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
- for (var k = 0; k < ordersList.value.length; k++) {
- if (ordersList.value[k]['insertTime']) {
- if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
- ordersList.value[k]['finishOrder'] = true //可以结束
- } else {
- ordersList.value[k]['finishOrder'] = false //不可以结束
- }
- }
- if (ordersList.value[k]['updateTime']) {
- if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
- ordersList.value[k]['isUseAgain'] = true //可以再次使用
- } else {
- ordersList.value[k]['isUseAgain'] = false //不可以再次使用
- }
- }
- }
- // uni.$emit('refreshFinish');
- uni.$emit("refreshOrder");
- console.log("data.refresh", props.refresh)
- console.log('输出内容app', ordersList)
- })
- .catch((err) => {
- console.log(err);
- });
-
- uni.$emit('refreshFinish');
- } catch (e) {
-
- uni.stopPullDownRefresh();
-
- }
- } else {
- options = {
- type: 2,
- data: {
- "opId": getItem(StorageKeys.OpenId),
- "source": newsource,
- "vehiclePlate": searchKeyWords.value,
- "tabIndex": props.index + '',
- "pageNo": params.pageNum,
- "pageSize": params.pageSize,
- "promotionModes": 1,
- },
- method: 'POST',
- showLoading: true
- }
- try {
-
- request(orderList, options).then((res) => {
- uni.hideLoading()
- var data = stringToJson(res.bizContent);
- console.log("ordersList.value", data)
-
- params.total = data.totalCount;
-
- if (params.pageNum === 1) {
- ordersList.value = [];
- }
- if (params.total > 0) {
- const curList = data.data || [];
- ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
- params.reload = false;
- }
-
- if (params.total === ordersList.value.length) {
- params.reload = false;
- params.status = 'noMore';
- }
-
- if (params.pageNum === 1) {
- uni.stopPullDownRefresh();
- }
- // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
- for (var k = 0; k < ordersList.value.length; k++) {
- if (ordersList.value[k]['insertTime']) {
- if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
- ordersList.value[k]['finishOrder'] = true //可以结束
- } else {
- ordersList.value[k]['finishOrder'] = false //不可以结束
- }
- }
- if (ordersList.value[k]['updateTime']) {
- if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
- ordersList.value[k]['isUseAgain'] = true //可以再次使用
- } else {
- ordersList.value[k]['isUseAgain'] = false //不可以再次使用
- }
- }
- }
- // uni.$emit('refreshFinish');
- // uni.$emit("refreshOrder");
- console.log('输出内容小程序', ordersList)
- })
- .catch((err) => {
- console.log(err);
- });
- } catch (e) {
-
- uni.stopPullDownRefresh();
-
- }
- }
-
- console.log("订单列表查询", options)
-
- }
-
- watch(() => props.index, () => {
- console.log("watch1111")
- refreshList(true);
- });
- // watch(() => props.refresh, (nv) => {
- // console.log("watch222222221", props.refresh)
- // if (nv) {
- // refreshList(false);
- // }
- // });
- onMounted(() => {
- if (props.refresh) {
- refreshList(false);
- }
- })
- onPullDownRefresh(() => {
- refreshList(true);
- });
-
- onReachBottom(() => {
- loadMore();
- });
-
- return {
- config,
- params,
- ordersList,
- doSearch,
- onKeyInput,
- refreshList,
- changeTab,
- tabName
- };
- }
|