index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view class="page-wrapper history">
  3. <block v-if="list.length>0">
  4. <view class="item area-row" :class="{gary :item.spu.status ==1 }" v-for="(item,index) in list" v-if="item.spu">
  5. <view v-if="isEdit" class="checkbox" @click="historyAllCheck(item,index)">
  6. <text v-if="!item.allCheck" class="iconfont icon-weixuanzhong"></text>
  7. <text v-else class="iconfont icon-xuanzhong1"></text>
  8. </view>
  9. <view class="item item_count" @click="goPage(item)">
  10. <image :src="item.spu.image" mode=""></image>
  11. <view class="info">
  12. <view class="title line2">
  13. <span v-if="item.spu.product_type != 0" :class="'font_bg-red type'+item.spu.product_type">{{item.spu.product_type == 1 ? "秒杀" : item.spu.product_type == 2 ? "预售" : item.spu.product_type == 3 ? "助力" : item.spu.product_type == 4 ? "拼团" : ""}}</span>
  14. {{item.spu.store_name}}</view>
  15. <view class="msg">
  16. <block v-if="item.spu.status == 1">
  17. <view class="price"><text>¥</text>{{item.spu.price}}</view>
  18. <!-- <view class="num">已售{{item.spu.sales}}件</view> -->
  19. </block>
  20. <block v-else>
  21. <view class="tips">该商品已下架</view>
  22. <view class="btn" @click.stop="bindDelete(item,index)">删除</view>
  23. </block>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </block>
  29. <block v-else>
  30. <emptyPage title="暂无浏览记录~"></emptyPage>
  31. </block>
  32. <view class='footer acea-row row-between-wrapper area-edit' v-if="list.length > 0">
  33. <view class="area-item">
  34. <view class="allcheckbox" @click.stop="subDel('empty')">
  35. <text class="iconfont icon-qingkonghuancun"></text>
  36. <text class="text">清空</text>
  37. </view>
  38. </view>
  39. <view class="area-item">
  40. <view class="allcheckbox" @click.stop="handleEdit">
  41. <text class="iconfont icon-bianji2"></text>
  42. <text class="text">编辑</text>
  43. </view>
  44. </view>
  45. </view>
  46. <view class='footer acea-row row-between-wrapper' v-if="isEdit">
  47. <view>
  48. <view class="allcheckbox" @click.stop="checkboxAllChange">
  49. <text v-if="!isAllSelect" class="iconfont icon-weixuanzhong"></text>
  50. <text v-else class="iconfont icon-xuanzhong1"></text>
  51. 全选
  52. </view>
  53. </view>
  54. <view class='button acea-row row-middle'>
  55. <form @submit="subDel('batch')" report-submit='true'>
  56. <button class='bnt' formType="submit">删除</button>
  57. </form>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import emptyPage from '@/components/emptyPage.vue'
  64. import { historyList, historyDelete, historyBatchDelete } from '@/api/user.js'
  65. import { goShopDetail } from '@/libs/order.js'
  66. export default{
  67. components:{
  68. emptyPage
  69. },
  70. data(){
  71. return {
  72. list:[],
  73. isScroll:true,
  74. page:1,
  75. limit:10,
  76. isAllSelect: false,
  77. isEdit: false,
  78. allArr: []
  79. }
  80. },
  81. onShow() {
  82. this.list = [];
  83. this.allArr = [];
  84. this.isScroll = true;
  85. this.page = 1;
  86. this.getList();
  87. this.isAllSelect = false;
  88. this.isEdit = false;
  89. },
  90. methods:{
  91. getList(){
  92. // if(!this.isScroll) return
  93. let that = this
  94. historyList({
  95. page:that.page,
  96. limit:that.limit
  97. }).then(({data})=>{
  98. data.list.forEach((item, index) => {
  99. item.allCheck = false
  100. })
  101. that.isScroll = data.list.length>=that.limit
  102. that.page+=1
  103. that.list = that.list.concat(data.list)
  104. // that.checkboxAllChange();
  105. })
  106. },
  107. // 全选
  108. checkboxAllChange() {
  109. this.isAllSelect = !this.isAllSelect
  110. this.cartAllCheck('allCheck')
  111. },
  112. handleEdit(){
  113. this.isEdit = true;
  114. },
  115. // 删除
  116. subDel: function(type) {
  117. let that = this
  118. let type_id
  119. let content = (type == 'empty') ? '确定清空浏览记录?' : '确定删除浏览记录?'
  120. if(type == 'batch'){
  121. type_id = []
  122. that.list.forEach(el=>{
  123. if(el.allCheck){
  124. type_id.push(el.user_history_id)
  125. }
  126. })
  127. }else{
  128. type_id = 1
  129. }
  130. if(type_id.length == 0 && type == 'batch'){
  131. return that.$util.Tips({
  132. title: '请选择记录'
  133. });
  134. }else{
  135. uni.showModal({
  136. title: '提示',
  137. content: content,
  138. success: function (res) {
  139. if (res.confirm) {
  140. historyBatchDelete({
  141. history_id:type_id,
  142. }).then(res=>{
  143. that.allArr = [];
  144. that.page = 1;
  145. that.list = [];
  146. that.isEdit = false;
  147. that.isScroll = true;
  148. that.getList();
  149. return that.$util.Tips({
  150. title: res.message,
  151. icon: 'success'
  152. });
  153. }).catch(err => {
  154. return that.$util.Tips({
  155. title: err
  156. });
  157. });
  158. }else if (res.cancel) {
  159. return that.$util.Tips({
  160. title: '已取消'
  161. });
  162. }
  163. }
  164. });
  165. }
  166. },
  167. // 商铺全选
  168. historyAllCheck(item, index) {
  169. // 取消
  170. if (item.allCheck) {
  171. item.allCheck = false
  172. } else {
  173. item.allCheck = true
  174. }
  175. this.cartAllCheck('itemCheck')
  176. },
  177. // 删除
  178. bindDelete(item,index){
  179. historyDelete(item.user_history_id).then(res=>{
  180. this.list.splice(index,1)
  181. uni.showToast({
  182. title:res.message,
  183. icon:'none'
  184. })
  185. }).catch(error=>{
  186. uni.showToast({
  187. title:error,
  188. icon:'none'
  189. })
  190. })
  191. },
  192. goPage(item){
  193. goShopDetail(item.spu).then(res => {
  194. uni.navigateTo({
  195. url:`/pages/goods_details/index?id=${item.spu.product_id}`
  196. })
  197. })
  198. },
  199. // 全选判断
  200. cartAllCheck(type) {
  201. this.allArr = []
  202. this.list.forEach((el, index) => {
  203. if(type == 'allCheck'){
  204. el.allCheck = this.isAllSelect
  205. }
  206. if (el.allCheck) this.allArr.push(el)
  207. })
  208. // 全选
  209. this.isAllSelect = this.allArr.length == this.list.length ? true : false
  210. },
  211. },
  212. onReachBottom() {
  213. this.getList()
  214. }
  215. }
  216. </script>
  217. <style lang="scss">
  218. .page-wrapper{
  219. margin-bottom: 96rpx;
  220. .item{
  221. display: flex;
  222. position: relative;
  223. padding:25rpx 20rpx;
  224. background-color: #fff;
  225. -webkit-box-align: center;
  226. -webkit-align-items: center;
  227. align-items: center;
  228. width: 100%;
  229. &.item_count{
  230. &::after{
  231. display: none;
  232. }
  233. }
  234. &:after{
  235. content: ' ';
  236. position: absolute;
  237. left: 20rpx;
  238. right: 0;
  239. bottom: 0;
  240. height: 1px;
  241. background: #f0f0f0;
  242. }
  243. image{
  244. width: 170rpx;
  245. height: 170rpx;
  246. border-radius:6rpx;
  247. }
  248. .info{
  249. flex: 1;
  250. display: flex;
  251. flex-direction: column;
  252. justify-content: space-between;
  253. padding: 5rpx 0;
  254. margin-left: 20rpx;
  255. .title{
  256. font-size: 30rpx;
  257. color: #999;
  258. }
  259. .msg{
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. margin-top: 20rpx;
  264. .price{
  265. color: $theme-color;
  266. font-size: 34rpx;
  267. text{
  268. font-size: 26rpx;
  269. }
  270. }
  271. .num{
  272. font-size: 22rpx;
  273. color: #AAAAAA;
  274. }
  275. .tips{
  276. font-size: 24rpx;
  277. color: #AAAAAA;
  278. }
  279. .btn{
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. width:120rpx;
  284. height:46rpx;
  285. border:1px solid #999;
  286. border-radius:23rpx;
  287. font-size: 26rpx;
  288. color: #999;
  289. }
  290. }
  291. }
  292. &.gary{
  293. .info .title{
  294. color: #333;
  295. }
  296. }
  297. }
  298. }
  299. .history .item .iconfont{
  300. font-size: 40rpx;
  301. color: #CCCCCC;
  302. }
  303. .history .item .icon-xuanzhong1{
  304. color: #E93323;
  305. }
  306. .history .footer {
  307. z-index: 9;
  308. width: 100%;
  309. height: 96rpx;
  310. background-color: #ffffff;
  311. position: fixed;
  312. padding: 0 20rpx;
  313. box-sizing: border-box;
  314. border-top: 1rpx solid #eee;
  315. bottom: var(--window-bottom);
  316. }
  317. .area-edit{
  318. justify-content: center;
  319. .area-item{
  320. width: 50%;
  321. text-align: center;
  322. position: relative;
  323. align-items: center;
  324. color: #333333;
  325. .text{
  326. position: relative;
  327. top: -1px;
  328. }
  329. .iconfont{
  330. color: #333333;
  331. }
  332. &:nth-child(1){
  333. &::after{
  334. content: '';
  335. display: inline-block;
  336. width: 2rpx;
  337. height: 42rpx;
  338. background: #CCCCCC;
  339. position: absolute;
  340. top: 0;
  341. right: 0;
  342. }
  343. }
  344. }
  345. }
  346. .history .footer .checkAll {
  347. font-size: 28rpx;
  348. color: #282828;
  349. margin-left: 16rpx;
  350. }
  351. .allcheckbox .iconfont{
  352. margin-right: 11px;
  353. font-size: 40rpx;
  354. color: #cccccc;
  355. }
  356. .allcheckbox .icon-xuanzhong1{
  357. color: #E93323;
  358. }
  359. .history .footer .button .bnt {
  360. font-size: 28rpx;
  361. color: #999;
  362. border-radius: 50rpx;
  363. border: 1px solid #999;
  364. width: 160rpx;
  365. height: 60rpx;
  366. text-align: center;
  367. line-height: 60rpx;
  368. }
  369. </style>