associatedProduct.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <view class="containers" :data-theme="theme">
  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. <text class="iconfont icon-guanbi5" @click="close"></text>
  10. </view>
  11. <view class="main borderPad">
  12. <scroll-view scroll-y="true" class="scroll" @scrolltolower="onScrolltolower" @touchmove.stop>
  13. <view v-if="isActive == 0">
  14. <view v-if="bought.length" id="goods">
  15. <view class="picTxt acea-row" v-for="(item, index) in bought" :key="index"
  16. @click.stop="goodsCheck(item,index,bought)">
  17. <view class="checkbox">
  18. <text v-if="item.check" class="iconfont icon-xuanzhong1"></text>
  19. <text v-else :class="{'disabled':disabled}" class="iconfont icon-weixuanzhong"></text>
  20. </view>
  21. <view class='pictrue'>
  22. <image :src='item.image'></image>
  23. </view>
  24. <view class='text'>
  25. <view class='line2 name'>{{item.name}}</view>
  26. <view class='money'>¥<text>{{item.price}}</text></view>
  27. </view>
  28. </view>
  29. </view>
  30. <view v-if="bought.length===0 && !loadingb" class="empty">
  31. <image :src="urlDomain+'crmebimage/presets/noShopper.png'"></image>
  32. <text>暂无商品哦~</text>
  33. </view>
  34. </view>
  35. <view v-if="isActive == 1">
  36. <view v-if="collect.length" id="collect">
  37. <view class="picTxt acea-row" v-for="(item, index) in collect" :key="index"
  38. @click.stop="goodsCheck(item,index,collect)">
  39. <view class="checkbox">
  40. <text v-if="item.check" class="iconfont icon-xuanzhong1"></text>
  41. <text v-else :class="{'disabled':disabled}" class="iconfont icon-weixuanzhong"></text>
  42. </view>
  43. <view class='pictrue'>
  44. <image :src='item.image'></image>
  45. </view>
  46. <view class='text'>
  47. <view class='line2 name'>{{item.name}}</view>
  48. <view class='money'>¥<text>{{item.price}}</text></view>
  49. </view>
  50. </view>
  51. </view>
  52. <view v-if="collect.length===0 && !loadingc" class="empty">
  53. <image :src="urlDomain+'crmebimage/presets/noShopper.png'"></image>
  54. <text>暂无商品哦~</text>
  55. </view>
  56. </view>
  57. <view v-if="isActive == 2">
  58. <view v-if="browse.length" id="browse">
  59. <view class="picTxt acea-row" v-for="(item, index) in browse" :key="index"
  60. @click.stop="goodsCheck(item,index,browse)">
  61. <view class="checkbox">
  62. <text v-if="item.check" class="iconfont icon-xuanzhong1"></text>
  63. <text v-else :class="{'disabled':disabled}" class="iconfont icon-weixuanzhong"></text>
  64. </view>
  65. <view class='pictrue'>
  66. <image :src='item.image'></image>
  67. </view>
  68. <view class='text'>
  69. <view class='line2 name'>{{item.name}}</view>
  70. <view class='money'>¥<text>{{item.price}}</text></view>
  71. </view>
  72. </view>
  73. </view>
  74. <view v-if="browse.length===0 && !loadings" class="empty">
  75. <image :src="urlDomain+'crmebimage/presets/noShopper.png'"></image>
  76. <text>暂无商品哦~</text>
  77. </view>
  78. </view>
  79. <view class="acea-row row-center-wrapper loadingicon">
  80. <text :hidden="!loadingb || !loadingc || !loadings"
  81. class="iconfont icon-jiazai loading"></text>{{(isActive == 0 &&bought.length>0) || (isActive == 1 &&collect.length>0) || (isActive == 2 &&browse.length>0) ?loadTitle:''}}
  82. </view>
  83. </scroll-view>
  84. <view class="foot_bar">
  85. <button class="confirm_btn" @click="submit">确定({{checkedArr.length}}/5)</button>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import {
  92. purchasedApi,
  93. getCollectUserList,
  94. proBrowseApi
  95. } from "@/api/product";
  96. import {
  97. browseRecordApi
  98. } from "@/api/user";
  99. import {
  100. mapGetters
  101. } from "vuex";
  102. let app = getApp();
  103. export default {
  104. props: {
  105. checkedObj: {
  106. type: Array,
  107. default: []
  108. }
  109. },
  110. data() {
  111. return {
  112. urlDomain: this.$Cache.get("imgHost"),
  113. loadTitle: '加载更多',
  114. theme: app.globalData.theme,
  115. isActive: 0,
  116. loadedb: false,
  117. loadingb: false,
  118. loadedc: false,
  119. loadingc: false,
  120. loadeds: false,
  121. loadings: false,
  122. whereb: {
  123. page: 1,
  124. limit: 10,
  125. },
  126. wherec: {
  127. page: 1,
  128. limit: 10,
  129. },
  130. wheres: {
  131. page: 1,
  132. limit: 10,
  133. },
  134. searchVal: "",
  135. checked: [],
  136. list: [],
  137. collect: [],
  138. bought: [],
  139. browse: [],
  140. checkedArr: this.checkedObj,
  141. disabled: false
  142. };
  143. },
  144. watch: {
  145. checkedObj: {
  146. handler(n) {
  147. this.checkedArr = n
  148. },
  149. deep: true
  150. }
  151. },
  152. mounted() {
  153. this.checkedArr = this.checkedObj
  154. this.getBounht();
  155. this.getCollect();
  156. this.getBrowse();
  157. },
  158. methods: {
  159. onScrolltolower() {
  160. if (this.isActive == 0) {
  161. this.getBounht();
  162. } else if (this.isActive == 1) {
  163. this.getCollect();
  164. } else {
  165. this.getBrowse();
  166. }
  167. },
  168. // 点击关闭按钮
  169. close() {
  170. this.$emit('close');
  171. },
  172. tabs(index) {
  173. this.isActive = index
  174. this.searchVal = ''
  175. this.searchBut()
  176. },
  177. searchBut() {
  178. this.loadingb = this.loadingc = this.loadings = this.loadedb = this.loadedc = this.loadeds = false
  179. this.whereb.page = this.wherec.page = this.wheres.page = 1
  180. this.bought = this.collect = this.browse = []
  181. this.isActive == 0 ? this.getBounht() : this.isActive == 1 ? this.getCollect() : this.getBrowse()
  182. },
  183. //已购
  184. getBounht() {
  185. var that = this;
  186. if (that.loadingb || that.loadedb) return;
  187. that.loadingb = true;
  188. purchasedApi(that.whereb).then(
  189. res => {
  190. that.loadedb = res.data.list.length < that.whereb.limit;
  191. that.bought.push.apply(that.bought, res.data.list);
  192. that.whereb.page = that.whereb.page + 1;
  193. that.loadTitle = that.loadedb ? '没有了' : '加载更多';
  194. that.getInitchecked(that.bought);
  195. that.loadingb = false;
  196. },
  197. error => {
  198. that.$util.Tips({
  199. title: error
  200. })
  201. }
  202. );
  203. },
  204. //收藏
  205. getCollect() {
  206. var that = this;
  207. if (that.loadingc || that.loadedc) return;
  208. that.loadingc = true;
  209. getCollectUserList(that.wherec).then(
  210. res => {
  211. that.loadedc = res.data.list.length < that.wherec.limit;
  212. that.collect.push.apply(that.collect, res.data.list);
  213. that.wherec.page = that.wherec.page + 1;
  214. that.loadTitle = that.loadedc ? '没有了' : '加载更多';
  215. that.getInitchecked(that.collect);
  216. that.loadingc = false;
  217. },
  218. error => {
  219. that.$util.Tips({
  220. title: error
  221. })
  222. }
  223. );
  224. },
  225. //足迹
  226. getBrowse() {
  227. var that = this;
  228. if (that.loadings || that.loadeds) return;
  229. that.loadings = true;
  230. proBrowseApi(that.wheres).then(
  231. res => {
  232. that.loadeds = res.data.list.length < that.wheres.limit;
  233. that.browse.push.apply(that.browse, res.data.list);
  234. that.wheres.page = that.wheres.page + 1;
  235. that.loadTitle = that.loadeds ? '没有了' : '加载更多';
  236. that.getInitchecked(that.browse);
  237. that.loadings = false;
  238. },
  239. error => {
  240. that.$util.Tips({
  241. title: error
  242. })
  243. }
  244. );
  245. },
  246. /*获取初始化选中的数据*/
  247. getInitchecked(arr) {
  248. let that = this;
  249. arr.forEach((item, index) => {
  250. that.$set(item, 'check', false);
  251. that.checkedArr.forEach((val, i) => {
  252. if ((item.productId == val.productId)) {
  253. that.$set(item, 'check', true);
  254. }
  255. })
  256. })
  257. },
  258. /*点击选中与否*/
  259. goodsCheck(item, index, list) {
  260. if (this.checkedArr.length > 4 && !item.check) {
  261. return;
  262. }
  263. list.forEach((val, i) => {
  264. if ((val.productId == item.productId)) {
  265. this.$set(val, 'check', !val.check);
  266. }
  267. })
  268. if (item.check) {
  269. this.checkedArr.push(item)
  270. } else {
  271. this.checkedArr.splice(this.checkedArr.findIndex(itemn => ((itemn.productId == item.productId))), 1)
  272. }
  273. this.disabled = this.checkedArr.length > 4
  274. },
  275. /*确定提交*/
  276. submit() {
  277. this.$emit('getProduct', this.checkedArr);
  278. },
  279. }
  280. }
  281. </script>
  282. <style lang="scss" scoped>
  283. .containers {
  284. background: #ffffff;
  285. border-radius: 16rpx 16rpx 0 0;
  286. padding: 34rpx 0;
  287. position: relative;
  288. height: 100%;
  289. .header {
  290. position: relative;
  291. padding: 0 30rpx;
  292. .title {
  293. width: 100%;
  294. text-align: center;
  295. text {
  296. position: relative;
  297. margin: 0 50rpx;
  298. color: #999999;
  299. font-size: 30rpx;
  300. &.on {
  301. color: #333333;
  302. font-weight: bold;
  303. font-size: 34rpx;
  304. &::after {
  305. content: "";
  306. display: inline-block;
  307. width: 40rpx;
  308. height: 5rpx;
  309. @include main_bg_color(theme);
  310. position: absolute;
  311. bottom: -14rpx;
  312. left: 10rpx;
  313. }
  314. }
  315. }
  316. }
  317. .search {
  318. margin-top: 44rpx;
  319. background: #F5F5F5;
  320. border-radius: 30rpx;
  321. padding: 12rpx 30rpx 12rpx 66rpx;
  322. position: relative;
  323. .iconfont {
  324. font-size: 24rpx;
  325. color: #939393;
  326. position: absolute;
  327. top: 20rpx;
  328. left: 30rpx;
  329. }
  330. .placeholder {
  331. color: #999999;
  332. font-size: 26rpx;
  333. }
  334. }
  335. .sub_title {
  336. color: #282828;
  337. font-size: 26rpx;
  338. margin-top: 40rpx;
  339. }
  340. .iconfont {
  341. color: #8A8A8A;
  342. font-size: 28rpx;
  343. position: absolute;
  344. top: 0;
  345. right: 30rpx;
  346. }
  347. }
  348. scroll-view {
  349. height: 88% !important;
  350. }
  351. .main {
  352. height: 100%;
  353. margin: 40rpx 0 80rpx;
  354. /deep/.uni-scroll-view-content {
  355. height: auto;
  356. }
  357. .scroll {
  358. overflow-y: scroll;
  359. }
  360. }
  361. }
  362. .picTxt {
  363. width: 100%;
  364. position: relative;
  365. align-items: center;
  366. justify-content: space-between;
  367. margin-bottom: 30rpx;
  368. .checkbox {
  369. margin-right: 4rpx;
  370. .iconfont {
  371. font-size: 38rpx;
  372. color: #CCCCCC;
  373. }
  374. .icon-xuanzhong1 {
  375. @include main_color(theme);
  376. }
  377. .disabled {
  378. pointer-events: none;
  379. cursor: default;
  380. opacity: 0.3;
  381. }
  382. }
  383. .pictrue {
  384. width: 160rpx;
  385. height: 160rpx;
  386. image {
  387. width: 100%;
  388. height: 100%;
  389. border-radius: 8rpx;
  390. }
  391. }
  392. .text {
  393. width: 450rpx;
  394. margin-left: 20rpx;
  395. font-size: 28rpx;
  396. color: #282828;
  397. position: relative;
  398. height: 160rpx;
  399. .name {
  400. color: #282828;
  401. font-size: 30rpx;
  402. font-weight: 600;
  403. }
  404. .money {
  405. position: absolute;
  406. bottom: 0;
  407. left: 0;
  408. @include main_color(theme);
  409. font-size: 26rpx;
  410. font-weight: bold;
  411. text {
  412. font-size: 34rpx;
  413. }
  414. }
  415. }
  416. }
  417. .foot_bar {
  418. width: 100%;
  419. position: fixed;
  420. bottom: 30rpx;
  421. left: 0;
  422. background: #ffffff;
  423. padding: 0 0 30rpx 0;
  424. z-index: 5;
  425. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  426. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  427. .confirm_btn {
  428. width: 710rpx;
  429. height: 86rpx;
  430. line-height: 86rpx;
  431. color: #ffffff;
  432. text-align: center;
  433. font-size: 32rpx;
  434. @include main_bg_color(theme);
  435. border-radius: 43rpx;
  436. margin: 0 auto;
  437. }
  438. }
  439. .empty {
  440. margin: 130rpx 0 150rpx;
  441. text-align: center;
  442. image,
  443. uni-image {
  444. display: inline-block;
  445. width: 414rpx;
  446. height: 305rpx;
  447. }
  448. text {
  449. display: block;
  450. color: #999999;
  451. font-size: 26rpx;
  452. }
  453. }
  454. </style>