associated.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <view class="containers" :style="viewColor">
  3. <view class="header">
  4. <view class="title">
  5. <text :class="isActive == 0 ? 'on' : ''" @click="tabs(0)">已购</text>
  6. <text :class="isActive == 1 ? 'on' : ''" @click="tabs(1)">收藏</text>
  7. <text :class="isActive == 2 ? 'on' : ''" @click="tabs(2)">浏览</text>
  8. </view>
  9. <view class="search">
  10. <text class="iconfont icon-xiazai5"></text>
  11. <input type="text" placeholder="请输入商品名称" v-model="searchVal" @input="setValue" confirm-type="search" @confirm="searchBut()" placeholder-class='placeholder'>
  12. </view>
  13. <view class="sub_title">{{isActive == 0 ? '已购宝贝' : isActive == 1 ?'收藏宝贝' : '浏览记录'}}</view>
  14. <text class="iconfont icon-guanbi5" @click="close"></text>
  15. </view>
  16. <view class="main">
  17. <scroll-view scroll-y="true">
  18. <block v-if="isActive == 0">
  19. <view v-if="bought.length" @touchmove="onTouchmove" id="goods">
  20. <view class="picTxt acea-row" v-for="(item, index) in bought" :key="index">
  21. <view class="checkbox">
  22. <text v-if="item.check" @click.stop="goodsCheck(item,index)" class="iconfont icon-xuanzhong1"></text>
  23. <text v-else @click.stop="goodsCheck(item,index)" :class="{'disabled':disabled}" class="iconfont icon-weixuanzhong"></text>
  24. </view>
  25. <view class='pictrue'>
  26. <image :src='item.image'></image>
  27. </view>
  28. <view class='text'>
  29. <view class='line2 name'>{{item.store_name}}</view>
  30. <view class='money'>¥<text>{{item.price}}</text></view>
  31. </view>
  32. </view>
  33. </view>
  34. <view v-else class="empty">
  35. <image :src="`${domain}/static/images/no_thing.png`"></image>
  36. <text>暂无内容哦~</text>
  37. </view>
  38. </block>
  39. <block v-if="isActive == 1">
  40. <view v-if="collect.length" id="collect" @touchmove="onTouchmove1">
  41. <view class="picTxt acea-row" v-for="(item, index) in collect" :key="index">
  42. <view class="checkbox">
  43. <text v-if="item.check" @click.stop="goodsCheck(item,index)" class="iconfont icon-xuanzhong1"></text>
  44. <text v-else @click.stop="goodsCheck(item,index)" :class="{'disabled':disabled}" class="iconfont icon-weixuanzhong"></text>
  45. </view>
  46. <view class='pictrue'>
  47. <image :src='item.image'></image>
  48. </view>
  49. <view class='text'>
  50. <view class='line2 name'>{{item.store_name}}</view>
  51. <view class='money'>¥<text>{{item.price}}</text></view>
  52. </view>
  53. </view>
  54. </view>
  55. <view v-else class="empty">
  56. <image :src="`${domain}/static/images/no_thing.png`"></image>
  57. <text>暂无内容哦~</text>
  58. </view>
  59. </block>
  60. <block v-if="isActive == 2">
  61. <view v-if="browse.length" id="browse" @touchmove="onTouchmove2">
  62. <view class="picTxt acea-row" v-for="(item, index) in browse" :key="index">
  63. <view class="checkbox">
  64. <text v-if="item.check" @click.stop="goodsCheck(item,index)" class="iconfont icon-xuanzhong1"></text>
  65. <text v-else @click.stop="goodsCheck(item,index)" :class="{'disabled':disabled}" class="iconfont icon-weixuanzhong"></text>
  66. </view>
  67. <view class='pictrue'>
  68. <image :src='item.image'></image>
  69. </view>
  70. <view class='text'>
  71. <view class='line2 name'>{{item.store_name}}</view>
  72. <view class='money'>¥<text>{{item.price}}</text></view>
  73. </view>
  74. </view>
  75. </view>
  76. <view v-else class="empty">
  77. <image :src="`${domain}/static/images/no_thing.png`"></image>
  78. <text>暂无内容哦~</text>
  79. </view>
  80. </block>
  81. </scroll-view>
  82. <view class="foot_bar">
  83. <button class="confirm_btn" @click="submit">确定({{checkedArr.length}})</button>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. // +----------------------------------------------------------------------
  90. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  91. // +----------------------------------------------------------------------
  92. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  93. // +----------------------------------------------------------------------
  94. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  95. // +----------------------------------------------------------------------
  96. // | Author: CRMEB Team <admin@crmeb.com>
  97. // +----------------------------------------------------------------------
  98. import Loading from '@/components/Loading/index.vue';
  99. import { boughtLstApi, collectLstApi, browseLstApi } from "@/api/community";
  100. import { mapGetters } from "vuex";
  101. import { HTTP_REQUEST_URL } from '@/config/app';
  102. export default {
  103. props:{
  104. checkedObj: {
  105. type: Array,
  106. default: []
  107. }
  108. },
  109. computed: mapGetters(['viewColor']),
  110. components: { Loading },
  111. data() {
  112. return {
  113. domain: HTTP_REQUEST_URL,
  114. isActive: 0,
  115. loadedb: false,
  116. loadingb: false,
  117. loadedc: false,
  118. loadingc: false,
  119. loadeds: false,
  120. loadings: false,
  121. whereb:{
  122. page: 1,
  123. limit: 10,
  124. keyword: '',
  125. },
  126. wherec:{
  127. page: 1,
  128. limit: 10,
  129. keyword: '',
  130. },
  131. wheres:{
  132. page: 1,
  133. limit: 10,
  134. keyword: '',
  135. },
  136. searchVal: "",
  137. checked: [],
  138. list: [],
  139. collect: [],
  140. bought: [],
  141. browse: [],
  142. checkedArr: this.checkedObj,
  143. disabled: false,
  144. };
  145. },
  146. watch: {},
  147. mounted(){
  148. this.checkedArr = this.checkedObj
  149. this.getBounht();
  150. this.getCollect();
  151. this.getBrowse();
  152. },
  153. methods: {
  154. // 点击关闭按钮
  155. close() {
  156. this.$emit('close');
  157. },
  158. tabs(index){
  159. this.isActive = index
  160. this.$set(this.whereb, 'keyword', '');
  161. this.$set(this.wherec, 'keyword', '');
  162. this.$set(this.wheres, 'keyword', '');
  163. this.searchVal = ''
  164. this.searchBut()
  165. },
  166. onTouchmove(e){
  167. if (this.loadendb) return;
  168. if (this.loadingb) return;
  169. const query = uni.createSelectorQuery().in(this);
  170. query.select('#goods').boundingClientRect(data => {
  171. if(data.bottom < 1500 && data.top < 0) {
  172. this.getBounht();
  173. }
  174. }).exec();
  175. // 模拟触底刷新
  176. },
  177. onTouchmove1(e){
  178. if (this.loadendc) return;
  179. if (this.loadingc) return;
  180. const query = uni.createSelectorQuery().in(this);
  181. query.select('#collect').boundingClientRect(data => {
  182. if(data.bottom < 1500 && data.top < 0) {
  183. this.getCollect();
  184. }
  185. }).exec();
  186. // 模拟触底刷新
  187. },
  188. onTouchmove2(e){
  189. if (this.loadends) return;
  190. if (this.loadings) return;
  191. const query = uni.createSelectorQuery().in(this);
  192. query.select('#browse').boundingClientRect(data => {
  193. if(data.bottom < 1500 && data.top < 0) {
  194. this.getBrowse();
  195. }
  196. }).exec();
  197. // 模拟触底刷新
  198. },
  199. setValue: function(event) {
  200. this.$set(this.whereb, 'keyword', event.detail.value);
  201. this.$set(this.wherec, 'keyword', event.detail.value);
  202. this.$set(this.wheres, 'keyword', event.detail.value);
  203. },
  204. searchBut(){
  205. this.loadingb=this.loadingc=this.loadings=this.loadedb=this.loadedc=this.loadeds = false
  206. this.whereb.page = this.wherec.page = this.wheres.page = 1
  207. this.bought = this.collect = this.browse = []
  208. this.isActive == 0 ? this.getBounht() : this.isActive == 1 ? this.getCollect() : this.getBrowse()
  209. },
  210. getBounht(){
  211. var that = this;
  212. if(that.loadingb || that.loadedb) return;
  213. that.loadingb = true;
  214. boughtLstApi(that.whereb).then(
  215. res => {
  216. that.loadingb = false;
  217. res.data.list.forEach((item, index) => {
  218. item.check = false;
  219. })
  220. that.loadedb = res.data.list.length < that.whereb.limit;
  221. that.bought.push.apply(that.bought, res.data.list);
  222. that.whereb.page = that.whereb.page + 1;
  223. that.getInitchecked(that.bought);
  224. },
  225. error => {
  226. that.$util.Tips({
  227. title: error.msg
  228. })
  229. }
  230. );
  231. },
  232. getCollect(){
  233. var that = this;
  234. if(that.loadingc || that.loadedc) return;
  235. that.loadingc = true;
  236. collectLstApi(that.wherec).then(
  237. res => {
  238. that.loadingc = false;
  239. res.data.list.forEach((item, index) => {
  240. item.check = false;
  241. })
  242. that.loadedc = res.data.list.length < that.wherec.limit;
  243. that.collect.push.apply(that.collect, res.data.list);
  244. that.wherec.page = that.wherec.page + 1;
  245. that.getInitchecked(that.collect);
  246. },
  247. error => {
  248. that.$util.Tips({
  249. title: error.msg
  250. })
  251. }
  252. );
  253. },
  254. getBrowse(){
  255. var that = this;
  256. if(that.loadings || that.loadeds) return;
  257. that.loadings = true;
  258. browseLstApi(that.wheres).then(
  259. res => {
  260. that.loadings = false;
  261. res.data.list.forEach((item, index) => {
  262. item.check = false;
  263. })
  264. that.loadeds = res.data.list.length < that.wheres.limit;
  265. that.browse.push.apply(that.browse, res.data.list);
  266. that.wheres.page = that.wheres.page + 1;
  267. that.getInitchecked(that.browse);
  268. },
  269. error => {
  270. that.$util.Tips({
  271. title: error.msg
  272. })
  273. }
  274. );
  275. },
  276. /*获取初始化选中的数据*/
  277. getInitchecked(arr){
  278. let that = this;
  279. arr.forEach((item, index) => {
  280. that.$set(item, 'check', false);
  281. that.checkedArr.forEach((val, i) =>{
  282. if((item.spu_id == (val.spu&&val.spu.spu_id)) || (item.spu_id == val.spu_id)){
  283. that.$set(item, 'check', true);
  284. }
  285. })
  286. })
  287. },
  288. /*点击选中与否*/
  289. goodsCheck(item,index){
  290. if(this.checkedArr.length > 4 && !item.check){
  291. return ;
  292. }
  293. if(!item.check){
  294. this.$set(item, 'check', true);
  295. this.checkedArr.push(item)
  296. }else{
  297. this.$set(item, 'check', false);
  298. let idx = this.checkedArr.findIndex(itemn => (itemn.spu_id == item.spu_id))
  299. this.checkedArr.splice(idx, 1)
  300. }
  301. this.disabled = this.checkedArr.length > 4
  302. },
  303. /*确定提交*/
  304. submit(){
  305. this.$emit('getProduct',this.checkedArr);
  306. },
  307. }
  308. }
  309. </script>
  310. <style lang="scss" scoped>
  311. .containers{
  312. background: #ffffff;
  313. border-radius: 16rpx 16rpx 0 0;
  314. padding: 40rpx 0;
  315. position: relative;
  316. .header{
  317. position: relative;
  318. padding: 0 30rpx;
  319. .title{
  320. width: 100%;
  321. text-align: center;
  322. text{
  323. position: relative;
  324. margin: 0 50rpx;
  325. color: #999999;
  326. font-size: 30rpx;
  327. &.on{
  328. color: #333333;
  329. font-weight: bold;
  330. font-size: 34rpx;
  331. &::after{
  332. content: "";
  333. display: inline-block;
  334. width: 40rpx;
  335. height: 5rpx;
  336. background: var(--view-theme);
  337. position: absolute;
  338. bottom: -10rpx;
  339. left: 10rpx;
  340. }
  341. }
  342. }
  343. }
  344. .search{
  345. margin-top: 44rpx;
  346. background: #F5F5F5;
  347. border-radius: 30rpx;
  348. padding: 12rpx 30rpx 12rpx 66rpx;
  349. position: relative;
  350. .iconfont{
  351. font-size: 24rpx;
  352. color: #939393;
  353. position: absolute;
  354. top: 20rpx;
  355. left: 30rpx;
  356. }
  357. .placeholder{
  358. color: #999999;
  359. font-size: 26rpx;
  360. }
  361. }
  362. .sub_title{
  363. color: #282828;
  364. font-size: 26rpx;
  365. margin-top: 30rpx;
  366. }
  367. .iconfont{
  368. color: #8A8A8A;
  369. font-size: 28rpx;
  370. position: absolute;
  371. top: 0;
  372. right: 30rpx;
  373. }
  374. }
  375. scroll-view{
  376. height: 650rpx;
  377. }
  378. .main{
  379. height: 650rpx;
  380. margin: 40rpx 0 80rpx;
  381. padding: 0 30rpx;
  382. }
  383. }
  384. .picTxt {
  385. width: 100%;
  386. padding: 25rpx 0;
  387. position: relative;
  388. align-items: center;
  389. justify-content: space-between;
  390. margin-bottom: 10rpx;
  391. .checkbox {
  392. margin-right: 30rpx;
  393. .iconfont {
  394. font-size: 38rpx;
  395. color: #CCCCCC;
  396. }
  397. .icon-xuanzhong1 {
  398. color: var(--view-theme);
  399. }
  400. .disabled{
  401. pointer-events: none;
  402. cursor: default;
  403. opacity: 0.3;
  404. }
  405. }
  406. .pictrue {
  407. width: 160rpx;
  408. height: 160rpx;
  409. image {
  410. width: 100%;
  411. height: 100%;
  412. border-radius: 8rpx;
  413. }
  414. }
  415. .text {
  416. width: 430rpx;
  417. margin-left: 30rpx;
  418. font-size: 28rpx;
  419. color: #282828;
  420. position: relative;
  421. height: 160rpx;
  422. .name{
  423. color: #282828;
  424. font-size: 28rpx;
  425. }
  426. .money{
  427. position: absolute;
  428. bottom: 0;
  429. left: 0;
  430. color: var(--view-priceColor);
  431. font-size: 22rpx;
  432. font-weight: bold;
  433. text{
  434. font-size: 26rpx;
  435. }
  436. }
  437. }
  438. }
  439. .foot_bar{
  440. width: 100%;
  441. position: fixed;
  442. bottom: 0;
  443. left: 0;
  444. background: #ffffff;
  445. padding: 20rpx 0;
  446. z-index: 5;
  447. .confirm_btn{
  448. width: 710rpx;
  449. height: 86rpx;
  450. line-height: 86rpx;
  451. color: #ffffff;
  452. text-align: center;
  453. font-size: 32rpx;
  454. background: var(--view-theme);
  455. border-radius: 43rpx;
  456. margin: 0 auto;
  457. }
  458. }
  459. .empty{
  460. margin: 130rpx 0 150rpx;
  461. text-align: center;
  462. image,uni-image{
  463. display: inline-block;
  464. width: 414rpx;
  465. height: 305rpx;
  466. }
  467. text{
  468. display: block;
  469. color: #999999;
  470. font-size: 26rpx;
  471. }
  472. }
  473. </style>