123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- /**
- * 订单列表业务逻辑
- */
- 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 } from "@/utils/storage";
- import { hasLogin, msg, timesDiff } from "@/utils/utils";
- import { orderList } from "@/utils/network/api";
- import { PageData } from "@/datas/enum";
-
- export default function useOrderListItem(props) {
- //搜索关键字
- const searchKeyWords = 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;
- }
- // #endif
- refreshList(true);
- }
-
- //订单车牌号输入
- const onKeyInput = (event) => {
- searchKeyWords.value = event.target.value;
- if (searchKeyWords.value == '') {
- refreshList(true);
- }
- }
-
- /* 刷新列表 */
- const refreshList = (isLoading) => {
- params.pageNum = 1;
- params.total = 0;
- params.status = 'more';
- params.reload = false;
-
- getList();
- }
-
- /* 加载更多 */
- const loadMore = () => {
- if (params.total > ordersList.value.length) {
- params.status = 'loading';
- params.pageNum++;
- getList();
- } else {
- params.status = 'noMore';
- }
- }
-
- /* 获取列表数据 */
- const getList = async (isLoading = true) => {
- if (!hasLogin()) {
- uni.stopPullDownRefresh();
- uni.$emit('refreshFinish');
- return;
- }
-
- let res : any = null;
- let newsource = "WECHAT"
- // #ifdef MP-ALIPAY
- newsource = "ALI"
- // #endif
-
-
- const options = {
- type: 2,
- data: {
- "opId": getItem(StorageKeys.OpenId),
- "source": newsource,
- "vehiclePlate": searchKeyWords.value,
- "tabIndex": props.index + '',
- "pageNo": params.pageNum,
- "pageSize": params.pageSize,
- "promotionModes": 1,
- "isAfter": true
- },
- method: 'POST',
- // showLoading: isLoading ? (params.pageNum === 1 ? true : false) : false ,
- }
- console.log("订单列表查询", options)
- try {
- // res = await request(orderList, options);
-
- console.log('输出内容1111111')
-
- request(orderList, options).then((res) => {
- const data = stringToJson(res.bizContent);
- console.log("ordersList.value", ordersList.value)
-
- 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 //不可以再次使用
- }
- }
-
- }
- })
- .catch((err) => {
- console.log(err);
- });
-
- uni.$emit('refreshFinish');
- } catch (e) {
- console.log('输出内容222222', e)
-
- uni.stopPullDownRefresh();
- uni.$emit('refreshFinish');
- }
- }
-
- watch(() => props.index, () => {
- refreshList(true);
- });
- watch(() => props.refresh, (nv) => {
- if (nv) {
- refreshList(false);
- }
- });
- onMounted(() => {
- if (props.refresh) {
- refreshList(false);
- }
- })
- onPullDownRefresh(() => {
- refreshList(true);
- });
-
- onReachBottom(() => {
- loadMore();
- });
-
- return {
- config,
- params,
- ordersList,
- doSearch,
- onKeyInput,
- refreshList
- };
- }
|