order_addcart.vue 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436
  1. <template>
  2. <!-- 购物车模块 -->
  3. <view :style="colorStyle">
  4. <view class="px-20">
  5. <view class="rd-24rpx bg--w111-fff mt-20 pt-32" v-if="cartList.valid.length > 0">
  6. <view class="px-24 flex-between-center">
  7. <view class="flex-y-center">
  8. <text class=" text--w111-333 fs-24 lh-34rpx">共
  9. <text class="text-primary-con Regular fs-28 px-4">{{cartNum || 0}}</text>件宝贝</text>
  10. </view>
  11. <view class="flex-y-center">
  12. <view class="w-104 h-40 rd-20rpx flex-center bg-primary-light text-primary-con fs-24" @click="couponTap">优惠券</view>
  13. <text class="inline-block w-1 h-20 bg--w111-ccc mx-32"></text>
  14. <text class="fs-24 text--w111-333 lh-34rpx" v-if="cartList.valid.length > 0 || cartList.invalid.length > 0" @click="manage">{{ footerswitch ? '管理' : '取消'}}</text>
  15. </view>
  16. </view>
  17. <view class="mt-24 pl-24">
  18. <checkbox-group @change="checkboxChange">
  19. <view v-for="(j,jindex) in cartList.valid" :key="jindex">
  20. <view class="pr-24 flex-between-center mt-40" v-for="p in j.promotions" :key="p.id">
  21. <view class="flex-y-center ">
  22. <text
  23. class="max-120 inline-block h-28 rd-6rpx px-6 lh-28rpx text--w111-fff bg-color fs-20 text-center line1">{{p.title}}</text>
  24. <text class="w-422 text--w111-333 fs-26 pl-12 lh-36rpx line1">{{p.desc}}<text v-if="p.differ_threshold>0">还差{{p.differ_threshold}}{{p.threshold_type==1?'元':'件'}}</text> </text>
  25. </view>
  26. <view class="text--w111-333 fs-24 lh-34rpx" @click="goCollect(p)"> {{p.is_valid == 1?'去逛逛':'去凑单'}} <text
  27. class="iconfont icon-ic_rightarrow fs-24"></text>
  28. </view>
  29. </view>
  30. <tui-swipe-action :operateWidth="136" @click="handlerButton" v-for="(item,index) in j.valid" :key="index">
  31. <template v-slot:content>
  32. <view class="flex-between-center py-28">
  33. <!-- #ifndef MP -->
  34. <checkbox :value="(item.id).toString()" :checked="item.checked"
  35. :disabled="(!item.attrStatus || item.is_gift?true:false) && footerswitch" />
  36. <!-- #endif -->
  37. <!-- #ifdef MP -->
  38. <checkbox :value="item.id" :checked="item.checked"
  39. :disabled="(!item.attrStatus || item.is_gift?true:false) && footerswitch" />
  40. <!-- #endif -->
  41. <view class="flex-1 ml-22 flex">
  42. <image class="w-200 h-200 rd-16rpx" v-if="item.productInfo.attrInfo" :src="item.productInfo.attrInfo.image"
  43. @tap="goPage(1,'/pages/goods_details/index?id=' + item.productInfo.id)"></image>
  44. <image class="w-200 h-200 rd-16rpx" v-else :src="item.productInfo.image"
  45. @tap="goPage(1,'/pages/goods_details/index?id=' + item.productInfo.id)"></image>
  46. <view class="ml-20 flex-1 flex-col justify-between">
  47. <view class="w-full">
  48. <view class="w-382 line1 fs-28 fw-500 text--w111-333 lh-40rpx">{{item.productInfo.store_name}}</view>
  49. <view class="inline-block max-w-322 h-38 lh-38rpx mt-12 bg--w111-f5f5f5 text--w111-999 rd-20rpx px-12 text-center fs-22"
  50. v-if="item.productInfo.attrInfo && item.productInfo.spec_type && !item.is_gift && item.attrStatus"
  51. @click.stop="cartAttr(item)">
  52. <view class="flex">
  53. <text class="line1">{{item.productInfo.attrInfo.suk}}</text>
  54. <text class="iconfont icon-ic_downarrow fs-24 ml-12"></text>
  55. </view>
  56. </view>
  57. <view class="inline-block max-w-322 h-38 lh-38rpx mt-12 bg--w111-f5f5f5 text--w111-999 rd-20rpx px-12 text-center fs-22"
  58. v-else>
  59. <view class="flex">
  60. <text class="line1">{{item.productInfo.attrInfo.suk}}</text>
  61. <text class="iconfont icon-ic_downarrow fs-24 ml-12"></text>
  62. </view>
  63. </view>
  64. <view class="flex items-end flex-wrap mt-12 w-382">
  65. <BaseTag
  66. :text="label.label_name"
  67. :color="label.color"
  68. :background="label.bg_color"
  69. :borderColor="label.border_color"
  70. :circle="label.border_color ? true : false"
  71. :imgSrc="label.icon"
  72. v-for="(label, idx) in item.productInfo.store_label" :key="idx"></BaseTag>
  73. </view>
  74. </view>
  75. <view class="flex-between-center "
  76. :class="item.productInfo.store_label.length ? 'mt-12' : 'mt-50'"
  77. v-if="item.attrStatus && !item.is_gift">
  78. <view>
  79. <baseMoney :money="item.sum_price" symbolSize="24" integerSize="36" decimalSize="24"
  80. weight></baseMoney>
  81. </view>
  82. <view class="flex-y-center pr-24 text--w111-333">
  83. <text class="iconfont icon-ic_Reduce fs-24" @click.stop='subCart(jindex,index)'></text>
  84. <input type="number" maxlength="3" class="w-72 h-36 rd-4rpx bg--w111-f5f5f5 flex-center text-center fs-24 text--w111-333 mx-8"
  85. @input="setValue($event,item)" v-model="item.cart_num" />
  86. <text class="iconfont icon-ic_increase fs-24" @click.stop='addCart(jindex,index,item)'></text>
  87. </view>
  88. </view>
  89. <view class="flex-between-center pr-24" v-if="!item.attrStatus">
  90. <text class="fs-24 lh-34rpx">请重新选择商品规格</text>
  91. <view class="w-96 h-48 rd-24rpx flex-center bg--w111-fff fs-24 font-num con_border" @click.stop="reElection(item)">重选</view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. <template v-slot:button>
  98. <view class="flex justify-end h-full">
  99. <view class="w-120 flex-center fs-24 text--w111-fff bg-collect" @tap="customBtn(0,item.product_id)">收藏</view>
  100. <view class="w-120 flex-center fs-24 text--w111-fff bg-color"
  101. :class="index == cartList.valid.length - 1? 'del_btn' : ''"
  102. @tap="customBtn(1,item.id)"
  103. >删除</view>
  104. </view>
  105. </template>
  106. </tui-swipe-action>
  107. </view>
  108. </checkbox-group >
  109. </view>
  110. </view>
  111. <view class="pt-20" v-if="cartList.valid.length == 0 && loadend">
  112. <emptyPage title="暂无商品,去加点别的吧~"></emptyPage>
  113. </view>
  114. <view class="rd-24rpx bg--w111-fff mt-20 pt-32" v-if="cartList.invalid.length > 0">
  115. <view class="px-24 flex-between-center">
  116. <text class="fs-28 text--w111-333 lh-40rpx fw-500">失效商品({{cartList.invalid.length}})</text>
  117. <text class="fs-24 lh-28rpx text--w111-999" @click='unsetCart'>一键清空</text>
  118. </view>
  119. <view class="mt-24 px-24">
  120. <view class="flex-between-center py-28" v-for="(item,ind) in cartList.invalid" :key='ind'>
  121. <text class="iconfont icon-ic_Disable"></text>
  122. <view class="flex-1 ml-22 flex">
  123. <view class="relative">
  124. <image class="w-200 h-200 rd-16rpx" v-if="item.productInfo.attrInfo" :src='item.productInfo.attrInfo.image'></image>
  125. <image class="w-200 h-200 rd-16rpx" v-else :src='item.productInfo.image'></image>
  126. <view class="over flex-center fs-24 text--w111-fff">失效</view>
  127. </view>
  128. <view class="ml-20">
  129. <view class="w-382 line1 fs-28 fw-500 text--w111-ccc lh-40rpx">{{item.productInfo.store_name}}</view>
  130. <view
  131. class="inline-block h-38 lh-38rpx mt-12 bg--w111-f5f5f5 text--w111-ccc rd-20rpx px-12 text-center fs-22">
  132. <view class="flex" v-if="item.productInfo.attrInfo">
  133. <text>{{item.productInfo.attrInfo.suk}}</text>
  134. <text class="iconfont icon-ic_downarrow fs-24 ml-12"></text>
  135. </view>
  136. </view>
  137. <view class="flex my-20">
  138. <view
  139. class="h-26 lh-22rpx px-6 rd-4rpx fs-18 bg--w111-fff disabled-tag" v-if="item.productInfo.freight == 1">
  140. 包邮</view>
  141. <view
  142. class="h-26 lh-22rpx px-6 rd-4rpx fs-18 bg--w111-fff disabled-tag ml-8">
  143. 7天无理由</view>
  144. </view>
  145. <view class="flex-between-center text--w111-bbb fs-22">
  146. {{item.invalid_desc}}
  147. <!-- <view>
  148. <baseMoney :money="item.sum_price" symbolSize="24" integerSize="36" decimalSize="24" color="#bbbbbb"
  149. weight></baseMoney>
  150. </view> -->
  151. </view>
  152. </view>
  153. </view>
  154. </view>
  155. </view>
  156. </view>
  157. </view>
  158. <!-- 热门推荐显示 -->
  159. <!-- <view class='px-20'>
  160. <recommend :hostProduct='hostProduct'></recommend>
  161. </view> -->
  162. <view v-if="cartList.valid.length == 0 && cartList.invalid.length == 0 && loadend"
  163. class="h-30"></view>
  164. <view v-else class="h-200"></view>
  165. <view :style="[moneyPD.b]" class="tips acea-row row-middle" :class="isFooter?'':'on'" v-if="isTips"><text
  166. class="iconfont icon-tishi"></text>部分活动不能叠加,系统已自动为您计算最优惠的价格</view>
  167. <!-- 订单结算 -->
  168. <view :style="[pdHeights]" class="fixed-lb fixed_bt w-full"
  169. v-if="cartList.valid.length">
  170. <view class="h-80 bg--w111-FFF0D1 flex-between-center mt-24 px-20"
  171. v-show="!discountInfo.discount"
  172. v-if="!discountInfo.svip_status && discountInfo.svip_price">
  173. <view class="flex-y-center">
  174. <image src="@/static/img/vip_leval.png" class="w-36 h-36"></image>
  175. <view class="pl-8">
  176. <text class="fs-24 text--w111-7E4B06">开通 SVIP会员 预计省</text>
  177. <text class="font-color Regular px-4 fs-28">¥{{discountInfo.svip_price}}</text>
  178. <text class="fs-24 text--w111-7E4B06">元</text>
  179. </view>
  180. </view>
  181. <view class="fs-24 text--w111-7E4B06" @click="goPage(1,'/pages/annex/vip_paid/index')">
  182. <text>立即开通</text>
  183. <text class="iconfont icon-ic_rightarrow fs-24"></text>
  184. </view>
  185. </view>
  186. <view class="h-96 pl-32 pr-20 flex-between-center bg--w111-fff">
  187. <checkbox-group @change="checkboxAllChange">
  188. <checkbox value="all" :checked="!!isAllSelect" />
  189. <text class="fs-26 text--w111-333 lh-36rpx">全选</text>
  190. </checkbox-group>
  191. <view class="flex-y-center" v-if="footerswitch==true && discountInfo.deduction">
  192. <view>
  193. <view class="lh-40rpx text--w111-333 fs-28">合计: <text class="fs-32 fw-600">¥{{selectValue.length?discountInfo.deduction.pay_price:0}}</text>
  194. </view>
  195. <view class="fs-22 text--w111-333 mt-6" @tap="discountTap"
  196. v-if="preferential">
  197. 已优惠: ¥{{$util.$h.Sub(discountInfo.deduction.sum_price,discountInfo.deduction.pay_price)}} 查看详情
  198. <text class="iconfont icon-ic_uparrow fs-20"></text>
  199. </view>
  200. </view>
  201. <form @submit="subOrder">
  202. <button v-if="selectValue.length" class="w-186 h-72 rd-36rpx flex-center bg-color text--w111-fff fs-26 fw-500 ml-20" formType="submit"
  203. >{{Object.prototype.toString.call(discountInfo.coupon) === "[object Array]" || discountInfo.coupon.used?'去':'领券'}}结算({{selectValue.length}})</button>
  204. <button v-else class='w-186 h-72 rd-36rpx flex-center bg-color text--w111-fff fs-26 fw-500 ml-20' formType="submit"
  205. >{{Object.prototype.toString.call(discountInfo.coupon) === "[object Array]" || discountInfo.coupon.used?'去':'领券'}}结算({{selectValue.length}})</button>
  206. </form>
  207. </view>
  208. <view class="flex-y-center justify-end" v-else>
  209. <view class="w-144 h-56 rd-28rpx flex-center fs-24 fw-500 text--w111-333 bg--w111-fff border_ccc" @click="subCollect">收藏商品</view>
  210. <view class="w-96 h-56 rd-28rpx flex-center fs-24 fw-500 text-primary-con bg--w111-fff border_con ml-20" @click="subDel">删除</view>
  211. </view>
  212. </view>
  213. </view>
  214. <!-- 产品属性显示 -->
  215. <productWindow
  216. :attr="attr"
  217. :isShow='1'
  218. :iSplus='1'
  219. :iScart='1'
  220. :storeInfo="storeInfo"
  221. :is_vip="is_vip"
  222. :type="2"
  223. :fangda="false"
  224. @myevent="onMyEvent"
  225. @ChangeAttr="ChangeAttr"
  226. @ChangeCartNum="ChangeCartNum"
  227. @attrVal="attrVal"
  228. @iptCartNum="iptCartNum"
  229. @goCat="reGoCat" id='product-window'></productWindow>
  230. <!-- 优惠明细显示 -->
  231. <cartDiscount :discountInfo="discountInfo" :moneyPD='moneyPD' @myevent="myDiscount"></cartDiscount>
  232. <view class="uni-p-b-98"></view>
  233. <pageFooter @newDataStatus="newDataStatus"></pageFooter>
  234. <!-- 优惠券列表弹框显示 -->
  235. <couponListWindow
  236. :coupon="coupon"
  237. :openType="0"
  238. @ChangCouponsClone="ChangCouponsClone"
  239. @ChangCouponsUseState="ChangCouponsUseState"
  240. @ChangCoupons="ChangCouponsClone"
  241. @tabCouponType="tabCouponType"
  242. @ruleToggle="ruleToggle"
  243. v-if="coupon">
  244. </couponListWindow>
  245. </view>
  246. </template>
  247. <script>
  248. // #ifdef APP-PLUS || MP
  249. let sysHeight = uni.getSystemInfoSync().statusBarHeight;
  250. // #endif
  251. // #ifdef H5
  252. let sysHeight = 0
  253. // #endif
  254. import {
  255. getCartList,
  256. getCartCounts,
  257. changeCartNum,
  258. cartDel,
  259. getResetCart,
  260. cartCompute
  261. } from '@/api/order.js';
  262. import {
  263. setCouponReceive,
  264. getCoupons
  265. } from '@/api/api.js';
  266. import {
  267. getProductHot,
  268. collectAll,
  269. getProductDetail,
  270. getAttr,
  271. } from '@/api/store.js';
  272. import {
  273. toLogin
  274. } from '@/libs/login.js';
  275. import {
  276. mapGetters
  277. } from "vuex";
  278. import recommend from '@/components/recommend';
  279. import productWindow from '@/components/productWindow';
  280. import cartDiscount from '@/components/cartDiscount';
  281. import couponListWindow from '@/components/couponListWindow';
  282. import pageFooter from '@/components/pageFooter/index.vue'
  283. import tuiSwipeAction from "@/components/tui-swipe-action/index.vue";
  284. import emptyPage from '@/components/emptyPage.vue';
  285. import colors from "@/mixins/color";
  286. import {HTTP_REQUEST_URL} from '@/config/app';
  287. import {Debounce} from '@/utils/validate.js'
  288. export default {
  289. components: {
  290. couponListWindow,
  291. pageFooter,
  292. recommend,
  293. productWindow,
  294. cartDiscount,
  295. tuiSwipeAction,
  296. emptyPage
  297. },
  298. mixins: [colors],
  299. data() {
  300. return {
  301. isFooter: false,
  302. isTips: false,
  303. //属性是否打开
  304. coupon: {
  305. coupon: false,
  306. type: -1,
  307. list: [],
  308. count: [],
  309. goFrom: 1
  310. },
  311. discountInfo: {
  312. discount: false,
  313. deduction: {},
  314. coupon: {},
  315. svip_price:0,
  316. svip_status:false
  317. },
  318. goodsHidden: true,
  319. footerswitch: true,
  320. hostProduct: [],
  321. cartList: {
  322. valid: [],
  323. invalid: []
  324. },
  325. isAllSelect: false, //全选
  326. selectValue: [], //选中的数据
  327. selectCountPrice: 0.00,
  328. isAuto: false, //没有授权的不会自动授权
  329. isShowAuth: false, //是否隐藏授权
  330. hotScroll: false,
  331. hotPage: 1,
  332. hotLimit: 10,
  333. loading: false,
  334. loadend: false,
  335. loadTitle: '没有更多内容啦~', //提示语
  336. page: 1,
  337. limit: 20,
  338. loadingInvalid: false,
  339. loadendInvalid: false,
  340. loadTitleInvalid: '加载更多', //提示语
  341. pageInvalid: 1,
  342. limitInvalid: 20,
  343. attr: {
  344. cartAttr: false,
  345. productAttr: [],
  346. productSelect: {}
  347. },
  348. productValue: [], //系统属性
  349. storeInfo: {},
  350. attrValue: '', //已选属性
  351. attrTxt: '请选择', //属性页面提示
  352. cartId: 0,
  353. product_id: 0,
  354. sysHeight: sysHeight,
  355. footerSee: false,
  356. isCart: 0,
  357. imgHost: HTTP_REQUEST_URL,
  358. is_vip: 0, //是否是会员
  359. pdHeight:0 //自定义底部导航上下边距和
  360. };
  361. },
  362. computed: {
  363. ...mapGetters(['isLogin', 'cartNum']),
  364. pdHeights(){
  365. let H = `calc(${this.pdHeight*2 + 94}rpx + env(safe-area-inset-bottom))`
  366. let HZ = `calc(94rpx + env(safe-area-inset-bottom))`
  367. return{
  368. //#ifdef H5
  369. bottom: this.isFooter?H:HZ
  370. //#endif
  371. // #ifdef MP || APP-PLUS
  372. bottom: this.isFooter?H:0
  373. //#endif
  374. }
  375. },
  376. moneyPD(){
  377. let H = `calc(${this.pdHeight*2 + 190}rpx + env(safe-area-inset-bottom))`
  378. let HZ = `calc(190rpx + env(safe-area-inset-bottom))`
  379. let pb = {
  380. //#ifdef H5
  381. paddingBottom: this.isFooter?H:HZ
  382. //#endif
  383. // #ifdef MP || APP-PLUS
  384. paddingBottom: this.isFooter?H:'96rpx'
  385. //#endif
  386. }
  387. let b = {
  388. //#ifdef H5
  389. bottom: this.isFooter?H:HZ
  390. //#endif
  391. // #ifdef MP || APP-PLUS
  392. bottom: this.isFooter?H:'96rpx'
  393. //#endif
  394. }
  395. return{
  396. pb:pb,
  397. b:b
  398. }
  399. },
  400. preferential(){
  401. let deduction = this.discountInfo.deduction;
  402. let obj = (Object.prototype.toString.call(this.discountInfo.coupon) === '[object Object]' || deduction.first_order_price || deduction.promotions_price || deduction.vip_price) && this.selectValue.length
  403. return obj
  404. }
  405. },
  406. onLoad: function(options) {
  407. this.hotPage = 1;
  408. this.hostProduct = [],
  409. this.hotScroll = false,
  410. this.getHostProduct();
  411. },
  412. onShow: function() {
  413. uni.setStorageSync('form_type_cart', 1);
  414. uni.pageScrollTo({
  415. duration: 0,
  416. scrollTop: 0
  417. })
  418. if (this.isLogin == true) {
  419. this.resetData();
  420. } else {
  421. toLogin()
  422. }
  423. },
  424. methods: {
  425. onLoadFun() {
  426. this.resetData();
  427. },
  428. resetData() {
  429. this.loadend = false;
  430. this.page = 1;
  431. this.cartList.valid = [];
  432. // 1:表示只有在onShow里面调用;
  433. this.getCartList();
  434. this.loadendInvalid = false;
  435. this.pageInvalid = 1;
  436. this.cartList.invalid = [];
  437. // this.getCartNum();
  438. this.goodsHidden = true;
  439. this.footerswitch = true;
  440. this.hotLimit = 10;
  441. this.isAllSelect = false; //全选
  442. this.selectValue = []; //选中的数据
  443. this.selectCountPrice = 0.00;
  444. this.isShowAuth = false;
  445. },
  446. newDataStatus(val,num) {
  447. this.isFooter = val ? true : false;
  448. this.pdHeight = num;
  449. },
  450. tabCouponType: function(type) {
  451. this.$set(this.coupon, 'type', type);
  452. this.getCouponList(type);
  453. },
  454. ChangCouponsUseState(index) {
  455. let that = this;
  456. that.coupon.list[index].is_use = true;
  457. that.$set(that.coupon, 'list', that.coupon.list);
  458. that.$set(that.coupon, 'coupon', false);
  459. },
  460. ChangCouponsClone: function() {
  461. this.$set(this.coupon, 'coupon', false);
  462. },
  463. ruleToggle(index){
  464. this.coupon.list[index].ruleshow = !this.coupon.list[index].ruleshow;
  465. },
  466. /**
  467. * 获取优惠券
  468. *
  469. */
  470. getCouponList(type) {
  471. let that = this,
  472. obj = {
  473. page: 1,
  474. limit: 20,
  475. product_id: that.id ? that.id : '',
  476. type: type ? type : ''
  477. };
  478. getCoupons(obj).then(res => {
  479. that.$set(that.coupon, 'count', res.data.count);
  480. if (type === undefined || type === null) {
  481. let count = [...that.coupon.count],
  482. indexs = '';
  483. let index = count.findIndex(item => item);
  484. let delCount = that.coupon.count,
  485. newDelCount = [];
  486. let countIndex = 0;
  487. delCount.forEach((item, index) => {
  488. if (item === 0) {
  489. countIndex = index;
  490. } else {
  491. newDelCount.push(item)
  492. }
  493. });
  494. if (newDelCount.length == 3) {
  495. indexs = 2;
  496. } else if (newDelCount.length == 2) {
  497. if (countIndex === 2) {
  498. indexs = 1;
  499. } else {
  500. indexs = 2;
  501. }
  502. } else {
  503. indexs = delCount.findIndex(item => item === count[index]);
  504. }
  505. that.$set(that.coupon, 'type', indexs);
  506. that.getCouponList(indexs);
  507. } else {
  508. res.data.list.map(item=>{
  509. that.$set(item,'ruleshow',false);
  510. })
  511. that.$set(that.coupon, 'list', res.data.list);
  512. }
  513. });
  514. },
  515. /**
  516. * 打开优惠券插件
  517. */
  518. couponTap: function() {
  519. let that = this;
  520. that.getCouponList();
  521. that.$set(that.coupon, 'coupon', true);
  522. },
  523. goCollect(item) {
  524. uni.navigateTo({
  525. url: `/pages/goods/goods_list/index?sid=0&title=默认&promotions_type=${item.promotions_type}&promotions_id=${item.id}`
  526. })
  527. },
  528. myDiscount() {
  529. this.discountInfo.discount = false;
  530. },
  531. discountTap() {
  532. this.coupon.coupon = false;
  533. this.discountInfo.discount = !this.discountInfo.discount;
  534. },
  535. // 授权关闭
  536. authColse: function(e) {
  537. this.isShowAuth = e;
  538. },
  539. // 修改购物车
  540. reGoCat: function() {
  541. let that = this,
  542. productSelect = that.productValue[this.attrValue];
  543. //如果有属性,没有选择,提示用户选择
  544. if (
  545. that.attr.productAttr.length &&
  546. productSelect === undefined
  547. ) {
  548. return that.$util.Tips({
  549. title: "产品库存不足,请选择其它"
  550. });
  551. }
  552. let q = {
  553. id: that.cartId,
  554. product_id: that.product_id,
  555. num: that.attr.productSelect.cart_num,
  556. unique: that.attr.productSelect !== undefined ?
  557. that.attr.productSelect.unique : ""
  558. };
  559. getResetCart(q)
  560. .then(function(res) {
  561. that.attr.cartAttr = false;
  562. that.$util.Tips({
  563. title: "添加购物车成功",
  564. success: () => {
  565. that.loadend = false;
  566. that.page = 1;
  567. that.cartList.valid = [];
  568. that.getCartList();
  569. that.getCartNum();
  570. }
  571. });
  572. })
  573. .catch(res => {
  574. return that.$util.Tips({
  575. title: res.msg
  576. });
  577. });
  578. },
  579. onMyEvent: function() {
  580. this.$set(this.attr, 'cartAttr', false);
  581. },
  582. // 点击切换属性
  583. cartAttr(item) {
  584. this.isCart = 1;
  585. this.getGoodsDetails(item);
  586. },
  587. // 重选
  588. reElection: function(item) {
  589. this.isCart = 0;
  590. this.getGoodsDetails(item)
  591. },
  592. /**
  593. * 获取产品详情
  594. *
  595. */
  596. getGoodsDetails: function(item) {
  597. uni.showLoading({
  598. title: '加载中',
  599. mask: true
  600. });
  601. let that = this;
  602. that.cartId = item.id;
  603. that.product_id = item.product_id;
  604. getAttr(item.product_id, 0).then(res => {
  605. uni.hideLoading();
  606. that.attr.cartAttr = true;
  607. let storeInfo = res.data.storeInfo;
  608. that.$set(that, 'storeInfo', storeInfo);
  609. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  610. that.$set(that.attr, 'productAttr', res.data.productAttr);
  611. that.$set(that, 'productValue', res.data.productValue);
  612. that.DefaultSelect();
  613. }).catch(err => {
  614. uni.hideLoading();
  615. })
  616. },
  617. /**
  618. * 属性变动赋值
  619. *
  620. */
  621. ChangeAttr: function(res) {
  622. let productSelect = this.productValue[res];
  623. if (productSelect && productSelect.stock > 0) {
  624. this.$set(this.attr.productSelect, "image", productSelect.image);
  625. this.$set(this.attr.productSelect, "price", productSelect.price);
  626. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  627. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  628. this.$set(this.attr.productSelect, "cart_num", 1);
  629. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  630. this.$set(this, "attrValue", res);
  631. this.$set(this, "attrTxt", "已选择");
  632. } else {
  633. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  634. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  635. this.$set(this.attr.productSelect, "stock", 0);
  636. this.$set(this.attr.productSelect, "unique", "");
  637. this.$set(this.attr.productSelect, "cart_num", 0);
  638. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  639. this.$set(this, "attrValue", "");
  640. this.$set(this, "attrTxt", "请选择");
  641. }
  642. },
  643. /**
  644. * 默认选中属性
  645. *
  646. */
  647. DefaultSelect: function() {
  648. let productAttr = this.attr.productAttr;
  649. let value = [],
  650. stock = 0,
  651. attrValue = [];
  652. for (var key in this.productValue) {
  653. if (this.productValue[key].stock > 0) {
  654. value = this.attr.productAttr.length ? key.split(",") : [];
  655. break;
  656. }
  657. }
  658. //isCart 1切换属性 0为重选
  659. if (this.isCart) {
  660. //购物车默认打开时,随着选中的属性改变
  661. // let attrValue = [];
  662. this.cartList.valid.forEach(j => {
  663. j.valid.forEach(item => {
  664. if (item.id == this.cartId) {
  665. attrValue = item.productInfo.attrInfo.suk.split(",");
  666. }
  667. })
  668. })
  669. let key = attrValue.join(",");
  670. stock = this.productValue[key].stock;
  671. for (let i = 0; i < productAttr.length; i++) {
  672. this.$set(productAttr[i], "index", stock ? attrValue[i] : value[i]);
  673. }
  674. } else {
  675. for (let i = 0; i < productAttr.length; i++) {
  676. this.$set(productAttr[i], "index", value[i]);
  677. }
  678. }
  679. //sort();排序函数:数字-英文-汉字;
  680. let productSelect = this.productValue[(this.isCart && stock) ? attrValue.join(",") : value.join(",")];
  681. if (productSelect && productAttr.length) {
  682. this.$set(
  683. this.attr.productSelect,
  684. "store_name",
  685. this.storeInfo.store_name
  686. );
  687. this.$set(this.attr.productSelect, "image", productSelect.image);
  688. this.$set(this.attr.productSelect, "price", productSelect.price);
  689. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  690. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  691. this.$set(this.attr.productSelect, "cart_num", 1);
  692. this.$set(this, "attrValue", value.join(","));
  693. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  694. this.$set(this, "attrTxt", "已选择");
  695. } else if (!productSelect && productAttr.length) {
  696. this.$set(
  697. this.attr.productSelect,
  698. "store_name",
  699. this.storeInfo.store_name
  700. );
  701. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  702. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  703. this.$set(this.attr.productSelect, "stock", 0);
  704. this.$set(this.attr.productSelect, "unique", "");
  705. this.$set(this.attr.productSelect, "cart_num", 0);
  706. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  707. this.$set(this, "attrValue", "");
  708. this.$set(this, "attrTxt", "请选择");
  709. } else if (!productSelect && !productAttr.length) {
  710. this.$set(
  711. this.attr.productSelect,
  712. "store_name",
  713. this.storeInfo.store_name
  714. );
  715. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  716. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  717. this.$set(this.attr.productSelect, "stock", this.storeInfo.stock);
  718. this.$set(
  719. this.attr.productSelect,
  720. "unique",
  721. this.storeInfo.unique || ""
  722. );
  723. this.$set(this.attr.productSelect, "cart_num", 1);
  724. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  725. this.$set(this, "attrValue", "");
  726. this.$set(this, "attrTxt", "请选择");
  727. }
  728. },
  729. attrVal(val) {
  730. this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val
  731. .indexn]);
  732. },
  733. /**
  734. * 购物车数量加和数量减
  735. *
  736. */
  737. ChangeCartNum: function(changeValue) {
  738. //changeValue:是否 加|减
  739. //获取当前变动属性
  740. let productSelect = this.productValue[this.attrValue];
  741. //如果没有属性,赋值给商品默认库存
  742. if (productSelect === undefined && !this.attr.productAttr.length)
  743. productSelect = this.attr.productSelect;
  744. //无属性值即库存为0;不存在加减;
  745. if (productSelect === undefined) return;
  746. let stock = productSelect.stock || 0;
  747. let num = this.attr.productSelect;
  748. if (changeValue) {
  749. num.cart_num++;
  750. if (num.cart_num > stock) {
  751. this.$set(this.attr.productSelect, "cart_num", stock ? stock : 1);
  752. this.$set(this, "cart_num", stock ? stock : 1);
  753. }
  754. } else {
  755. num.cart_num--;
  756. if (num.cart_num < 1) {
  757. this.$set(this.attr.productSelect, "cart_num", 1);
  758. this.$set(this, "cart_num", 1);
  759. }
  760. }
  761. },
  762. /**
  763. * 购物车手动填写
  764. *
  765. */
  766. iptCartNum: function(e) {
  767. this.$set(this.attr.productSelect, 'cart_num', e);
  768. },
  769. subDel: function(event) {
  770. let that = this,
  771. selectValue = that.selectValue,
  772. storeId = uni.getStorageSync('user_store_id');
  773. if (selectValue.length > 0)
  774. cartDel(selectValue,storeId).then(res => {
  775. that.loadend = false;
  776. that.page = 1;
  777. that.cartList.valid = [];
  778. that.getCartList();
  779. that.getCartNum();
  780. });
  781. else
  782. return that.$util.Tips({
  783. title: '请选择产品'
  784. });
  785. },
  786. getSelectValueProductId: function() {
  787. let that = this;
  788. let validList = that.cartList.valid;
  789. let selectValue = that.selectValue;
  790. let productId = [];
  791. if (selectValue.length > 0) {
  792. for (let j in validList) {
  793. for (let index in validList[j].valid) {
  794. if (that.inArray(validList[j].valid[index].id, selectValue)) {
  795. productId.push(validList[j].valid[index].product_id);
  796. }
  797. }
  798. }
  799. };
  800. return productId;
  801. },
  802. subCollect: function(event) {
  803. let that = this,
  804. selectValue = that.selectValue;
  805. if (selectValue.length > 0) {
  806. let selectValueProductId = that.getSelectValueProductId();
  807. collectAll(that.getSelectValueProductId().join(',')).then(res => {
  808. return that.$util.Tips({
  809. title: res.msg,
  810. icon: 'success'
  811. });
  812. }).catch(err => {
  813. return that.$util.Tips({
  814. title: err
  815. });
  816. });
  817. } else {
  818. return that.$util.Tips({
  819. title: '请选择产品'
  820. });
  821. }
  822. },
  823. subOrder(event) {
  824. let that = this,
  825. selectValue = that.selectValue,
  826. delivery_type = 1,
  827. storeId = 0;
  828. if (selectValue.length > 0) {
  829. that.cartList.valid.forEach(item=>{
  830. item.valid.forEach(j=>{
  831. if(j.id == selectValue[0]){
  832. let deliverySort = j.productInfo.delivery_type.sort((x,y)=>x - y);
  833. delivery_type = deliverySort[0];
  834. storeId = j.productInfo.type == 1?j.productInfo.relation_id:0
  835. }
  836. })
  837. })
  838. let coupon = this.discountInfo.coupon;
  839. if (Object.prototype.toString.call(coupon) === '[object Object]' && !coupon.used) {
  840. setCouponReceive(this.discountInfo.coupon.id).then(res => {
  841. uni.navigateTo({
  842. url: '/pages/goods/order_confirm/index?cartId=' + selectValue.join(',') +
  843. '&couponId=' + res.data.id + '&couponTitle=' + coupon.coupon_title+'&delivery_type='+delivery_type + '&store_id=' + storeId
  844. });
  845. }).catch(err => {
  846. return that.$util.Tips({
  847. title: err
  848. });
  849. })
  850. } else {
  851. let url = '';
  852. if (Object.prototype.toString.call(coupon) === '[object Array]') {
  853. url = '/pages/goods/order_confirm/index?cartId=' + selectValue.join(',')+'&delivery_type='+delivery_type+ '&store_id=' + storeId
  854. } else {
  855. url = '/pages/goods/order_confirm/index?cartId=' + selectValue.join(',') + '&couponId=' + coupon.used.id +'&couponTitle='+ coupon.coupon_title+'&delivery_type='+delivery_type+ '&store_id=' + storeId
  856. }
  857. uni.navigateTo({
  858. url: url
  859. });
  860. }
  861. } else {
  862. return that.$util.Tips({
  863. title: '请选择产品'
  864. });
  865. }
  866. },
  867. checkboxAllChange: function(event) {
  868. let value = event.detail.value;
  869. if (value.length > 0) {
  870. this.setAllSelectValue(1)
  871. } else {
  872. this.setAllSelectValue(0)
  873. }
  874. },
  875. setAllSelectValue: function(status) {
  876. let that = this;
  877. let selectValue = [];
  878. let valid = that.cartList.valid;
  879. if (valid.length > 0) {
  880. valid.forEach(j => {
  881. j.valid.forEach(item => {
  882. if (status) {
  883. if (that.footerswitch) {
  884. if (item.attrStatus && !item.is_gift) {
  885. item.checked = true;
  886. selectValue.push(item.id);
  887. } else {
  888. item.checked = false;
  889. }
  890. } else {
  891. item.checked = true;
  892. selectValue.push(item.id);
  893. }
  894. that.isAllSelect = true;
  895. } else {
  896. item.checked = false;
  897. that.isAllSelect = false;
  898. }
  899. })
  900. })
  901. that.$set(that.cartList, 'valid', valid);
  902. that.selectValue = selectValue;
  903. that.switchSelect();
  904. }
  905. },
  906. checkboxChange: function(event) {
  907. let that = this;
  908. let value = event.detail.value;
  909. let valid = that.cartList.valid;
  910. let arr1 = [];
  911. let arr2 = [];
  912. let arr3 = [];
  913. let len = 0;
  914. valid.forEach(j => {
  915. j.valid.forEach(item => {
  916. len = len + 1;
  917. if (that.inArray(item.id, value)) {
  918. if (that.footerswitch) {
  919. if (item.attrStatus && !item.is_gift) {
  920. item.checked = true;
  921. arr1.push(item);
  922. } else {
  923. item.checked = false;
  924. }
  925. } else {
  926. item.checked = true;
  927. arr1.push(item);
  928. }
  929. } else {
  930. item.checked = false;
  931. arr2.push(item);
  932. }
  933. })
  934. })
  935. if (that.footerswitch) {
  936. arr3 = arr2.filter(item => !item.attrStatus || item.is_gift);
  937. }
  938. that.$set(that.cartList, 'valid', valid);
  939. that.isAllSelect = len === arr1.length + arr3.length;
  940. that.selectValue = value;
  941. that.switchSelect();
  942. },
  943. inArray: function(search, array) {
  944. for (let i in array) {
  945. if (array[i] == search) {
  946. return true;
  947. }
  948. }
  949. return false;
  950. },
  951. switchSelect: function() {
  952. let that = this;
  953. let validList = that.cartList.valid;
  954. let selectValue = that.selectValue;
  955. let selectCountPrice = 0.00;
  956. let cartId = [];
  957. if (selectValue.length < 1) {
  958. that.selectCountPrice = selectCountPrice;
  959. } else {
  960. for (let j in validList) {
  961. for (let index in validList[j].valid) {
  962. if (that.inArray(validList[j].valid[index].id, selectValue)) {
  963. cartId.push(validList[j].valid[index].id)
  964. selectCountPrice = that.$util.$h.Add(selectCountPrice, that.$util.$h.Mul(validList[j]
  965. .valid[index]
  966. .cart_num, validList[j].valid[
  967. index].truePrice))
  968. }
  969. }
  970. }
  971. that.selectCountPrice = selectCountPrice;
  972. }
  973. let data = {
  974. cartId: cartId.join(',')
  975. }
  976. if (cartId.length) {
  977. this.getCartCompute(data);
  978. }
  979. },
  980. setValue: Debounce(function(e,item){
  981. let num = e.detail.value, that = this;
  982. if (item.productInfo.limit_num > 0 && num > item.productInfo.limit_num) {
  983. item.cart_num = item.productInfo.limit_num;
  984. return this.$util.Tips({
  985. title: '购物车数量不能大于限购数量'
  986. });
  987. }
  988. that.setCartNum(item.id, item.cart_num, function(data) {
  989. that.getCartNum();
  990. that.loadend = false;
  991. that.loading = false;
  992. that.page = 1;
  993. that.getCartList('addCart');
  994. });
  995. }),
  996. subCart: Debounce(function(jindex, index) {
  997. let that = this;
  998. let status = false;
  999. let item = that.cartList.valid[jindex].valid[index];
  1000. item.cart_num = Number(item.cart_num) - 1;
  1001. if (item.cart_num < 1) status = true;
  1002. if (item.cart_num <= 1) {
  1003. item.cart_num = 1;
  1004. item.numSub = true;
  1005. } else {
  1006. item.numSub = false;
  1007. item.numAdd = false;
  1008. }
  1009. if (false == status) {
  1010. that.setCartNum(item.id, item.cart_num, function(data) {
  1011. that.cartList.valid[jindex].valid[index] = item;
  1012. that.getCartNum();
  1013. that.loadend = false;
  1014. that.page = 1;
  1015. that.getCartList('subCart');
  1016. });
  1017. }
  1018. }),
  1019. addCart: Debounce(function(jindex, index, obj) {
  1020. let that = this;
  1021. let item = that.cartList.valid[jindex].valid[index];
  1022. if (obj.numAdd || (obj.productInfo.limit_num > 0 && obj.cart_num >= obj.productInfo.limit_num)) {
  1023. item.cart_num = item.productInfo.limit_num;
  1024. return this.$util.Tips({
  1025. title: '购物车数量不能大于限购数量'
  1026. });
  1027. }
  1028. item.cart_num = Number(item.cart_num) + 1;
  1029. let productInfo = item.productInfo;
  1030. if (productInfo.hasOwnProperty('attrInfo') && item.cart_num >= item.productInfo.attrInfo.stock) {
  1031. item.cart_num = item.productInfo.attrInfo.stock;
  1032. item.numAdd = true;
  1033. item.numSub = false;
  1034. } else {
  1035. item.numAdd = false;
  1036. item.numSub = false;
  1037. }
  1038. that.setCartNum(item.id, item.cart_num, function(data) {
  1039. that.cartList.valid[jindex].valid[index] = item;
  1040. that.getCartNum();
  1041. that.loadend = false;
  1042. that.page = 1;
  1043. that.getCartList('addCart');
  1044. });
  1045. }),
  1046. setCartNum(cartId, cartNum, successCallback) {
  1047. let that = this;
  1048. changeCartNum(cartId, cartNum).then(res => {
  1049. successCallback && successCallback(res.data);
  1050. });
  1051. },
  1052. getCartNum: function() {
  1053. let that = this;
  1054. let id = uni.getStorageSync('user_store_id') || 0;
  1055. getCartCounts(0,id).then(res => {
  1056. this.$store.commit('indexData/setCartNum', res.data.count)
  1057. if (res.data.count > 0) {
  1058. wx.setTabBarBadge({
  1059. index: 3,
  1060. text: res.data.count + ''
  1061. })
  1062. } else {
  1063. wx.hideTabBarRedDot({
  1064. index: 3
  1065. })
  1066. }
  1067. });
  1068. },
  1069. // 购物车计算
  1070. getCartCompute(cartId) {
  1071. cartCompute(cartId).then(res => {
  1072. this.discountInfo.coupon = res.data.coupon;
  1073. this.discountInfo.deduction = res.data.deduction;
  1074. this.discountInfo.svip_price = res.data.svip_price;
  1075. this.discountInfo.svip_status = res.data.svip_status;
  1076. }).catch(err => {
  1077. this.$util.Tips({
  1078. title: err
  1079. })
  1080. })
  1081. },
  1082. getCartList: function(handle) {
  1083. let that = this;
  1084. if (this.loadend) return false;
  1085. if (this.loading) return false;
  1086. let data = {
  1087. page: that.page,
  1088. limit: that.limit,
  1089. status: 1,
  1090. latitude: uni.getStorageSync('user_latitude'),
  1091. longitude: uni.getStorageSync('user_longitude'),
  1092. store_id: uni.getStorageSync('user_store_id'),
  1093. }
  1094. getCartList(data).then(res => {
  1095. this.getInvalidList();
  1096. // this.discountInfo.deduction = res.data.deduction;
  1097. // this.discountInfo.coupon = res.data.coupon;
  1098. this.isTips = false;
  1099. let cartList = res.data.valid;
  1100. let valid = cartList.map(x => {
  1101. return {
  1102. valid: x.cart,
  1103. promotions: x.promotions
  1104. }
  1105. })
  1106. let loadend = valid.length < that.limit;
  1107. // let validList = that.$util.SplitArray(valid, that.cartList.valid);
  1108. let validList = valid;
  1109. let numSub = [{
  1110. numSub: true
  1111. }, {
  1112. numSub: false
  1113. }];
  1114. let numAdd = [{
  1115. numAdd: true
  1116. }, {
  1117. numAdd: false
  1118. }],
  1119. selectValue = [];
  1120. if (validList.length > 0) {
  1121. for (let j in validList) {
  1122. if (validList[j].promotions.length > 1) {
  1123. that.isTips = true;
  1124. }
  1125. for (let index in validList[j].valid) {
  1126. if (validList[j].valid[index].cart_num == 1) {
  1127. validList[j].valid[index].numSub = true;
  1128. } else {
  1129. validList[j].valid[index].numSub = false;
  1130. }
  1131. let productInfo = validList[j].valid[index].productInfo;
  1132. if (productInfo.hasOwnProperty('attrInfo') && validList[j].valid[index]
  1133. .cart_num == validList[j].valid[index].productInfo.attrInfo.stock) {
  1134. validList[j].valid[index].numAdd = true;
  1135. } else if (validList[j].valid[index].cart_num == validList[j].valid[index]
  1136. .productInfo.stock) {
  1137. validList[j].valid[index].numAdd = true;
  1138. } else {
  1139. validList[j].valid[index].numAdd = false;
  1140. }
  1141. if (validList[j].valid[index].attrStatus && !validList[j].valid[index]
  1142. .is_gift) {
  1143. if (['addCart', 'subCart'].includes(handle)) {
  1144. validList[j].valid[index].checked = false;
  1145. for (let k = 0; k < that.selectValue.length; k++) {
  1146. if (that.selectValue[k] == validList[j].valid[index].id) {
  1147. validList[j].valid[index].checked = true;
  1148. break;
  1149. }
  1150. }
  1151. if (validList[j].valid[index].checked) {
  1152. selectValue.push(validList[j].valid[index].id);
  1153. }
  1154. } else {
  1155. validList[j].valid[index].checked = true;
  1156. selectValue.push(validList[j].valid[index].id);
  1157. }
  1158. } else if (!this.footerswitch) {
  1159. validList[j].valid[index].checked = true;
  1160. } else {
  1161. validList[j].valid[index].checked = false;
  1162. }
  1163. }
  1164. }
  1165. }
  1166. that.$set(that.cartList, 'valid', res.data.valid.length ? validList : []);
  1167. that.loadend = true;
  1168. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  1169. that.page = that.page + 1;
  1170. that.loading = false;
  1171. // that.goodsHidden = cartList.valid.length <= 0 ? false : true;
  1172. that.selectValue = selectValue;
  1173. let newArr = [],
  1174. newAttr = [];
  1175. validList.forEach(j => {
  1176. j.valid.forEach(item => {
  1177. if (item.attrStatus && !item.is_gift) {
  1178. newArr.push(item)
  1179. }
  1180. let obj = {
  1181. id: item.product_id,
  1182. num: item.cart_num
  1183. }
  1184. newAttr.push(obj)
  1185. })
  1186. })
  1187. that.isAllSelect = newArr.length == selectValue.length && newArr.length;
  1188. that.switchSelect();
  1189. uni.$emit('newAttrNum', newAttr)
  1190. }).catch(function(err) {
  1191. that.loading = false;
  1192. that.loadTitle = '加载失败';
  1193. that.$util.Tips({
  1194. title: err
  1195. })
  1196. })
  1197. },
  1198. getInvalidList: function() {
  1199. let that = this;
  1200. if (this.loadendInvalid) return false;
  1201. if (this.loadingInvalid) return false;
  1202. let data = {
  1203. page: that.pageInvalid,
  1204. limit: that.limitInvalid,
  1205. status: 0,
  1206. store_id: uni.getStorageSync('user_store_id'),
  1207. }
  1208. getCartList(data).then(res => {
  1209. let cartList = res.data,
  1210. invalid = cartList.invalid,
  1211. loadendInvalid = invalid.length < that.limitInvalid;
  1212. // let invalidList = that.$util.SplitArray(invalid, that.cartList.invalid);
  1213. let invalidList = invalid;
  1214. that.$set(that.cartList, 'invalid', invalidList);
  1215. that.loadendInvalid = loadendInvalid;
  1216. that.loadTitleInvalid = loadendInvalid ? '没有更多内容啦~' : '加载更多';
  1217. that.pageInvalid = that.pageInvalid + 1;
  1218. that.loadingInvalid = false;
  1219. }).catch(res => {
  1220. that.loadingInvalid = false;
  1221. that.loadTitleInvalid = '加载更多';
  1222. })
  1223. },
  1224. getHostProduct: function() {
  1225. let that = this;
  1226. if (that.hotScroll) return
  1227. getProductHot(
  1228. that.hotPage,
  1229. that.hotLimit,
  1230. ).then(res => {
  1231. that.hotPage++
  1232. that.hotScroll = res.data.length < that.hotLimit
  1233. that.hostProduct = that.hostProduct.concat(res.data)
  1234. });
  1235. },
  1236. goodsOpen: function() {
  1237. let that = this;
  1238. that.goodsHidden = !that.goodsHidden;
  1239. },
  1240. manage: function() {
  1241. let that = this;
  1242. that.footerswitch = !that.footerswitch;
  1243. let arr1 = [];
  1244. let arr2 = [];
  1245. let len = 0;
  1246. that.cartList.valid.forEach(j => {
  1247. j.valid.forEach(item => {
  1248. len = len + 1;
  1249. if (that.footerswitch) {
  1250. if (item.attrStatus && !item.is_gift) {
  1251. if (item.checked) {
  1252. arr1.push(item.id);
  1253. }
  1254. } else {
  1255. item.checked = false;
  1256. arr2.push(item);
  1257. }
  1258. } else {
  1259. if (item.checked) {
  1260. arr1.push(item.id);
  1261. }
  1262. }
  1263. })
  1264. })
  1265. if (that.footerswitch) {
  1266. that.isAllSelect = len === arr1.length + arr2.length;
  1267. } else {
  1268. that.isAllSelect = len === arr1.length;
  1269. }
  1270. that.selectValue = arr1;
  1271. if (that.footerswitch) {
  1272. that.switchSelect();
  1273. }
  1274. },
  1275. unsetCart: function() {
  1276. let that = this,
  1277. ids = [],
  1278. storeId = uni.getStorageSync('user_store_id');
  1279. for (let i = 0, len = that.cartList.invalid.length; i < len; i++) {
  1280. ids.push(that.cartList.invalid[i].id);
  1281. }
  1282. cartDel(ids,storeId).then(res => {
  1283. that.$util.Tips({
  1284. title: '清除成功'
  1285. });
  1286. that.$set(that.cartList, 'invalid', []);
  1287. that.getCartNum();
  1288. }).catch(res => {
  1289. });
  1290. },
  1291. customBtn(type,id){
  1292. if(type == 0){
  1293. collectAll(id).then(res => {
  1294. return this.$util.Tips({
  1295. title: res.msg,
  1296. icon: 'success'
  1297. });
  1298. }).catch(err => {
  1299. return this.$util.Tips({
  1300. title: err
  1301. });
  1302. });
  1303. }else{
  1304. let storeId = uni.getStorageSync('user_store_id');
  1305. cartDel(id,storeId).then(res => {
  1306. this.loadend = false;
  1307. this.page = 1;
  1308. this.cartList.valid = [];
  1309. this.getCartList();
  1310. this.getCartNum();
  1311. });
  1312. }
  1313. },
  1314. goPage(type, url){
  1315. if(type == 1){
  1316. uni.navigateTo({
  1317. url
  1318. })
  1319. }else if(type == 2){
  1320. uni.switchTab({
  1321. url
  1322. })
  1323. }else if(type == 3){
  1324. uni.navigateBack();
  1325. }
  1326. }
  1327. },
  1328. onPageScroll(e) {
  1329. uni.$emit('scroll');
  1330. },
  1331. onReachBottom() {
  1332. let that = this;
  1333. that.getHostProduct();
  1334. }
  1335. }
  1336. </script>
  1337. <style scoped lang="scss">
  1338. /deep/.tui-swipeout-wrap{
  1339. border-radius: 0 0 24rpx 0;
  1340. }
  1341. .text-primary-con {
  1342. color: var(--view-theme);
  1343. }
  1344. .bg-primary-light {
  1345. background: var(--view-minorColorT);
  1346. }
  1347. .fixed_bt {
  1348. z-index: 999;
  1349. }
  1350. .max-120{
  1351. max-width: 120rpx;
  1352. }
  1353. .tips {
  1354. position: fixed;
  1355. z-index: 9;
  1356. width: 100%;
  1357. height: 56rpx;
  1358. background: #FEF4E7;
  1359. color: #FE960F;
  1360. font-size: 24rpx;
  1361. padding: 0 20rpx;
  1362. box-sizing: border-box;
  1363. bottom: 192rpx;
  1364. bottom: calc(192rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  1365. bottom: calc(192rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  1366. .iconfont {
  1367. margin-right: 12rpx;
  1368. }
  1369. &.on {
  1370. // #ifndef H5
  1371. bottom: 96rpx;
  1372. // #endif
  1373. }
  1374. }
  1375. .bg-collect{
  1376. background:var(--view-bntColor);
  1377. }
  1378. .del_btn{
  1379. border-radius:0 0 24rpx 0;
  1380. }
  1381. .border_ccc {
  1382. border: 1px solid #ccc;
  1383. }
  1384. .border_con {
  1385. border: 1px solid var(--view-theme);
  1386. }
  1387. .uni-p-b-96 {
  1388. height: 96rpx;
  1389. }
  1390. .w-322{
  1391. width: 322rpx;
  1392. }
  1393. .max-w-322{
  1394. max-width: 322rpx;
  1395. }
  1396. .con_border{
  1397. border: 1rpx solid var(--view-theme);
  1398. }
  1399. .disabled-tag{
  1400. border: 1px solid rgba(255, 125, 0, .3);
  1401. color: rgba(255, 125, 0, .3);
  1402. }
  1403. .icon-ic_Disable{
  1404. color: #ddd;
  1405. font-size: 37rpx;
  1406. }
  1407. .text--w111-ccc{
  1408. color: #ccc;
  1409. }
  1410. .over{
  1411. width:104rpx;
  1412. height:104rpx;
  1413. border-radius: 50%;
  1414. background-color: rgba(51, 51, 51, 0.6);
  1415. position: absolute;
  1416. top:50%;
  1417. left:50%;
  1418. transform: translate(-50%,-50%);
  1419. }
  1420. </style>