优化我的足迹部分代码

master
ran 2022-05-03 10:12:01 +08:00
parent 6f60cc6afb
commit a9046aded4
1 changed files with 242 additions and 315 deletions

View File

@ -1,20 +1,20 @@
<template> <template>
<view class="myTracks"> <view class="myTracks">
<u-navbar title="我的足迹"> <u-navbar title="我的足迹">
<div @click="changeRightBtn" slot="right" style="margin-right:32rpx">
{{edit}}
</div>
</u-navbar> </u-navbar>
<u-empty text="暂无历史记录" style="margin-top:200rpx;" mode="history" v-if="whetherEmpty"></u-empty> <u-empty text="暂无历史记录" style="margin-top:200rpx;" mode="history" v-if="whetherEmpty"></u-empty>
<div v-else> <div v-else>
<view v-for="(item, index) in trackList" :key="index"> <view v-for="(item, index) in trackList" :key="index">
<view class="myTracks-title" @click="navgaiteToStore(item)">{{item.storeName}}</view> <view class="myTracks-title" @click="navgaiteToStore(item)">{{item.storeName}}</view>
<view class="myTracks-items"> <view class="myTracks-items">
<u-swipe-action style="width: 100%;" :show="item.show" :index="index" :key="item.id" @click="delTracks"
@open="open" :options="options">
<view class="myTracks-item"> <view class="myTracks-item">
<u-checkbox-group>
<u-checkbox v-model="item.___isDel" v-if="editFlag" active-color="#ff6b35" style="margin-right: 10rpx"
@change="changeChecked(item)"></u-checkbox>
</u-checkbox-group>
<view class="myTracks-item-img" @click.stop="navgaiteToDetail(item)"> <view class="myTracks-item-img" @click.stop="navgaiteToDetail(item)">
<image :src="item.thumbnail"></image> <image :src="item.thumbnail"></image>
</view> </view>
@ -28,41 +28,27 @@
</view> </view>
</view> </view>
</view> </view>
</u-swipe-action>
</view> </view>
<view class="myTracks-divider"></view> <view class="myTracks-divider"></view>
</view> </view>
<uni-load-more :status="loadStatus"></uni-load-more> <uni-load-more :status="loadStatus"></uni-load-more>
</div> </div>
<view v-if="editFlag">
<view class="myTracks-action">
<view class="myTracks-action-check">
<u-checkbox-group>
<u-checkbox v-model="allChecked" v-if="editFlag" active-color="#ff6b35" style="margin-right: 10rpx"
@change="checkedAllitem"></u-checkbox>
全选
</u-checkbox-group>
</view>
<view>
<u-button type="warning" @click="delAllTracks" class="myTracks-action-btn">
删除
</u-button>
</view>
</view>
</view>
</view> </view>
</template> </template>
<script> <script>
import { myTrackList, deleteHistoryListId } from "@/api/members.js"; import {
myTrackList,
deleteHistoryListId
} from "@/api/members.js";
export default { export default {
data() { data() {
return { return {
edit: "编辑",
editFlag: false, //
allChecked: false, //
loadStatus: "more", // loadStatus: "more", //
whetherEmpty: false, // whetherEmpty: false, //
params: { params: {
@ -71,7 +57,14 @@ export default {
order: "desc", order: "desc",
sort: "updateTime", sort: "updateTime",
}, },
options: [
{
text: '删除',
style: {
backgroundColor: '#dd524d'
}
}
],
trackList: [], // trackList: [], //
}; };
}, },
@ -101,35 +94,14 @@ export default {
url: "/pages/product/shopPage?id=" + val.storeId, url: "/pages/product/shopPage?id=" + val.storeId,
}); });
}, },
open(index) {
/** // swipeActionprops
* 设置右侧导航栏文本 // 'false''false'
*/ this.trackList[index].show = true;
setStyle(text) { this.trackList.map((val, idx) => {
// if (index != idx) this.trackList[idx].show = false;
let pages = getCurrentPages(); })
let page = pages[pages.length - 1];
// #ifdef APP-PLUS
let currentWebview = page.$getAppWebview();
let titleNView = currentWebview.getStyle().titleNView;
titleNView.buttons[0].text = text;
if (text == "完成") {
this.trackList.forEach((key) => {
key.history.forEach((item) => {
this.$set(item, "___isDel", false);
});
});
}
currentWebview.setStyle({
titleNView: titleNView,
});
// #endif
// #ifdef H5
// h5
document.getElementsByClassName("uni-btn-icon")[1].innerText = text;
// #endif
}, },
/** /**
* 跳转详情 * 跳转详情
*/ */
@ -152,7 +124,7 @@ export default {
if (res.statusCode == 200) { if (res.statusCode == 200) {
res.data.result && res.data.result &&
res.data.result.forEach((item) => { res.data.result.forEach((item) => {
item.___isDel = false; item.show = false;
}); });
let data = res.data.result; let data = res.data.result;
@ -169,61 +141,14 @@ export default {
}); });
}, },
/**
* 点击后判断是不是全选
*/
changeChecked(val) {
var opt = null;
const isCheckedAll = this.trackList.every((key) => {
key.___isDel == val.___isDel;
opt = key.___isDel;
return opt;
});
if(opt){
this.allChecked = isCheckedAll;
}else{
this.allChecked = false;
}
},
/**
* 右侧标签栏切换
*/
changeRightBtn(e) {
if (!this.editFlag) {
this.edit = "完成";
} else {
this.edit = "编辑";
}
this.editFlag = !this.editFlag;
},
/**
* 点击全选按钮
*/
checkedAllitem() {
//
this.trackList.forEach((key) => {
this.$set(key, "___isDel", this.allChecked);
});
},
/** /**
* 删除足迹 * 删除足迹
*/ */
delAllTracks() { delTracks(index) {
let way = []; deleteHistoryListId(this.trackList[index].goodsId).then((res) => {
this.trackList.forEach((key) => {
if (key.___isDel) {
way.push(key.goodsId);
}
});
if (way.length == 0) return false;
deleteHistoryListId(way).then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
this.trackList = []; this.trackList = [];
this.allChecked = false;
this.getList(); this.getList();
} else { } else {
uni.showToast({ uni.showToast({
@ -285,6 +210,7 @@ export default {
.myTracks-item-img { .myTracks-item-img {
margin-right: 20rpx; margin-right: 20rpx;
border-radius: 8rpx; border-radius: 8rpx;
image { image {
width: 130rpx; width: 130rpx;
height: 130rpx; height: 130rpx;
@ -307,6 +233,7 @@ export default {
color: $light-color; color: $light-color;
padding: 10rpx 0 0 0; padding: 10rpx 0 0 0;
} }
.myTracks-action { .myTracks-action {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;