index.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  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. },
  214. price: 0,
  215. stock: 0,
  216. nows: false,
  217. loadend: false,
  218. loading: false,
  219. loadTitle: '加载更多',
  220. title: '',
  221. hostProduct: [],
  222. hotPage: 1,
  223. hotLimit: 10,
  224. hotScroll: false,
  225. brandList: [],
  226. promotionList:[],
  227. labelList:[],
  228. filterCateList:[],
  229. storeInfo: {},
  230. totalPrice: 0,
  231. promotionsInfo: {},
  232. totalNum: 0,
  233. imgHost: HTTP_REQUEST_URL,
  234. isShowAuth: false,
  235. marTop:'',
  236. showFilterDrawer:false,
  237. cateSearch:false,
  238. showSortAbleBox:false,
  239. sortableShowTab:[
  240. {title:'综合排序',value:0},
  241. {title:'好评优先',value:1},
  242. {title:'新品优先',value:2},
  243. ],
  244. getHeight: this.$util.getWXStatusHeight()
  245. };
  246. },
  247. onLoad: function(options) {
  248. this.where.cid = options.cid || 0;
  249. this.$set(this.where, 'sid', options.sid || 0);
  250. this.$set(this.where, 'tid', options.tid || 0);
  251. this.title = options.title || '';
  252. this.$set(this.where, 'keyword', options.searchValue || '');
  253. this.$set(this.where, 'productId', options.productId || '');
  254. this.$set(this.where, 'brand_id', options.brandId || 0);
  255. if (options.promotions_type) {
  256. this.where.promotions_type = options.promotions_type;
  257. this.where.promotions_id = options.promotions_id;
  258. this.is_switch = false
  259. }
  260. if(options.sid){
  261. //用于判断顶部分类选择内容是否展示
  262. this.cateSearch = true;
  263. this.getProCate();
  264. }
  265. this.getProductList();
  266. this.getSearchFilter();
  267. this.marTop = (115 + sysHeight) * 2;
  268. },
  269. onShow() {
  270. uni.removeStorageSync('form_type_cart');
  271. if (this.isLogin && !this.is_switch) {
  272. this.getCartList();
  273. this.getCartNum();
  274. }
  275. },
  276. created() {
  277. this.$eventHub.$on('onCartAddChange',(data)=>{
  278. if(data.spec_type){
  279. this.goCartDuo(data);
  280. }else{
  281. this.goCartDan(data);
  282. }
  283. });
  284. },
  285. methods: {
  286. getCartNum() {
  287. getCartCounts().then(res => {
  288. this.totalNum = res.data.count;
  289. }).catch(err => {
  290. return this.$util.Tips({
  291. title: err
  292. });
  293. })
  294. },
  295. getCartList() {
  296. let truePrice = 0;
  297. getCartList().then(res => {
  298. let data = res.data,
  299. valid = res.data.valid;
  300. valid.forEach(item => {
  301. item.promotions.forEach(z => {
  302. if (this.where.promotions_id == z.id) {
  303. this.promotionsInfo = z;
  304. }
  305. })
  306. item.cart.forEach(j => {
  307. truePrice = this.$util.$h.Add(truePrice, this.$util.$h.Mul(j.truePrice,
  308. j.cart_num));
  309. })
  310. })
  311. this.totalPrice = this.$util.$h.Sub(truePrice, data.deduction.coupon_price)
  312. }).catch(err => {
  313. return this.$util.Tips({
  314. title: err
  315. });
  316. })
  317. },
  318. goCart() {
  319. if (this.where.promotions_type) {
  320. uni.switchTab({
  321. url: '/pages/order_addcart/order_addcart'
  322. })
  323. } else {
  324. uni.switchTab({
  325. url: '/pages/goods_cate/goods_cate'
  326. })
  327. }
  328. },
  329. // 商品详情接口;
  330. getAttrs(id) {
  331. let that = this;
  332. getAttr(id, 0).then(res => {
  333. uni.hideLoading();
  334. that.$set(that.attr, 'productAttr', res.data.productAttr);
  335. that.$set(that, 'productValue', res.data.productValue);
  336. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  337. that.$set(that, 'storeInfo', res.data.storeInfo);
  338. that.DefaultSelect();
  339. })
  340. },
  341. getProCate(){
  342. levelCategoryApi({id:this.where.sid}).then(res=>{
  343. this.filterCateList = res.data;
  344. })
  345. },
  346. // 筛选
  347. getSearchFilter() {
  348. let data = {
  349. keyword: this.where.keyword,
  350. cid: this.where.cid,
  351. sid: this.where.sid,
  352. tid: this.where.tid,
  353. productId: this.where.productId,
  354. promotions_type: this.where.promotions_type,
  355. // promotions_id: this.where.promotions_id
  356. };
  357. searchFilterApi(data).then(res => {
  358. this.brandList = res.data.brand;
  359. this.labelList = res.data.store_label;
  360. this.promotionList = res.data.promotions;
  361. this.getMarTop();
  362. }).catch(err => {
  363. return this.$util.Tips({
  364. title: err.msg
  365. });
  366. })
  367. },
  368. toggleSortable(){
  369. this.showSortAbleBox = !this.showSortAbleBox;
  370. },
  371. checkSortable(val){
  372. this.where.defaultOrder = val;
  373. this.showSortAbleBox = false;
  374. this.loadend = false;
  375. this.$set(this.where, 'page', 1);
  376. this.getProductList(true);
  377. },
  378. promotionTap(item){
  379. this.where.promotions_id = this.where.promotions_id == 0 ? item.id : 0;
  380. this.loadend = false;
  381. this.$set(this.where, 'page', 1);
  382. this.getProductList(true);
  383. },
  384. clearWord(){
  385. this.where.keyword = ''
  386. },
  387. cateCheck(item){
  388. this.where.sid = item.id;
  389. this.loadend = false;
  390. this.$set(this.where, 'page', 1);
  391. this.getProductList(true);
  392. },
  393. filterConfirm(data){
  394. this.showFilterDrawer = false;
  395. Object.assign(this.where,data);
  396. this.loadend = false;
  397. this.$set(this.where, 'page', 1);
  398. this.getProductList(true);
  399. this.getMarTop();
  400. },
  401. // 去详情页
  402. goDetail(item) {
  403. this.currentPage = false;
  404. goShopDetail(item, this.uid).catch(res => {
  405. uni.navigateTo({
  406. url: `/pages/goods_details/index?id=${item.id}`
  407. });
  408. });
  409. },
  410. Changswitch: function() {
  411. let that = this;
  412. this.currentPage = false
  413. that.is_switch = !that.is_switch
  414. },
  415. searchSubmit: function(e) {
  416. let that = this;
  417. this.currentPage = false
  418. that.$set(that.where, 'keyword', e.detail.value);
  419. that.loadend = false;
  420. that.$set(that.where, 'page', 1)
  421. this.getProductList(true);
  422. this.getSearchFilter();
  423. },
  424. /**
  425. * 获取我的推荐
  426. */
  427. get_host_product: function() {
  428. let that = this;
  429. if (that.hotScroll) return
  430. getProductHot(
  431. that.hotPage,
  432. that.hotLimit,
  433. ).then(res => {
  434. that.hotPage++
  435. that.hotScroll = res.data.length < that.hotLimit
  436. that.hostProduct = that.hostProduct.concat(res.data)
  437. // that.$set(that, 'hostProduct', res.data)
  438. });
  439. },
  440. //点击事件处理
  441. set_where: function(e) {
  442. this.currentPage = false
  443. switch (e) {
  444. case 1:
  445. // #ifdef H5
  446. return history.back();
  447. // #endif
  448. // #ifndef H5
  449. return uni.navigateBack({
  450. delta: 1,
  451. })
  452. // #endif
  453. break;
  454. case 2:
  455. if (this.price == 0) this.price = 1;
  456. else if (this.price == 1) this.price = 2;
  457. else if (this.price == 2) this.price = 0;
  458. this.stock = 0;
  459. break;
  460. case 3:
  461. if (this.stock == 0) this.stock = 1;
  462. else if (this.stock == 1) this.stock = 2;
  463. else if (this.stock == 2) this.stock = 0;
  464. this.price = 0
  465. break;
  466. case 4:
  467. this.nows = !this.nows;
  468. break;
  469. }
  470. this.loadend = false;
  471. this.$set(this.where, 'page', 1);
  472. this.getProductList(true);
  473. },
  474. //设置where条件
  475. setWhere: function() {
  476. if (this.price == 0) this.where.priceOrder = '';
  477. else if (this.price == 1) this.where.priceOrder = 'asc';
  478. else if (this.price == 2) this.where.priceOrder = 'desc';
  479. if (this.stock == 0) this.where.salesOrder = '';
  480. else if (this.stock == 1) this.where.salesOrder = 'asc';
  481. else if (this.stock == 2) this.where.salesOrder = 'desc';
  482. this.where.news = this.nows ? 1 : 0;
  483. },
  484. //查找产品
  485. getProductList: function(isPage) {
  486. let that = this;
  487. that.setWhere();
  488. if (that.loadend) return;
  489. if (that.loading) return;
  490. if (isPage === true) {
  491. that.$set(that, 'productList', []);
  492. }
  493. that.loading = true;
  494. that.loadTitle = '';
  495. getProductslist(that.where).then(res => {
  496. let list = res.data;
  497. let productList = that.$util.SplitArray(list, that.productList);
  498. let loadend = list.length < that.where.limit;
  499. that.loadend = loadend;
  500. that.loading = false;
  501. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  502. that.$set(that, 'productList', productList);
  503. that.$set(that.where, 'page', that.where.page + 1);
  504. if (!that.productList.length) this.get_host_product();
  505. }).catch(err => {
  506. that.loading = false;
  507. that.loadTitle = '加载更多';
  508. });
  509. },
  510. getMarTop(){
  511. if((this.promotionList.length && !this.cateSearch) || this.where.promotions_id || this.filterCateList.length){
  512. this.marTop = (115 + sysHeight) * 2;
  513. }else{
  514. this.marTop = (75 + sysHeight) * 2
  515. }
  516. },
  517. goCartDuo(item) {
  518. if (!this.isLogin) {
  519. toLogin();
  520. } else {
  521. if(item.cart_button == 0){
  522. if(item.is_presale_product){
  523. uni.navigateTo({
  524. url: `/pages/activity/goods_details/index?id=${item.id}&type=6`
  525. })
  526. }else{
  527. uni.navigateTo({
  528. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  529. })
  530. }
  531. }else{
  532. this.storeName = item.store_name;
  533. this.getAttrs(item.id);
  534. this.$set(this, 'id', item.id);
  535. this.$set(this.attr, 'cartAttr', true);
  536. }
  537. }
  538. },
  539. // 多规格加入购物车;
  540. goCatNum() {
  541. this.goCat(1, this.id, 1);
  542. },
  543. // 点击默认单属性购物车
  544. goCartDan(item) {
  545. if (!this.isLogin) {
  546. toLogin();
  547. } else {
  548. if(item.cart_button == 0){
  549. if(item.is_presale_product){
  550. uni.navigateTo({
  551. url: `/pages/activity/goods_details/index?id=${item.id}&type=6`
  552. })
  553. }else{
  554. uni.navigateTo({
  555. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  556. })
  557. }
  558. }else{
  559. this.goCat(0, item.id, 1);
  560. }
  561. }
  562. },
  563. DefaultSelect: function() {
  564. let productAttr = this.attr.productAttr;
  565. let value = [];
  566. for (let key in this.productValue) {
  567. if (this.productValue[key].stock > 0) {
  568. value = this.attr.productAttr.length ? key.split(",") : [];
  569. break;
  570. }
  571. }
  572. for (let i = 0; i < productAttr.length; i++) {
  573. this.$set(productAttr[i], "index", value[i]);
  574. }
  575. //sort();排序函数:数字-英文-汉字;
  576. let productSelect = this.productValue[value.join(",")];
  577. this.$set(this.attr.productSelect,"store_name",this.storeName);
  578. if (productSelect && productAttr.length) {
  579. this.$set(this.attr.productSelect, "image", productSelect.image);
  580. this.$set(this.attr.productSelect, "price", productSelect.price);
  581. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  582. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  583. this.$set(this.attr.productSelect, "cart_num", 1);
  584. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  585. this.$set(this, "attrValue", value.join(","));
  586. } else if (!productSelect && productAttr.length) {
  587. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  588. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  589. this.$set(this.attr.productSelect, "stock", 0);
  590. this.$set(this.attr.productSelect, "unique", "");
  591. this.$set(this.attr.productSelect, "cart_num", 0);
  592. this.$set(this, "attrValue", "");
  593. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  594. } else if (!productSelect && !productAttr.length) {
  595. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  596. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  597. this.$set(this.attr.productSelect, "stock", this.storeInfo.stock);
  598. this.$set(this.attr.productSelect,"unique",this.storeInfo.unique || "");
  599. this.$set(this.attr.productSelect, "cart_num", 1);
  600. this.$set(this, "attrValue", "");
  601. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  602. }
  603. },
  604. /**
  605. * 属性变动赋值
  606. *
  607. */
  608. ChangeAttr: function(res) {
  609. let productSelect = this.productValue[res];
  610. if (productSelect && productSelect.stock >= 0) {
  611. this.$set(this.attr.productSelect, "image", productSelect.image);
  612. this.$set(this.attr.productSelect, "price", productSelect.price);
  613. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  614. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  615. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  616. this.$set(this.attr.productSelect, "cart_num", 1);
  617. this.$set(this, "attrValue", res);
  618. } else {
  619. this.$set(this.attr.productSelect, 'image', this.storeInfo.image);
  620. this.$set(this.attr.productSelect, 'price', this.storeInfo.price);
  621. this.$set(this.attr.productSelect, 'stock', 0);
  622. this.$set(this.attr.productSelect, 'unique', '');
  623. this.$set(this.attr.productSelect, 'cart_num', 0);
  624. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  625. this.$set(this, 'attrValue', '');
  626. }
  627. },
  628. attrVal(val) {
  629. this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val
  630. .indexn]);
  631. },
  632. iptCartNum: function(e) {
  633. this.$set(this.attr.productSelect, 'cart_num', e);
  634. },
  635. onMyEvent: function() {
  636. this.$set(this.attr, 'cartAttr', false);
  637. },
  638. ChangeCartNumDuo(changeValue) {
  639. //获取当前变动属性
  640. let productSelect = this.productValue[this.attrValue];
  641. //如果没有属性,赋值给商品默认库存
  642. if (productSelect === undefined && !this.attr.productAttr.length)
  643. productSelect = this.attr.productSelect;
  644. //无属性值即库存为0;不存在加减;
  645. if (productSelect === undefined) return;
  646. let stock = productSelect.stock || 0;
  647. let num = this.attr.productSelect;
  648. this.ChangeCartNum(changeValue, num, stock, 1);
  649. },
  650. // 购物车加减计算函数
  651. ChangeCartNum(changeValue, num, stock, isDuo, id, index, cart) {
  652. if (changeValue) {
  653. num.cart_num++;
  654. if (num.cart_num > stock) {
  655. if (isDuo) {
  656. this.$set(this.attr.productSelect, "cart_num", stock ? stock : 1);
  657. this.$set(this, "cart_num", stock ? stock : 1);
  658. } else {
  659. num.cart_num = stock ? stock : 0;
  660. this.$set(this, 'tempArr', this.tempArr);
  661. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  662. }
  663. return this.$util.Tips({
  664. title: "该产品没有更多库存了"
  665. });
  666. } else {
  667. if (!isDuo) {
  668. if (cart) {
  669. this.goCat(0, id, 1, 1, num.product_attr_unique);
  670. this.getTotalPrice();
  671. } else {
  672. this.goCat(0, id, 1);
  673. }
  674. }
  675. }
  676. } else {
  677. num.cart_num--;
  678. if (num.cart_num == 0) {
  679. this.cartData.cartList.splice(index, 1);
  680. if (isDuo) {
  681. this.$set(this.attr.productSelect, "cart_num", 1);
  682. this.$set(this, "cart_num", 1);
  683. }
  684. }
  685. if (num.cart_num < 0) {
  686. if (isDuo) {
  687. this.$set(this.attr.productSelect, "cart_num", 1);
  688. this.$set(this, "cart_num", 1);
  689. } else {
  690. num.cart_num = 0;
  691. this.$set(this, 'tempArr', this.tempArr);
  692. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  693. }
  694. } else {
  695. if (!isDuo) {
  696. if (cart) {
  697. this.goCat(0, id, 0, 1, num.product_attr_unique);
  698. this.getTotalPrice();
  699. } else {
  700. this.goCat(0, id, 0);
  701. }
  702. }
  703. }
  704. }
  705. },
  706. /*
  707. * 加入购物车
  708. */
  709. goCat: function(duo, id, type, cart, unique) {
  710. let that = this;
  711. if (duo) {
  712. let productSelect = that.productValue[this.attrValue];
  713. //如果有属性,没有选择,提示用户选择
  714. if (
  715. that.attr.productAttr.length &&
  716. productSelect === undefined
  717. )
  718. return that.$util.Tips({
  719. title: "产品库存不足,请选择其它属性"
  720. });
  721. }
  722. let q = {
  723. product_id: id,
  724. num: duo ? that.attr.productSelect.cart_num : 1,
  725. type: type,
  726. unique: duo ? that.attr.productSelect.unique : cart ? unique : ""
  727. };
  728. postCartNum(q).then(function(res) {
  729. that.attr.cartAttr = false;
  730. if(!duo){
  731. return that.$util.Tips({
  732. title: '加入购物车成功,刷新购物车看看哦'
  733. });
  734. }else{
  735. return that.$util.Tips({
  736. title: res.msg
  737. });
  738. }
  739. // that.getCartNum();
  740. // if (!cart) {
  741. // that.getCartList(1);
  742. // }
  743. })
  744. .catch(err => {
  745. return that.$util.Tips({
  746. title: err
  747. });
  748. });
  749. },
  750. goBack(){
  751. uni.navigateBack()
  752. }
  753. },
  754. onPageScroll(e) {
  755. this.currentPage = false;
  756. uni.$emit('scroll');
  757. },
  758. onReachBottom() {
  759. if (this.productList.length > 0) {
  760. this.getProductList();
  761. } else {
  762. this.get_host_product();
  763. }
  764. }
  765. }
  766. </script>
  767. <style scoped lang="scss">
  768. .loadingicon{
  769. height: 100rpx;
  770. height: calc(100rpx + constant(safe-area-inset-bottom);
  771. height: calc(100rpx + env(safe-area-inset-bottom));
  772. margin-top: 0;
  773. }
  774. input{
  775. width: 100% !important;
  776. }
  777. .z-200{
  778. z-index: 200;
  779. }
  780. .pro_item ~ .pro_item{
  781. margin-top: 32rpx;
  782. }
  783. .border-picture {
  784. position: absolute;
  785. top: 0;
  786. left: 0;
  787. width: 100%;
  788. height: 100%;
  789. border-radius: 16rpx 16rpx 0 0;
  790. background: center/cover no-repeat;
  791. }
  792. .menu_line {
  793. width: 1px;
  794. height: 30rpx;
  795. background: #B3B3B3;
  796. margin: 0 20rpx;
  797. }
  798. .icon-ic_close1{
  799. position: absolute;
  800. right: 34rpx;
  801. top: 50%;
  802. transform: translateY(-50%);
  803. }
  804. .select_cate{
  805. &:after{
  806. content: '';
  807. position: absolute;
  808. top: 42rpx;
  809. left:50%;
  810. transform: translateX(-50%);
  811. width:36rpx;
  812. height:14rpx;
  813. background-image: url('../static/select_zs.png');
  814. background-size: 100%;
  815. background-repeat: no-repeat;
  816. }
  817. }
  818. .jinabian{
  819. position: absolute;
  820. top: 0;
  821. left: 0;
  822. width: 100%;
  823. height: 330rpx;
  824. background: linear-gradient(180deg, #FFFFFF 0%, rgba(255,255,255,0) 100%);
  825. }
  826. .info_box{
  827. padding: 16rpx 20rpx;
  828. border-radius: 0 0 20rpx 20rpx;
  829. background-color: #fff;
  830. }
  831. .text-primary-con{
  832. color: var(--view-theme);
  833. }
  834. .bg-primary-light{
  835. background: var(--view-minorColorT);
  836. }
  837. .bg--w111-484643{
  838. background: linear-gradient(90deg, #484643 0%, #1F1B17 100%);
  839. }
  840. .text--w111-FDDAA4{
  841. color: #FDDAA4;
  842. }
  843. .svip_rd{
  844. border-radius: 14rpx 0 8rpx 14rpx;
  845. }
  846. .op-border{
  847. border: 1px solid #f5f5f5;
  848. }
  849. .active{
  850. border: 1px solid var(--view-theme);
  851. color: var(--view-theme);
  852. background: var(--view-minorColorT);
  853. }
  854. .sortable-box{
  855. padding: 32rpx 32rpx 0;
  856. position: absolute;
  857. top: 88rpx;
  858. left: 0;
  859. }
  860. </style>