index.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. <template>
  2. <!-- 商品列表 -->
  3. <view :style="colorStyle">
  4. <view class="header_box fixed-lt w-full z-200 bg--w111-fff" :style="{'padding-top': sysHeight + 'px'}">
  5. <view class="h-80 px-20 flex-y-center">
  6. <text class="iconfont icon-ic_leftarrow fs-40 mr-16" @tap="goBack"></text>
  7. <view class="flex-1 h-58 rd-30 bg--w111-f5f5f5 flex-y-center px-32 relative">
  8. <text class="iconfont icon-ic_search fs-24"></text>
  9. <input :value='where.keyword' class="pl-18 w-460 line1 fs-24" placeholder="请输入商品名称" @confirm="searchSubmit" />
  10. <text class="iconfont icon-ic_close1 fs-28 text--w111-999 z-10" v-if="where.keyword" @tap="clearWord"></text>
  11. </view>
  12. <!-- 胶囊占据的位置 -->
  13. <!-- #ifdef MP -->
  14. <view class="ml-12" :style="'width:'+getHeight.barWidth+'px'"></view>
  15. <!-- #endif -->
  16. </view>
  17. <scroll-view scroll-x="true" class="white-nowrap vertical-middle w-full pl-32"
  18. show-scrollbar="false" v-if="cateSearch">
  19. <view class="inline-block fs-30 h-80 lh-80rpx mr-40"
  20. v-for="item in filterCateList" :key="item.id"
  21. :class="item.id == where.sid ? 'text-primary-con fw-500 fs-32' : ''"
  22. @tap="cateCheck(item)">{{item.cate_name}}</view>
  23. </scroll-view>
  24. <view class="h-88 px-32 flex-between-center relative">
  25. <view class="text--w111-333 fw-500 select_cate relative" v-if="!cateSearch && title">{{title}}</view>
  26. <view class="text--w111-333 fs-26 fw-500 flex-y-center" v-else @tap="toggleSortable">
  27. <text>综合排序</text>
  28. <text class="iconfont icon-ic_down2 fs-14 ml-6"></text>
  29. </view>
  30. <view class="text--w111-666 flex-y-center fs-26" @tap='set_where(3)'>
  31. <text :class="[1,2].includes(stock) ? 'text-primary-con' : ''">销量</text>
  32. <text v-show="stock==2" class="iconfont icon-ic_down2 fs-14 ml-6 text-primary-con"></text>
  33. <text v-show="stock==1" class="iconfont icon-ic_up2 fs-14 ml-6 text-primary-con"></text>
  34. <text v-show="stock==0" class="iconfont icon-ic_down2 fs-14 ml-6"></text>
  35. </view>
  36. <view class="text--w111-666 flex-y-center fs-26" @tap='set_where(2)'>
  37. <text :class="[1,2].includes(price) ? 'text-primary-con' : ''">价格</text>
  38. <text v-show="price==2" class="iconfont icon-ic_down2 fs-14 ml-6 text-primary-con"></text>
  39. <text v-show="price==1" class="iconfont icon-ic_up2 fs-14 ml-6 text-primary-con"></text>
  40. <text v-show="price==0" class="iconfont icon-ic_down2 fs-14 ml-6"></text>
  41. </view>
  42. <view class="text--w111-666 flex-y-center fs-26">
  43. <text class="iconfont" :class="is_switch ? 'icon-a-ic_Imageandtextsorting' : 'icon-a-ic_QRcode'" @tap='Changswitch'></text>
  44. <text class="menu_line"></text>
  45. <view @tap="showFilterDrawer = true">筛选</view>
  46. <text class="iconfont icon-ic_sort pl-8" @tap="showFilterDrawer = true"></text>
  47. </view>
  48. <view class="sortable-box w-full bg--w111-fff rd-b-24rpx z-999" v-if="showSortAbleBox">
  49. <view class="flex-between-center pb-40"
  50. v-for="(item, index) in sortableShowTab" :key="index" @tap="checkSortable(item.value)">
  51. <text class="fs-26" :class="item.value == where.defaultOrder ? 'text-primary-con' : 'text--w111-333'">{{item.title}}</text>
  52. <image class="w-28 h-28" src="../static/dui-icon.png" v-show="item.value == where.defaultOrder"></image>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="pt-12 pb-16 flex-y-center bg--w111-fff" v-if="(promotionList.length && !cateSearch) || where.promotions_id">
  57. <scroll-view scroll-x="true" class="white-nowrap vertical-middle w-full" show-scrollbar="false">
  58. <view
  59. class="inline-block op-border ml-24 h-48 lh-48rpx bg--w111-f5f5f5 px-24 rd-24 text-center fs-22 text--w111-333"
  60. v-for="item in promotionList" :key="item.id"
  61. :class="where.promotions_id == item.id ? 'active' : ''"
  62. @tap="promotionTap(item)">
  63. <text class="w-full line1 text-center">{{item.desc}}</text>
  64. </view>
  65. </scroll-view>
  66. </view>
  67. </view>
  68. <view class="pt-32 pl-20 pr-20 bg--w111-fff pb-10" :style="{'margin-top':marTop + 'rpx'}" v-if="is_switch==false">
  69. <view class="flex mb-32 pro_item" v-for="(item,index) in productList" :key="index" @tap="goDetail(item)">
  70. <view class="list-pic w-240 h-240 relative">
  71. <easy-loadimage
  72. mode="widthFix"
  73. :image-src="item.image"
  74. :borderSrc="item.activity_frame.image"
  75. width="240rpx"
  76. height="240rpx"
  77. borderRadius="20rpx"></easy-loadimage>
  78. </view>
  79. <view class="flex-1 pl-20 flex-col justify-between">
  80. <view class="w-full">
  81. <view class="w-full line2 fs-28 text--w111-333 lh-40rpx">{{item.store_name}}</view>
  82. <view class="w-full flex items-end flex-wrap mt-16">
  83. <BaseTag
  84. :text="label.label_name"
  85. :color="label.color"
  86. :background="label.bg_color"
  87. :borderColor="label.border_color"
  88. :circle="label.border_color ? true : false"
  89. :imgSrc="label.icon"
  90. v-for="(label, idx) in item.store_label" :key="idx"></BaseTag>
  91. </view>
  92. </view>
  93. <view class="flex-y-center">
  94. <baseMoney :money="item.price" symbolSize="24" integerSize="40" decimalSize="24" weight></baseMoney>
  95. <view class="inline-block h-26 lh-28rpx rd-14rpx bg--w111-F7E9CD fs-22 ml-8" v-if="Number(item.vip_price) > 0">
  96. <text class="inline-block h-26 lh-28rpx svip_rd fs-18 bg--w111-484643 text--w111-FDDAA4 px-8">SVIP</text>
  97. <text class="px-8 fs-22">¥{{item.vip_price}}</text>
  98. </view>
  99. </view>
  100. <view class="text--w111-999 fs-22">
  101. <text>已售{{item.sales}}件</text>
  102. <text class="pl-16">评分 {{item.star}}</text>
  103. </view>
  104. </view>
  105. </view>
  106. </view>
  107. <view class="pl-20 pr-20 pb-20 pt-32 relative" :style="{'margin-top':marTop + 'rpx'}" v-else>
  108. <view class="jinabian"></view>
  109. <waterfallsFlow ref="waterfallsFlow" :wfList="productList" @itemTap="goDetail"></waterfallsFlow>
  110. </view>
  111. <view class='loadingicon acea-row row-center-wrapper' v-if='productList.length > 0'>
  112. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  113. </view>
  114. <view class='px-20' v-if="productList.length==0 && where.page > 1">
  115. <emptyPage :title="where.keyword ? '无搜索结果,换个词试试吧' : '暂无商品,去看点别的吧~'"
  116. :src="where.keyword ? '/statics/images/noSearch.gif' : '/statics/images/empty-box.gif'"></emptyPage>
  117. <recommend :hostProduct="hostProduct"></recommend>
  118. </view>
  119. <productWindow
  120. :attr="attr"
  121. :isShow='1'
  122. :iSplus='1'
  123. :iScart='1'
  124. :type="2"
  125. :storeInfo='storeInfo'
  126. @myevent="onMyEvent"
  127. @ChangeAttr="ChangeAttr"
  128. @ChangeCartNum="ChangeCartNumDuo"
  129. @attrVal="attrVal"
  130. @iptCartNum="iptCartNum"
  131. @goCat="goCatNum"
  132. id='product-window'
  133. :is_vip="is_vip" :fangda='false'></productWindow>
  134. <filterDrawer
  135. :visible="showFilterDrawer"
  136. :promotionId="where.promotions_id"
  137. :brandList="brandList"
  138. :labelList="labelList"
  139. :promotionList="promotionList"
  140. @closeDrawer="()=>{showFilterDrawer = false}"
  141. @filterChange="filterConfirm"></filterDrawer>
  142. <view class="mask" v-if="showSortAbleBox" @tap="showSortAbleBox = false"></view>
  143. </view>
  144. </template>
  145. <script>
  146. let sysHeight = uni.getSystemInfoSync().statusBarHeight;
  147. import homeList from '@/components/homeList';
  148. import productWindow from '@/components/productWindow';
  149. import waterfallsFlow from "@/components/WaterfallsFlow/WaterfallsFlow.vue";
  150. import {
  151. getProductslist,
  152. getProductHot,
  153. searchFilterApi,
  154. levelCategoryApi,
  155. getAttr,
  156. postCartAdd,
  157. postCartNum
  158. } from '@/api/store.js';
  159. import {
  160. toLogin
  161. } from '@/libs/login.js';
  162. import recommend from '@/components/recommend';
  163. import filterDrawer from '../components/filterDrwer/index.vue';
  164. import emptyPage from '@/components/emptyPage.vue';
  165. import { mapGetters } from "vuex";
  166. import { goShopDetail } from '@/libs/order.js';
  167. import { getCartList, getCartCounts } from '@/api/order.js';
  168. import colors from '@/mixins/color.js';
  169. import { HTTP_REQUEST_URL } from '@/config/app';
  170. export default {
  171. computed: {
  172. ...mapGetters(['uid', 'isLogin'])
  173. },
  174. components: {
  175. recommend,
  176. homeList,
  177. waterfallsFlow,
  178. productWindow,
  179. filterDrawer,
  180. emptyPage
  181. },
  182. mixins: [colors],
  183. data() {
  184. return {
  185. id: 0,
  186. productValue: [], //系统属性
  187. is_vip: 0, //是否是会员
  188. attr: {
  189. cartAttr: false,
  190. productAttr: [],
  191. productSelect: {}
  192. },
  193. attrValue: '', //已选属性
  194. sysHeight: sysHeight,
  195. goodList: true,
  196. currentPage: false,
  197. productList: [],
  198. is_switch: true,
  199. where: {
  200. sid: 0,
  201. keyword: '',
  202. priceOrder: '',
  203. salesOrder: '',
  204. news: 0,
  205. page: 1,
  206. limit: 8,
  207. cid: 0,
  208. tid: 0,
  209. brand_id: '',
  210. promotions_id: 0,
  211. promotions_type:0,
  212. defaultOrder:0,
  213. give_award_range:0,//报单商品
  214. join_games:0,//抽奖商品
  215. },
  216. price: 0,
  217. stock: 0,
  218. nows: false,
  219. loadend: false,
  220. loading: false,
  221. loadTitle: '加载更多',
  222. title: '',
  223. hostProduct: [],
  224. hotPage: 1,
  225. hotLimit: 10,
  226. hotScroll: false,
  227. brandList: [],
  228. promotionList:[],
  229. labelList:[],
  230. filterCateList:[],
  231. storeInfo: {},
  232. totalPrice: 0,
  233. promotionsInfo: {},
  234. totalNum: 0,
  235. imgHost: HTTP_REQUEST_URL,
  236. isShowAuth: false,
  237. marTop:'',
  238. showFilterDrawer:false,
  239. cateSearch:false,
  240. showSortAbleBox:false,
  241. sortableShowTab:[
  242. {title:'综合排序',value:0},
  243. {title:'好评优先',value:1},
  244. {title:'新品优先',value:2},
  245. ],
  246. getHeight: this.$util.getWXStatusHeight()
  247. };
  248. },
  249. onLoad: function(options) {
  250. this.where.cid = options.cid || 0;
  251. this.$set(this.where, 'sid', options.sid || 0);
  252. this.$set(this.where, 'tid', options.tid || 0);
  253. this.title = options.title || '';
  254. this.$set(this.where, 'keyword', options.searchValue || '');
  255. this.$set(this.where, 'productId', options.productId || '');
  256. this.$set(this.where, 'brand_id', options.brandId || 0);
  257. console.log(options)
  258. // 判断是否报单商品
  259. if(options.awardRange){
  260. this.where.give_award_range=1;
  261. }
  262. // 判断是否抽奖商品
  263. if(options.joinGame){
  264. this.where.join_games=1;
  265. }
  266. if (options.promotions_type) {
  267. this.where.promotions_type = options.promotions_type;
  268. this.where.promotions_id = options.promotions_id;
  269. this.is_switch = false
  270. }
  271. if(options.sid){
  272. //用于判断顶部分类选择内容是否展示
  273. this.cateSearch = true;
  274. this.getProCate();
  275. }
  276. this.getProductList();
  277. this.getSearchFilter();
  278. this.marTop = (115 + sysHeight) * 2;
  279. },
  280. onShow() {
  281. uni.removeStorageSync('form_type_cart');
  282. if (this.isLogin && !this.is_switch) {
  283. this.getCartList();
  284. this.getCartNum();
  285. }
  286. },
  287. created() {
  288. this.$eventHub.$on('onCartAddChange',(data)=>{
  289. if(data.spec_type){
  290. this.goCartDuo(data);
  291. }else{
  292. this.goCartDan(data);
  293. }
  294. });
  295. },
  296. methods: {
  297. getCartNum() {
  298. getCartCounts().then(res => {
  299. this.totalNum = res.data.count;
  300. }).catch(err => {
  301. return this.$util.Tips({
  302. title: err
  303. });
  304. })
  305. },
  306. getCartList() {
  307. let truePrice = 0;
  308. getCartList().then(res => {
  309. let data = res.data,
  310. valid = res.data.valid;
  311. valid.forEach(item => {
  312. item.promotions.forEach(z => {
  313. if (this.where.promotions_id == z.id) {
  314. this.promotionsInfo = z;
  315. }
  316. })
  317. item.cart.forEach(j => {
  318. truePrice = this.$util.$h.Add(truePrice, this.$util.$h.Mul(j.truePrice,
  319. j.cart_num));
  320. })
  321. })
  322. this.totalPrice = this.$util.$h.Sub(truePrice, data.deduction.coupon_price)
  323. }).catch(err => {
  324. return this.$util.Tips({
  325. title: err
  326. });
  327. })
  328. },
  329. goCart() {
  330. if (this.where.promotions_type) {
  331. uni.switchTab({
  332. url: '/pages/order_addcart/order_addcart'
  333. })
  334. } else {
  335. uni.switchTab({
  336. url: '/pages/goods_cate/goods_cate'
  337. })
  338. }
  339. },
  340. // 商品详情接口;
  341. getAttrs(id) {
  342. let that = this;
  343. getAttr(id, 0).then(res => {
  344. uni.hideLoading();
  345. that.$set(that.attr, 'productAttr', res.data.productAttr);
  346. that.$set(that, 'productValue', res.data.productValue);
  347. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  348. that.$set(that, 'storeInfo', res.data.storeInfo);
  349. that.DefaultSelect();
  350. })
  351. },
  352. getProCate(){
  353. levelCategoryApi({id:this.where.sid}).then(res=>{
  354. this.filterCateList = res.data;
  355. })
  356. },
  357. // 筛选
  358. getSearchFilter() {
  359. let data = {
  360. keyword: this.where.keyword,
  361. cid: this.where.cid,
  362. sid: this.where.sid,
  363. tid: this.where.tid,
  364. productId: this.where.productId,
  365. promotions_type: this.where.promotions_type,
  366. // promotions_id: this.where.promotions_id
  367. };
  368. searchFilterApi(data).then(res => {
  369. this.brandList = res.data.brand;
  370. this.labelList = res.data.store_label;
  371. this.promotionList = res.data.promotions;
  372. this.getMarTop();
  373. }).catch(err => {
  374. return this.$util.Tips({
  375. title: err.msg
  376. });
  377. })
  378. },
  379. toggleSortable(){
  380. this.showSortAbleBox = !this.showSortAbleBox;
  381. },
  382. checkSortable(val){
  383. this.where.defaultOrder = val;
  384. this.showSortAbleBox = false;
  385. this.loadend = false;
  386. this.$set(this.where, 'page', 1);
  387. this.getProductList(true);
  388. },
  389. promotionTap(item){
  390. this.where.promotions_id = this.where.promotions_id == 0 ? item.id : 0;
  391. this.loadend = false;
  392. this.$set(this.where, 'page', 1);
  393. this.getProductList(true);
  394. },
  395. clearWord(){
  396. this.where.keyword = ''
  397. },
  398. cateCheck(item){
  399. this.where.sid = item.id;
  400. this.loadend = false;
  401. this.$set(this.where, 'page', 1);
  402. this.getProductList(true);
  403. },
  404. filterConfirm(data){
  405. this.showFilterDrawer = false;
  406. Object.assign(this.where,data);
  407. this.loadend = false;
  408. this.$set(this.where, 'page', 1);
  409. this.getProductList(true);
  410. this.getMarTop();
  411. },
  412. // 去详情页
  413. goDetail(item) {
  414. this.currentPage = false;
  415. goShopDetail(item, this.uid).catch(res => {
  416. uni.navigateTo({
  417. url: `/pages/goods_details/index?id=${item.id}`
  418. });
  419. });
  420. },
  421. Changswitch: function() {
  422. let that = this;
  423. this.currentPage = false
  424. that.is_switch = !that.is_switch
  425. },
  426. searchSubmit: function(e) {
  427. let that = this;
  428. this.currentPage = false
  429. that.$set(that.where, 'keyword', e.detail.value);
  430. that.loadend = false;
  431. that.$set(that.where, 'page', 1)
  432. this.getProductList(true);
  433. this.getSearchFilter();
  434. },
  435. /**
  436. * 获取我的推荐
  437. */
  438. get_host_product: function() {
  439. let that = this;
  440. if (that.hotScroll) return
  441. getProductHot(
  442. that.hotPage,
  443. that.hotLimit,
  444. ).then(res => {
  445. that.hotPage++
  446. that.hotScroll = res.data.length < that.hotLimit
  447. that.hostProduct = that.hostProduct.concat(res.data)
  448. // that.$set(that, 'hostProduct', res.data)
  449. });
  450. },
  451. //点击事件处理
  452. set_where: function(e) {
  453. this.currentPage = false
  454. switch (e) {
  455. case 1:
  456. // #ifdef H5
  457. return history.back();
  458. // #endif
  459. // #ifndef H5
  460. return uni.navigateBack({
  461. delta: 1,
  462. })
  463. // #endif
  464. break;
  465. case 2:
  466. if (this.price == 0) this.price = 1;
  467. else if (this.price == 1) this.price = 2;
  468. else if (this.price == 2) this.price = 0;
  469. this.stock = 0;
  470. break;
  471. case 3:
  472. if (this.stock == 0) this.stock = 1;
  473. else if (this.stock == 1) this.stock = 2;
  474. else if (this.stock == 2) this.stock = 0;
  475. this.price = 0
  476. break;
  477. case 4:
  478. this.nows = !this.nows;
  479. break;
  480. }
  481. this.loadend = false;
  482. this.$set(this.where, 'page', 1);
  483. this.getProductList(true);
  484. },
  485. //设置where条件
  486. setWhere: function() {
  487. if (this.price == 0) this.where.priceOrder = '';
  488. else if (this.price == 1) this.where.priceOrder = 'asc';
  489. else if (this.price == 2) this.where.priceOrder = 'desc';
  490. if (this.stock == 0) this.where.salesOrder = '';
  491. else if (this.stock == 1) this.where.salesOrder = 'asc';
  492. else if (this.stock == 2) this.where.salesOrder = 'desc';
  493. this.where.news = this.nows ? 1 : 0;
  494. },
  495. //查找产品
  496. getProductList: function(isPage) {
  497. let that = this;
  498. that.setWhere();
  499. if (that.loadend) return;
  500. if (that.loading) return;
  501. if (isPage === true) {
  502. that.$set(that, 'productList', []);
  503. }
  504. that.loading = true;
  505. that.loadTitle = '';
  506. getProductslist(that.where).then(res => {
  507. let list = res.data;
  508. let productList = that.$util.SplitArray(list, that.productList);
  509. let loadend = list.length < that.where.limit;
  510. that.loadend = loadend;
  511. that.loading = false;
  512. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  513. that.$set(that, 'productList', productList);
  514. that.$set(that.where, 'page', that.where.page + 1);
  515. if (!that.productList.length) this.get_host_product();
  516. }).catch(err => {
  517. that.loading = false;
  518. that.loadTitle = '加载更多';
  519. });
  520. },
  521. getMarTop(){
  522. if((this.promotionList.length && !this.cateSearch) || this.where.promotions_id || this.filterCateList.length){
  523. this.marTop = (115 + sysHeight) * 2;
  524. }else{
  525. this.marTop = (75 + sysHeight) * 2
  526. }
  527. },
  528. goCartDuo(item) {
  529. if (!this.isLogin) {
  530. toLogin();
  531. } else {
  532. if(item.cart_button == 0){
  533. if(item.is_presale_product){
  534. uni.navigateTo({
  535. url: `/pages/activity/goods_details/index?id=${item.id}&type=6`
  536. })
  537. }else{
  538. uni.navigateTo({
  539. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  540. })
  541. }
  542. }else{
  543. this.storeName = item.store_name;
  544. this.getAttrs(item.id);
  545. this.$set(this, 'id', item.id);
  546. this.$set(this.attr, 'cartAttr', true);
  547. }
  548. }
  549. },
  550. // 多规格加入购物车;
  551. goCatNum() {
  552. this.goCat(1, this.id, 1);
  553. },
  554. // 点击默认单属性购物车
  555. goCartDan(item) {
  556. if (!this.isLogin) {
  557. toLogin();
  558. } else {
  559. if(item.cart_button == 0){
  560. if(item.is_presale_product){
  561. uni.navigateTo({
  562. url: `/pages/activity/goods_details/index?id=${item.id}&type=6`
  563. })
  564. }else{
  565. uni.navigateTo({
  566. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  567. })
  568. }
  569. }else{
  570. this.goCat(0, item.id, 1);
  571. }
  572. }
  573. },
  574. DefaultSelect: function() {
  575. let productAttr = this.attr.productAttr;
  576. let value = [];
  577. for (let key in this.productValue) {
  578. if (this.productValue[key].stock > 0) {
  579. value = this.attr.productAttr.length ? key.split(",") : [];
  580. break;
  581. }
  582. }
  583. for (let i = 0; i < productAttr.length; i++) {
  584. this.$set(productAttr[i], "index", value[i]);
  585. }
  586. //sort();排序函数:数字-英文-汉字;
  587. let productSelect = this.productValue[value.join(",")];
  588. this.$set(this.attr.productSelect,"store_name",this.storeName);
  589. if (productSelect && productAttr.length) {
  590. this.$set(this.attr.productSelect, "image", productSelect.image);
  591. this.$set(this.attr.productSelect, "price", productSelect.price);
  592. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  593. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  594. this.$set(this.attr.productSelect, "cart_num", 1);
  595. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  596. this.$set(this, "attrValue", value.join(","));
  597. } else if (!productSelect && productAttr.length) {
  598. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  599. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  600. this.$set(this.attr.productSelect, "stock", 0);
  601. this.$set(this.attr.productSelect, "unique", "");
  602. this.$set(this.attr.productSelect, "cart_num", 0);
  603. this.$set(this, "attrValue", "");
  604. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  605. } else if (!productSelect && !productAttr.length) {
  606. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  607. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  608. this.$set(this.attr.productSelect, "stock", this.storeInfo.stock);
  609. this.$set(this.attr.productSelect,"unique",this.storeInfo.unique || "");
  610. this.$set(this.attr.productSelect, "cart_num", 1);
  611. this.$set(this, "attrValue", "");
  612. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  613. }
  614. },
  615. /**
  616. * 属性变动赋值
  617. *
  618. */
  619. ChangeAttr: function(res) {
  620. let productSelect = this.productValue[res];
  621. if (productSelect && productSelect.stock >= 0) {
  622. this.$set(this.attr.productSelect, "image", productSelect.image);
  623. this.$set(this.attr.productSelect, "price", productSelect.price);
  624. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  625. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  626. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  627. this.$set(this.attr.productSelect, "cart_num", 1);
  628. this.$set(this, "attrValue", res);
  629. } else {
  630. this.$set(this.attr.productSelect, 'image', this.storeInfo.image);
  631. this.$set(this.attr.productSelect, 'price', this.storeInfo.price);
  632. this.$set(this.attr.productSelect, 'stock', 0);
  633. this.$set(this.attr.productSelect, 'unique', '');
  634. this.$set(this.attr.productSelect, 'cart_num', 0);
  635. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  636. this.$set(this, 'attrValue', '');
  637. }
  638. },
  639. attrVal(val) {
  640. this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val
  641. .indexn]);
  642. },
  643. iptCartNum: function(e) {
  644. this.$set(this.attr.productSelect, 'cart_num', e);
  645. },
  646. onMyEvent: function() {
  647. this.$set(this.attr, 'cartAttr', false);
  648. },
  649. ChangeCartNumDuo(changeValue) {
  650. //获取当前变动属性
  651. let productSelect = this.productValue[this.attrValue];
  652. //如果没有属性,赋值给商品默认库存
  653. if (productSelect === undefined && !this.attr.productAttr.length)
  654. productSelect = this.attr.productSelect;
  655. //无属性值即库存为0;不存在加减;
  656. if (productSelect === undefined) return;
  657. let stock = productSelect.stock || 0;
  658. let num = this.attr.productSelect;
  659. this.ChangeCartNum(changeValue, num, stock, 1);
  660. },
  661. // 购物车加减计算函数
  662. ChangeCartNum(changeValue, num, stock, isDuo, id, index, cart) {
  663. if (changeValue) {
  664. num.cart_num++;
  665. if (num.cart_num > stock) {
  666. if (isDuo) {
  667. this.$set(this.attr.productSelect, "cart_num", stock ? stock : 1);
  668. this.$set(this, "cart_num", stock ? stock : 1);
  669. } else {
  670. num.cart_num = stock ? stock : 0;
  671. this.$set(this, 'tempArr', this.tempArr);
  672. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  673. }
  674. return this.$util.Tips({
  675. title: "该产品没有更多库存了"
  676. });
  677. } else {
  678. if (!isDuo) {
  679. if (cart) {
  680. this.goCat(0, id, 1, 1, num.product_attr_unique);
  681. this.getTotalPrice();
  682. } else {
  683. this.goCat(0, id, 1);
  684. }
  685. }
  686. }
  687. } else {
  688. num.cart_num--;
  689. if (num.cart_num == 0) {
  690. this.cartData.cartList.splice(index, 1);
  691. if (isDuo) {
  692. this.$set(this.attr.productSelect, "cart_num", 1);
  693. this.$set(this, "cart_num", 1);
  694. }
  695. }
  696. if (num.cart_num < 0) {
  697. if (isDuo) {
  698. this.$set(this.attr.productSelect, "cart_num", 1);
  699. this.$set(this, "cart_num", 1);
  700. } else {
  701. num.cart_num = 0;
  702. this.$set(this, 'tempArr', this.tempArr);
  703. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  704. }
  705. } else {
  706. if (!isDuo) {
  707. if (cart) {
  708. this.goCat(0, id, 0, 1, num.product_attr_unique);
  709. this.getTotalPrice();
  710. } else {
  711. this.goCat(0, id, 0);
  712. }
  713. }
  714. }
  715. }
  716. },
  717. /*
  718. * 加入购物车
  719. */
  720. goCat: function(duo, id, type, cart, unique) {
  721. let that = this;
  722. if (duo) {
  723. let productSelect = that.productValue[this.attrValue];
  724. //如果有属性,没有选择,提示用户选择
  725. if (
  726. that.attr.productAttr.length &&
  727. productSelect === undefined
  728. )
  729. return that.$util.Tips({
  730. title: "产品库存不足,请选择其它属性"
  731. });
  732. }
  733. let q = {
  734. product_id: id,
  735. num: duo ? that.attr.productSelect.cart_num : 1,
  736. type: type,
  737. unique: duo ? that.attr.productSelect.unique : cart ? unique : ""
  738. };
  739. postCartNum(q).then(function(res) {
  740. that.attr.cartAttr = false;
  741. if(!duo){
  742. return that.$util.Tips({
  743. title: '加入购物车成功,刷新购物车看看哦'
  744. });
  745. }else{
  746. return that.$util.Tips({
  747. title: res.msg
  748. });
  749. }
  750. // that.getCartNum();
  751. // if (!cart) {
  752. // that.getCartList(1);
  753. // }
  754. })
  755. .catch(err => {
  756. return that.$util.Tips({
  757. title: err
  758. });
  759. });
  760. },
  761. goBack(){
  762. uni.navigateBack()
  763. }
  764. },
  765. onPageScroll(e) {
  766. this.currentPage = false;
  767. uni.$emit('scroll');
  768. },
  769. onReachBottom() {
  770. if (this.productList.length > 0) {
  771. this.getProductList();
  772. } else {
  773. this.get_host_product();
  774. }
  775. }
  776. }
  777. </script>
  778. <style scoped lang="scss">
  779. .loadingicon{
  780. height: 100rpx;
  781. height: calc(100rpx + constant(safe-area-inset-bottom);
  782. height: calc(100rpx + env(safe-area-inset-bottom));
  783. margin-top: 0;
  784. }
  785. input{
  786. width: 100% !important;
  787. }
  788. .z-200{
  789. z-index: 200;
  790. }
  791. .pro_item ~ .pro_item{
  792. margin-top: 32rpx;
  793. }
  794. .border-picture {
  795. position: absolute;
  796. top: 0;
  797. left: 0;
  798. width: 100%;
  799. height: 100%;
  800. border-radius: 16rpx 16rpx 0 0;
  801. background: center/cover no-repeat;
  802. }
  803. .menu_line {
  804. width: 1px;
  805. height: 30rpx;
  806. background: #B3B3B3;
  807. margin: 0 20rpx;
  808. }
  809. .icon-ic_close1{
  810. position: absolute;
  811. right: 34rpx;
  812. top: 50%;
  813. transform: translateY(-50%);
  814. }
  815. .select_cate{
  816. &:after{
  817. content: '';
  818. position: absolute;
  819. top: 42rpx;
  820. left:50%;
  821. transform: translateX(-50%);
  822. width:36rpx;
  823. height:14rpx;
  824. background-image: url('../static/select_zs.png');
  825. background-size: 100%;
  826. background-repeat: no-repeat;
  827. }
  828. }
  829. .jinabian{
  830. position: absolute;
  831. top: 0;
  832. left: 0;
  833. width: 100%;
  834. height: 330rpx;
  835. background: linear-gradient(180deg, #FFFFFF 0%, rgba(255,255,255,0) 100%);
  836. }
  837. .info_box{
  838. padding: 16rpx 20rpx;
  839. border-radius: 0 0 20rpx 20rpx;
  840. background-color: #fff;
  841. }
  842. .text-primary-con{
  843. color: var(--view-theme);
  844. }
  845. .bg-primary-light{
  846. background: var(--view-minorColorT);
  847. }
  848. .bg--w111-484643{
  849. background: linear-gradient(90deg, #484643 0%, #1F1B17 100%);
  850. }
  851. .text--w111-FDDAA4{
  852. color: #FDDAA4;
  853. }
  854. .svip_rd{
  855. border-radius: 14rpx 0 8rpx 14rpx;
  856. }
  857. .op-border{
  858. border: 1px solid #f5f5f5;
  859. }
  860. .active{
  861. border: 1px solid var(--view-theme);
  862. color: var(--view-theme);
  863. background: var(--view-minorColorT);
  864. }
  865. .sortable-box{
  866. padding: 32rpx 32rpx 0;
  867. position: absolute;
  868. top: 88rpx;
  869. left: 0;
  870. }
  871. </style>