优化我的足迹部分代码

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>
<view class="myTracks">
<u-navbar title="我的足迹">
<div @click="changeRightBtn" slot="right" style="margin-right:32rpx">
{{edit}}
</div>
</u-navbar>
<u-empty text="暂无历史记录" style="margin-top:200rpx;" mode="history" v-if="whetherEmpty"></u-empty>
<div v-else>
<view v-for="(item, index) in trackList" :key="index">
<view class="myTracks-title" @click="navgaiteToStore(item)">{{item.storeName}}</view>
<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">
<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)">
<image :src="item.thumbnail"></image>
</view>
@ -28,41 +28,27 @@
</view>
</view>
</view>
</u-swipe-action>
</view>
<view class="myTracks-divider"></view>
</view>
<uni-load-more :status="loadStatus"></uni-load-more>
</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>
</template>
<script>
import { myTrackList, deleteHistoryListId } from "@/api/members.js";
import {
myTrackList,
deleteHistoryListId
} from "@/api/members.js";
export default {
data() {
return {
edit: "编辑",
editFlag: false, //
allChecked: false, //
loadStatus: "more", //
whetherEmpty: false, //
params: {
@ -71,7 +57,14 @@ export default {
order: "desc",
sort: "updateTime",
},
options: [
{
text: '删除',
style: {
backgroundColor: '#dd524d'
}
}
],
trackList: [], //
};
},
@ -101,35 +94,14 @@ export default {
url: "/pages/product/shopPage?id=" + val.storeId,
});
},
/**
* 设置右侧导航栏文本
*/
setStyle(text) {
//
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
open(index) {
// swipeActionprops
// 'false''false'
this.trackList[index].show = true;
this.trackList.map((val, idx) => {
if (index != idx) this.trackList[idx].show = false;
})
},
/**
* 跳转详情
*/
@ -152,7 +124,7 @@ export default {
if (res.statusCode == 200) {
res.data.result &&
res.data.result.forEach((item) => {
item.___isDel = false;
item.show = false;
});
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() {
let way = [];
this.trackList.forEach((key) => {
if (key.___isDel) {
way.push(key.goodsId);
}
});
if (way.length == 0) return false;
deleteHistoryListId(way).then((res) => {
delTracks(index) {
deleteHistoryListId(this.trackList[index].goodsId).then((res) => {
if (res.data.code == 200) {
this.trackList = [];
this.allChecked = false;
this.getList();
} else {
uni.showToast({
@ -285,6 +210,7 @@ export default {
.myTracks-item-img {
margin-right: 20rpx;
border-radius: 8rpx;
image {
width: 130rpx;
height: 130rpx;
@ -307,6 +233,7 @@ export default {
color: $light-color;
padding: 10rpx 0 0 0;
}
.myTracks-action {
display: flex;
justify-content: space-between;