associated.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <view class="container" :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 @click.stop="goodsCheck(item,index)" v-if="item.check" class="iconfont icon-xuanzhong1"></text>
  23. <text @click.stop="goodsCheck(item,index)" v-else :class="checkedArr.length >=5 ? '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="http://ygs.hqgjsmc.com/baseimg/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 @click.stop="goodsCheck(item,index)" v-if="item.check" class="iconfont icon-xuanzhong1"></text>
  44. <text @click.stop="goodsCheck(item,index)" v-else :class="checkedArr.length >=5 ? '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="http://ygs.hqgjsmc.com/baseimg/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 @click.stop="goodsCheck(item,index)" v-if="item.check" class="iconfont icon-xuanzhong1"></text>
  65. <text @click.stop="goodsCheck(item,index)" v-else :class="checkedArr.length >=5 ? '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="http://ygs.hqgjsmc.com/baseimg/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. import Loading from '@/components/Loading/index.vue';
  90. import { boughtLstApi, collectLstApi, browseLstApi } from "@/api/community";
  91. import { mapGetters } from "vuex";
  92. export default {
  93. props:{
  94. checkedObj: {
  95. type: Array,
  96. default: []
  97. }
  98. },
  99. computed: mapGetters(['viewColor']),
  100. components: { Loading },
  101. data() {
  102. return {
  103. isActive: 0,
  104. loadedb: false,
  105. loadingb: false,
  106. loadedc: false,
  107. loadingc: false,
  108. loadeds: false,
  109. loadings: false,
  110. whereb:{
  111. page: 1,
  112. limit: 10,
  113. keyword: '',
  114. },
  115. wherec:{
  116. page: 1,
  117. limit: 10,
  118. keyword: '',
  119. },
  120. wheres:{
  121. page: 1,
  122. limit: 10,
  123. keyword: '',
  124. },
  125. searchVal: "",
  126. checked: [],
  127. list: [],
  128. collect: [],
  129. bought: [],
  130. browse: [],
  131. checkedArr: this.checkedObj,
  132. };
  133. },
  134. watch: {
  135. },
  136. mounted(){
  137. this.checkedArr = this.checkedObj
  138. this.getBounht();
  139. this.getCollect();
  140. this.getBrowse();
  141. console.log(this.checkedArr)
  142. },
  143. methods: {
  144. // 点击关闭按钮
  145. close() {
  146. this.$emit('close');
  147. },
  148. tabs(index){
  149. this.isActive = index
  150. this.$set(this.whereb, 'keyword', '');
  151. this.$set(this.wherec, 'keyword', '');
  152. this.$set(this.wheres, 'keyword', '');
  153. this.searchVal = ''
  154. this.searchBut()
  155. },
  156. onTouchmove(e){
  157. if (this.loadendb) return;
  158. if (this.loadingb) return;
  159. const query = uni.createSelectorQuery().in(this);
  160. query.select('#goods').boundingClientRect(data => {
  161. console.log(data)
  162. if(data.bottom < 1500 && data.top < 0) {
  163. this.getBounht();
  164. }
  165. }).exec();
  166. // 模拟触底刷新
  167. },
  168. onTouchmove1(e){
  169. if (this.loadendc) return;
  170. if (this.loadingc) return;
  171. const query = uni.createSelectorQuery().in(this);
  172. query.select('#collect').boundingClientRect(data => {
  173. console.log(data)
  174. if(data.bottom < 1500 && data.top < 0) {
  175. this.getCollect();
  176. }
  177. }).exec();
  178. // 模拟触底刷新
  179. },
  180. onTouchmove2(e){
  181. if (this.loadends) return;
  182. if (this.loadings) return;
  183. const query = uni.createSelectorQuery().in(this);
  184. query.select('#browse').boundingClientRect(data => {
  185. console.log(data)
  186. if(data.bottom < 1500 && data.top < 0) {
  187. this.getBrowse();
  188. }
  189. }).exec();
  190. // 模拟触底刷新
  191. },
  192. setValue: function(event) {
  193. this.$set(this.whereb, 'keyword', event.detail.value);
  194. this.$set(this.wherec, 'keyword', event.detail.value);
  195. this.$set(this.wheres, 'keyword', event.detail.value);
  196. },
  197. searchBut(){
  198. this.loadingb=this.loadingc=this.loadings=this.loadedb=this.loadedc=this.loadeds = false
  199. this.whereb.page = this.wherec.page = this.wheres.page = 1
  200. this.bought = this.collect = this.browse = []
  201. this.isActive == 0 ? this.getBounht() : this.isActive == 1 ? this.getCollect() : this.getBrowse()
  202. },
  203. getBounht(){
  204. var that = this;
  205. if(that.loadingb || that.loadedb) return;
  206. that.loadingb = true;
  207. boughtLstApi(that.whereb).then(
  208. res => {
  209. that.loadingb = false;
  210. that.loadedb = res.data.list.length < that.whereb.limit;
  211. that.bought.push.apply(that.bought, res.data.list);
  212. that.whereb.page = that.whereb.page + 1;
  213. that.getInitchecked(that.bought);
  214. },
  215. error => {
  216. that.$util.Tips({
  217. title: error.msg
  218. })
  219. }
  220. );
  221. },
  222. getCollect(){
  223. var that = this;
  224. if(that.loadingc || that.loadedc) return;
  225. that.loadingc = true;
  226. collectLstApi(that.wherec).then(
  227. res => {
  228. that.loadingc = false;
  229. that.loadedc = res.data.list.length < that.wherec.limit;
  230. that.collect.push.apply(that.collect, res.data.list);
  231. that.wherec.page = that.wherec.page + 1;
  232. that.getInitchecked(that.collect);
  233. },
  234. error => {
  235. that.$util.Tips({
  236. title: error.msg
  237. })
  238. }
  239. );
  240. },
  241. getBrowse(){
  242. var that = this;
  243. if(that.loadings || that.loadeds) return;
  244. that.loadings = true;
  245. browseLstApi(that.wheres).then(
  246. res => {
  247. that.loadings = false;
  248. that.loadeds = res.data.list.length < that.wheres.limit;
  249. that.browse.push.apply(that.browse, res.data.list);
  250. that.wheres.page = that.wheres.page + 1;
  251. that.getInitchecked(that.browse);
  252. },
  253. error => {
  254. that.$util.Tips({
  255. title: error.msg
  256. })
  257. }
  258. );
  259. },
  260. /*获取初始化选中的数据*/
  261. getInitchecked(arr){
  262. let that = this;
  263. arr.forEach((item, index) => {
  264. that.$set(item, 'check', false);
  265. that.checkedArr.forEach((val, i) =>{
  266. if((item.spu_id == (val.spu&&val.spu.spu_id)) || (item.spu_id == val.spu_id)){
  267. that.$set(item, 'check', true);
  268. }
  269. })
  270. })
  271. },
  272. /*已选中的商品打钩*/
  273. getCheckedGoods(){
  274. this.checked = []
  275. this.checkedArr.forEach((item, index) => {
  276. this.check.push(item)
  277. })
  278. },
  279. /*点击选中与否*/
  280. goodsCheck(item,index){
  281. this.$set(item, 'check', !item.check);
  282. if(item.check){
  283. this.checkedArr.push(item)
  284. console.log(this.checkedArr)
  285. }else{
  286. this.checkedArr.splice(this.checkedArr.findIndex(itemn => ((itemn.spu_id == item.spu_id) || (item.spu_id == (itemn.spu&&itemn.spu.spu_id)))), 1)
  287. }
  288. },
  289. /*确定提交*/
  290. submit(){
  291. this.$emit('getProduct',this.checkedArr);
  292. },
  293. }
  294. }
  295. </script>
  296. <style lang="scss" scoped>
  297. .container{
  298. background: #ffffff;
  299. border-radius: 16rpx 16rpx 0 0;
  300. padding: 40rpx 0;
  301. position: relative;
  302. .header{
  303. position: relative;
  304. padding: 0 30rpx;
  305. .title{
  306. width: 100%;
  307. text-align: center;
  308. text{
  309. position: relative;
  310. margin: 0 50rpx;
  311. color: #999999;
  312. font-size: 30rpx;
  313. &.on{
  314. color: #333333;
  315. font-weight: bold;
  316. font-size: 34rpx;
  317. &::after{
  318. content: "";
  319. display: inline-block;
  320. width: 40rpx;
  321. height: 5rpx;
  322. background: var(--view-theme);
  323. position: absolute;
  324. bottom: -10rpx;
  325. left: 10rpx;
  326. }
  327. }
  328. }
  329. }
  330. .search{
  331. margin-top: 44rpx;
  332. background: #F5F5F5;
  333. border-radius: 30rpx;
  334. padding: 12rpx 30rpx 12rpx 66rpx;
  335. position: relative;
  336. .iconfont{
  337. font-size: 24rpx;
  338. color: #939393;
  339. position: absolute;
  340. top: 20rpx;
  341. left: 30rpx;
  342. }
  343. .placeholder{
  344. color: #999999;
  345. font-size: 26rpx;
  346. }
  347. }
  348. .sub_title{
  349. color: #282828;
  350. font-size: 26rpx;
  351. margin-top: 30rpx;
  352. }
  353. .iconfont{
  354. color: #8A8A8A;
  355. font-size: 28rpx;
  356. position: absolute;
  357. top: 0;
  358. right: 30rpx;
  359. }
  360. }
  361. scroll-view{
  362. height: 650rpx;
  363. }
  364. .main{
  365. margin: 40rpx 0 80rpx;
  366. padding: 0 30rpx;
  367. }
  368. }
  369. .picTxt {
  370. width: 100%;
  371. padding: 25rpx 0;
  372. position: relative;
  373. align-items: center;
  374. justify-content: space-between;
  375. margin-bottom: 10rpx;
  376. .checkbox {
  377. margin-right: 30rpx;
  378. .iconfont {
  379. font-size: 38rpx;
  380. color: #CCCCCC;
  381. }
  382. .icon-xuanzhong1 {
  383. color: var(--view-theme);
  384. }
  385. .disabled{
  386. pointer-events: none;
  387. cursor: default;
  388. opacity: 0.3;
  389. }
  390. }
  391. .pictrue {
  392. width: 160rpx;
  393. height: 160rpx;
  394. image {
  395. width: 100%;
  396. height: 100%;
  397. border-radius: 8rpx;
  398. }
  399. }
  400. .text {
  401. width: 430rpx;
  402. margin-left: 30rpx;
  403. font-size: 28rpx;
  404. color: #282828;
  405. position: relative;
  406. height: 160rpx;
  407. .name{
  408. color: #282828;
  409. font-size: 28rpx;
  410. }
  411. .money{
  412. position: absolute;
  413. bottom: 0;
  414. left: 0;
  415. color: var(--view-priceColor);
  416. font-size: 22rpx;
  417. font-weight: bold;
  418. text{
  419. font-size: 26rpx;
  420. }
  421. }
  422. }
  423. }
  424. .foot_bar{
  425. width: 100%;
  426. position: fixed;
  427. bottom: 0;
  428. left: 0;
  429. background: #ffffff;
  430. padding: 20rpx 0;
  431. z-index: 5;
  432. .confirm_btn{
  433. width: 710rpx;
  434. height: 86rpx;
  435. line-height: 86rpx;
  436. color: #ffffff;
  437. text-align: center;
  438. font-size: 32rpx;
  439. background: var(--view-theme);
  440. border-radius: 43rpx;
  441. margin: 0 auto;
  442. }
  443. }
  444. .empty{
  445. margin: 130rpx 0 150rpx;
  446. text-align: center;
  447. image,uni-image{
  448. display: inline-block;
  449. width: 414rpx;
  450. height: 305rpx;
  451. }
  452. text{
  453. display: block;
  454. color: #999999;
  455. font-size: 26rpx;
  456. }
  457. }
  458. </style>