DetailFooter.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <!-- footer.vue -->
  2. <template>
  3. <view
  4. class="div ui-detail-footer"
  5. v-if="detailInfo"
  6. v-bind:class="{
  7. 'hidden-cart-footer': ispromotion,
  8. 'show-cart-footer': !ispromotion
  9. }"
  10. >
  11. <view class="div footer-flex">
  12. <view class="div left">
  13. <view class="div item" v-on:click="goNavigate('/pages/home/storedetail/Storedetail',{id:storeInfo.store_id})">
  14. <text class="span iconfont">&#xe69f;</text>
  15. <text class="span text">店铺</text>
  16. </view>
  17. <view class="div item" v-if="config && config.instant_message_open == '1' && config.instant_message_gateway_url" v-on:click="goChat()">
  18. <text class="span iconfont">&#xe6f1;</text>
  19. <text class="span text">客服</text>
  20. </view>
  21. <view class="div item" v-on:click="goCart()">
  22. <text class="span iconfont">&#xe6ae;</text>
  23. <text class="span icon" v-if="cartNumber > 0">{{ getCarCount }}</text>
  24. <text class="span text">购物车</text>
  25. </view>
  26. </view>
  27. <view class="div right">
  28. <view class="div right-wrapper">
  29. <view
  30. class="div button "
  31. :class="canBuy?'active-cart':'disabled-cart'"
  32. v-on:click="addShopping(true)"
  33. v-if="!detailInfo.bargain_info && ((!detailInfo.pintuan_type && detailInfo.cart) || (detailInfo.pintuan_type && (detailInfo.pintuangroup_list.length || detailInfo.pintuanorder_state)))"
  34. >
  35. {{addCartText}}
  36. </view>
  37. <view
  38. class="div button "
  39. :class="canBuy?'active-buy':'disabled-buy'"
  40. v-on:click="checkout()"
  41. >
  42. {{buyNowText}}
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="p good-stock-none" v-if="detailInfo.goods_state != 1 || detailInfo.goods_verify!=1">
  48. 所选产品已下架,非常抱歉!
  49. </view>
  50. <view class="p good-stock-none" v-else-if="detailInfo.goods_storage <= 0">
  51. 所选产品暂时无货,非常抱歉!
  52. </view>
  53. <shopping></shopping>
  54. <translate></translate>
  55. <!-- 加入购物车显示动画 -->
  56. <view class="div ui-cart-animation" v-if="isAnimation">
  57. <uni-load-more status="loading" color="#e93b3d"></uni-load-more>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { urlencode } from '@/util/common'
  63. import { mapState, mapMutations } from 'vuex'
  64. import shopping from './child/Shopping'
  65. import translate from './child/Translate'
  66. import { cartQuantity } from '../../../api/homecart'
  67. import { addBargain } from '../../../api/memberBargain'
  68. export default {
  69. data () {
  70. return {
  71. addCartText: '加入购物车',
  72. buyNowText: '立即购买',
  73. cartNumber: 0,
  74. isAnimation: false // 加入购物车成功之后是否显示动画
  75. }
  76. },
  77. components: {
  78. shopping,
  79. translate
  80. },
  81. props: {
  82. ishidefooter: {
  83. type: Boolean,
  84. default: false
  85. }
  86. },
  87. computed: {
  88. ...mapState({
  89. config: state => state.config.config,
  90. user: state => state.member.info,
  91. storeInfo: state => state.goodsdetail.storeInfo,
  92. detailInfo: state => state.goodsdetail.detailInfo,
  93. specList: state => state.goodsdetail.specList,
  94. isOnline: state => state.member.isOnline,
  95. ispromotion: state => state.goodsdetail.ispromotion,
  96. // cartNumber: state => state.tabBar.cartNumber,
  97. chooseinfo: state => state.goodsdetail.chooseinfo,
  98. number: state => state.goodsdetail.number
  99. }),
  100. canBuy () {
  101. if (this.detailInfo.goods_storage > 0 && this.detailInfo.goods_state == 1 && this.detailInfo.goods_verify == 1) {
  102. return true
  103. } else {
  104. return false
  105. }
  106. },
  107. getCarCount () {
  108. if (this.cartNumber > 0 && this.cartNumber < 100) {
  109. return this.cartNumber
  110. } else if (this.cartNumber >= 100) {
  111. return '99+'
  112. }
  113. }
  114. },
  115. created () {
  116. if (this.detailInfo.bargain_info) {
  117. if (this.detailInfo.bargainorder_info) {
  118. if (this.detailInfo.bargainorder_info.bargainorder_state == 2) {
  119. this.buyNowText = '砍价成功去下单'
  120. } else {
  121. this.buyNowText = '正在砍价'
  122. }
  123. } else {
  124. this.buyNowText = '发起砍价'
  125. }
  126. } else if (this.detailInfo.pintuan_type) {
  127. if (this.detailInfo.pintuanorder_state) {
  128. if (this.detailInfo.pintuanorder_state == 1) {
  129. this.addCartText = '参团中'
  130. } else {
  131. this.addCartText = '已成团'
  132. }
  133. this.buyNowText = '原价购买'
  134. } else {
  135. this.addCartText = '参加拼团'
  136. this.buyNowText = '立刻开团'
  137. }
  138. } else if (this.detailInfo.presell_type) {
  139. this.buyNowText = '预售购买'
  140. } else if (this.detailInfo.is_goodsfcode == 1) {
  141. this.buyNowText = 'F码购买'
  142. }
  143. uni.$on('start-addcart-animation', () => {
  144. this.isAnimation = true
  145. })
  146. uni.$on('end-addcart-animation', () => {
  147. this.isAnimation = false
  148. this.saveCartState(false)
  149. })
  150. this.getCartCount()
  151. uni.$on('update-cart-num', () => {
  152. this.getCartCount()
  153. })
  154. },
  155. beforeDestroy: function () {
  156. uni.$off('start-addcart-animation')
  157. uni.$off('end-addcart-animation')
  158. uni.$off('update-cart-num')
  159. },
  160. methods:{
  161. goNavigate(path,query=false){
  162. uni.navigateTo({url:path+(query?('?'+urlencode(query)):'')})
  163. },
  164. ...mapMutations({
  165. saveCartState: 'saveCartState',
  166. changeType: 'changeType',
  167. saveSelectedCartGoods: 'saveSelectedCartGoods'
  168. }),
  169. goChat () {
  170. if (!this.user) {
  171. uni.showToast({icon:'none',title: '请先登录'})
  172. } else if (this.user.member_id == this.storeInfo.member_id) {
  173. uni.showToast({icon:'none',title: '不能和自己聊天'})
  174. } else {
  175. uni.navigateTo({ url: '/pages/member/chat/ChatInfo'+'?'+urlencode( { t_id: this.storeInfo.member_id, t_name: this.storeInfo.store_name, goods_id: this.detailInfo.goods_id } )})
  176. }
  177. },
  178. getCartCount () {
  179. if (this.isOnline) {
  180. cartQuantity().then(res => {
  181. if (res) {
  182. this.cartNumber = res.result.cart_count
  183. }
  184. })
  185. }
  186. },
  187. // 加入购物车
  188. addShopping (value) {
  189. this.saveCartState(value)
  190. this.changeType('确定')
  191. },
  192. // 立即购买
  193. checkout () {
  194. if (!this.canBuy) {
  195. return
  196. }
  197. if (this.specList && Object.keys(this.specList).length > 1) {
  198. this.addShopping(true)
  199. return
  200. }
  201. if (this.user) {
  202. if (this.user.store_id == this.storeInfo.store_id) {
  203. uni.showToast({icon:'none',title: '不能购买自己的商品'})
  204. return
  205. }
  206. } else {
  207. uni.navigateTo({ url: '/pages/home/memberlogin/Login' })
  208. return
  209. }
  210. if (this.detailInfo.is_virtual == '1') {
  211. let params = { goods_id: this.detailInfo.goods_id, quantity: 1 }
  212. if (this.detailInfo.pintuan_type && !this.detailInfo.pintuanorder_state) {
  213. params['pintuan_id'] = this.detailInfo.pintuan_id
  214. params['pintuangroup_id'] = 0
  215. }
  216. uni.navigateTo({ url: '/pages/member/vrbuy/step1'+'?'+urlencode( params )})
  217. } else {
  218. let params = { buy_now: 1, cart_id: this.detailInfo.goods_id + '|1' }
  219. if (this.detailInfo.bargain_info) {
  220. if (this.detailInfo.bargainorder_info) {
  221. if (this.detailInfo.bargainorder_info.bargainorder_state == 2) {
  222. params['bargainorder_id'] = this.detailInfo.bargainorder_info.bargainorder_id
  223. } else {
  224. uni.navigateTo({ url: '/pages/home/bargain/Bargainshare'+'?'+urlencode( { bargainorder_id: this.detailInfo.bargainorder_info.bargainorder_id } )})
  225. return
  226. }
  227. } else {
  228. // 新增砍价
  229. addBargain(this.detailInfo.bargain_info.bargain_id).then(res => {
  230. uni.navigateTo({ url: '/pages/home/bargain/Bargainshare'+'?'+urlencode( { bargainorder_id: res.result.bargainorder_id })})
  231. }).catch(function (error) {
  232. uni.showToast({icon:'none',title: error.message})
  233. })
  234. return
  235. }
  236. } else if (this.detailInfo.pintuan_type && !this.detailInfo.pintuanorder_state) {
  237. params['pintuan_id'] = this.detailInfo.pintuan_id
  238. params['pintuangroup_id'] = 0
  239. }
  240. uni.navigateTo({ url: '/pages/member/buy/step1'+'?'+urlencode( params )})
  241. }
  242. },
  243. // 购物车
  244. goCart () {
  245. if (this.isOnline) {
  246. uni.navigateTo({ url: '/pages/member/cart/Cart', params: { type: 0 } })
  247. } else {
  248. uni.navigateTo({ url: '/pages/home/memberlogin/Login' })
  249. }
  250. },
  251. /*
  252. * fromatArray: 格式化数组
  253. */
  254. fromatArray (delimiter, arrays) {
  255. let data = ''
  256. if (delimiter) {
  257. data = arrays.join(delimiter)
  258. }
  259. return delimiter ? data : arrays
  260. },
  261. /*
  262. * isHasStock: 是否还有库存
  263. */
  264. isHasStock (id) {
  265. let data = this.detailInfo.stock
  266. if (data.length > 0) {
  267. for (let i = 0, len = data.length; i <= len - 1; i++) {
  268. if (data[i].goods_attr == id) {
  269. return '' + data[i].stock_number + ''
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. .ui-detail-footer {
  279. background: rgba(255, 255, 255, 1);
  280. border-top: 0.5px solid #e8eaed;
  281. width: auto;
  282. position: fixed;
  283. bottom: var(--window-bottom);
  284. left: 0;
  285. right: 0;
  286. z-index: 0;
  287. &.hidden-cart-footer {
  288. display: none;
  289. }
  290. &.show-cart-footer {
  291. display: block;
  292. }
  293. .footer-flex {
  294. display: flex;
  295. justify-content: space-between;
  296. align-content: center;
  297. align-items: center;
  298. height: $footerHeight;
  299. padding-bottom: constant(safe-area-inset-bottom);/*兼容 IOS<11.2*/padding-bottom: env(safe-area-inset-bottom);/*兼容 IOS>11.2*/box-sizing: content-box;
  300. }
  301. .p.good-stock-none {
  302. width: 100%;
  303. height: 1.6rem;
  304. background: #c3c3c3;
  305. opacity: 0.5;
  306. font-size:$subFontSize;
  307. color: #333;
  308. position: absolute;
  309. text-align: center;
  310. line-height: 1.6rem;
  311. padding: 0;
  312. margin: 0;
  313. bottom: 3rem;
  314. }
  315. .div.left {
  316. display: flex;
  317. justify-content: center;
  318. align-items: center;
  319. width: 7.5rem;
  320. .item{flex:1;text-align: center;line-height: 1;position:relative;
  321. .iconfont {
  322. flex-shrink: 0;
  323. font-size:1.3rem;
  324. }
  325. .text{font-size:$h6;color:gray;display: block}
  326. }
  327. .span.icon {
  328. position: absolute;
  329. right: 0;
  330. top: 0;
  331. font-size:$h6;
  332. line-height: 0.7rem;
  333. width: 0.9rem;
  334. height: 0.7rem;
  335. background: #ef3338;
  336. border-radius: 1rem;
  337. text-align: center;
  338. color: #ffffff;
  339. }
  340. }
  341. .div.right {
  342. flex: 1;
  343. align-items: center;
  344. padding-right:$pageSpace;
  345. .right-wrapper{
  346. display: flex;
  347. flex-direction: row;
  348. border-radius:2rem;
  349. overflow: hidden;
  350. }
  351. .button {
  352. flex: 1;
  353. height: 2rem;
  354. font-size:$subFontSize;
  355. display:flex;align-items:center;justify-content:center;
  356. color: #ffffff;
  357. text-align: center;
  358. line-height: 2rem;
  359. cursor: pointer;
  360. }
  361. .disabled-cart {
  362. background: #c3c3c3;
  363. }
  364. .active-cart {
  365. background: $primaryColor;
  366. }
  367. .disabled-buy {
  368. background: #999999;
  369. }
  370. .active-buy {
  371. background: #000;
  372. }
  373. }
  374. }
  375. .ui-cart-animation {
  376. position: fixed;
  377. top: 50%;
  378. left: 50%;
  379. }
  380. </style>