create-order.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <template>
  2. <view class="container order clearfix" :style="{paddingBottom :isIphoneX ? '170rpx' : '134rpx'}">
  3. <!-- 地址选择 -->
  4. <choice-address ref="choiceAddress" v-if="isAddress" :addressData="addressData"></choice-address>
  5. <!-- 商品 -->
  6. <goods-list ref='goods' v-if="isRequest" :goodsData="goodsData" @handleGoodList="handChangeInputGoodsList"></goods-list>
  7. <!-- 发票信息 -->
  8. <invoice-tent ref="invoice"
  9. v-if="isRequest"
  10. :invoiceDatas="invoiceData"
  11. @handleChoiceaInvoice="handleChoiceaInvoiceData">
  12. </invoice-tent>
  13. <!-- 运费 -->
  14. <freight ref="freight"
  15. v-if="isFreight"
  16. :freightData="freightData"
  17. @confirmFreight="hanldFreightFn"
  18. @confirmFreightBeans = "hanldFreightBeans"
  19. >
  20. </freight>
  21. <freight-alert v-if="isfreightTip" ref="csPhone"></freight-alert>
  22. <!-- 余额抵扣 -->
  23. <view class="invoice-balance" v-show="!rechargeGoods">
  24. <view class="balabce-t">
  25. <view class="balabce-t-le">余额抵扣</view>
  26. <view class="balabce-t-ri">
  27. <view class="money">
  28. <text>可用余额:</text>
  29. <text>¥{{userMoney | NumFormat}}</text>
  30. </view>
  31. <view class="checkbox-box">
  32. <button class="checkbox iconfont"
  33. hover-class="btn-hover"
  34. v-if="userMoney!=0"
  35. @click.stop="checkedBalabce"
  36. :class="[ischecked ?'icon-yixuanze':'icon-weixuanze']"
  37. >
  38. </button>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="balabce-b" :class="{'balabce-b--hide':!ischecked}">
  43. <view class="balabce-b-text animation" :style="{'transform':ischecked?'translateY(0)':'translateY(-50%)','-webkit-transform':ischecked?'translateY(0)':'translateY(-50%)'}">
  44. <text>当前使用:¥{{deductMoney | NumFormat}},剩余:¥{{surplusMoney | NumFormat}}</text>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 底部 -->
  49. <view class="footer" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
  50. <view class="footer-le">
  51. <view class="footer-count">
  52. <text>共{{allCount}}件商品</text>
  53. </view>
  54. <view class="footer-price">
  55. <view class="sum-none" v-if="reducedPrice>0">
  56. <text class="money-sign">¥</text>
  57. <text class="money">{{ totalOriginalPrice | NumFormat }}</text>
  58. <text class="money-reduced">减<text>¥{{ reducedPrice | NumFormat}}</text></text>
  59. </view>
  60. <view class="sum" :class="reducedPrice == 0 ? 'none' : ''">总价:<text class="price">¥{{payAllPrice | NumFormat}}</text></view>
  61. </view>
  62. </view>
  63. <view class="footer-submit" @click.stop="orderSubmitMit">
  64. <view class="btn" :class="isSubLoading ? 'disabled' : ''" >提交订单</view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import choiceAddress from '@/components/cm-module/creatOrder/choiceAddress'
  71. import goodsList from '@/components/cm-module/creatOrder/goodsList'
  72. import invoiceTent from '@/components/cm-module/creatOrder/invoiceTent'
  73. import freight from '@/components/cm-module/creatOrder/freight'
  74. import freightAlert from '@/components/cm-module/modelAlert/freightAlert'
  75. export default {
  76. components:{
  77. choiceAddress,
  78. goodsList,
  79. invoiceTent,
  80. freight,
  81. freightAlert
  82. },
  83. data() {
  84. return {
  85. isIphoneX:this.$store.state.isIphoneX,
  86. isSubLoading:false,
  87. orderID:0,
  88. productIds:'', // 获取上一级页面商品信息
  89. productCount:'', // 获取上一级页面商品数量
  90. classifyIDS:'', // 获取上一级页面商品分类
  91. userID:'', // 用户ID
  92. cartType:'', // 购买类型(1购物车提交,2直接购买提交)
  93. submitState:'', // 提交状态
  94. balanceDeductionFlag:2, // 勾选余额的状态(1使用,2不使用)
  95. allCount:1, // 订单提交总数量
  96. totalOriginalPrice:0, // 订单总原价(划线部分)
  97. reducedPrice:0, // 满减金额
  98. payAllPrice:0.00, // 订单提交总金额
  99. allPrice:0.00, // 订单总金额
  100. surplusMoney:0.00, // 显示勾选后的剩余抵扣
  101. userMoney:0.00, // 显示可使用余额
  102. deductMoney:0.00, // 显示已使用的余额
  103. addressID:'', // 地址ID
  104. townID:'', // 区ID
  105. isRequest:false, // 是否加载完成渲染子组件
  106. isFreight:false, // 是否加载完成渲染子组件
  107. isAddress:false, // 是否加载完成地址
  108. isfreightTip:false, // 控制邮费弹窗
  109. ischecked:false, // 是否勾选余额
  110. hanldFreePostFlag:'', // 邮费状态
  111. hanldFreight:'', // 邮费
  112. addressData:{}, // 初始化地址信息
  113. goodsData:[], // 初始化商品信息
  114. invoiceData:{type:0}, // 初始化发票信息
  115. freightData:{}, // 邮费数据
  116. orderInfo:[], // 提交的商品信息
  117. payInfo:{}, // 订单信息
  118. rechargeGoods:null, // 判断订单里有定金商品或者充值商品时,余额抵扣部分不显示
  119. freightBeansMoney:0, // 存储采美豆抵扣金额
  120. hanldUserBeans:0, // 抵扣的采美豆数
  121. isCheckedBeans:false, // 是否抵扣采美豆
  122. }
  123. },
  124. onLoad(option){//商品数据
  125. let data = JSON.parse(option.data);
  126. if(option.type =='prodcut'){
  127. this.cartType = 2
  128. this.productCount = data.data.productCount
  129. this.productIds = data.data.productID
  130. }else{
  131. this.cartType = 1
  132. this.productCount = data.data.productCount
  133. this.productIds = data.data.productID
  134. }
  135. this.$api.getStorage().then((resolve) =>{
  136. this.userID = resolve.userId ? resolve.userId : 0
  137. this.getInitCrearOrder(option);
  138. })
  139. },
  140. filters:{
  141. NumFormat(value) {//处理金额
  142. return Number(value).toFixed(2);
  143. },
  144. },
  145. methods: {
  146. getInitCrearOrder(option){//获取订单商品信息
  147. this.OrderService.CreateOrderInfo({
  148. userId:this.userID,
  149. count:this.productCount,
  150. productIds:this.productIds,
  151. unionId:uni.getStorageSync('unionId')
  152. })
  153. .then(response =>{
  154. let resData = response.data
  155. this.isRequest = true
  156. this.goodsData = resData.list
  157. this.userMoney = resData.userMoney
  158. this.reducedPrice = resData.reducedPrice
  159. this.allPrice = this.payAllPrice = resData.totalPrice
  160. this.totalOriginalPrice = resData.totalOriginalPrice
  161. this.rechargeGoods = resData.rechargeGoods
  162. })
  163. .catch(error =>{
  164. this.$util.msg(error.msg,2000)
  165. })
  166. },
  167. getFreightData(){//获取邮费信息
  168. let params ={
  169. userId:this.userID,
  170. productIds:this.productIds,
  171. totalPrice:this.allPrice,
  172. townId:this.addressData.townID
  173. }
  174. this.OrderService.GetOrderPostage(params).then(response =>{
  175. this.isFreight = true
  176. this.isCheckedBeans = false
  177. this.freightData = response.data
  178. this.hanldFreePostFlag = response.data.freePostFlag
  179. this.hanldFreight = response.data.freight
  180. if(this.hanldFreePostFlag == 1){
  181. if( this.freightData.userBeans >= this.hanldFreight*100 ){
  182. this.freightBeansMoney = this.hanldFreight
  183. }else{
  184. this.freightBeansMoney = 0
  185. }
  186. this.payAllPrice = this.allPrice + response.data.freight
  187. this.attributePallPrice()
  188. this.hanldFreightBeans(this.isCheckedBeans)
  189. }else{
  190. if( this.freightData.userBeans >= 3000 ){
  191. this.freightBeansMoney = 30
  192. }else{
  193. this.freightBeansMoney = 0
  194. }
  195. this.payAllPrice = this.allPrice
  196. this.attributePallPrice()
  197. this.hanldFreightBeans(this.isCheckedBeans)
  198. }
  199. })
  200. },
  201. getAddressData(){//获取地址信息
  202. this.$api.getStorage().then((resolve) => {
  203. this.UserService.QueryAddressList({pageNum:1,pageSize:1,userID:resolve.userId}).then(response =>{
  204. this.isAddress = true
  205. this.addressData = {}
  206. if(response.data.results != ''){
  207. this.addressID = response.data.results[0].addressID;
  208. this.townID = response.data.results[0].townID;
  209. this.addressData = response.data.results[0];
  210. this.getFreightData()
  211. }else{
  212. this.addressData = this.addressData;
  213. }
  214. })
  215. })
  216. },
  217. handChangeInputGoodsList(data){//对应供应商的留言信息
  218. this.goodsData = data;
  219. },
  220. handleChoiceaInvoiceData(data){//获取发票信息
  221. this.invoiceData = data
  222. },
  223. hanldFreightFn(data){//显示邮费弹窗
  224. console.log(data)
  225. switch(data.freePostFlag){
  226. case 1:
  227. this.hanldFreight = this.freightData.freight
  228. this.hanldFreePostFlag = data.freePostFlag
  229. this.freightBeansMoney = data.freightBeansMoney
  230. this.payAllPrice =this.allPrice + this.hanldFreight
  231. this.attributePallPrice()
  232. this.hanldFreightBeans(this.isCheckedBeans)
  233. break
  234. case -1:
  235. this.hanldFreight = 0
  236. this.hanldFreePostFlag = data.freePostFlag
  237. this.freightBeansMoney = data.freightBeansMoney
  238. this.payAllPrice = this.allPrice
  239. this.attributePallPrice()
  240. this.hanldFreightBeans(this.isCheckedBeans)
  241. break
  242. }
  243. },
  244. hanldFreightBeans(data){//是否勾选采美豆抵扣
  245. this.isCheckedBeans = data;
  246. if(this.isCheckedBeans){
  247. // 判断如果采美豆大于等于运费*100
  248. if( this.freightData.userBeans >= this.hanldFreight*100 ){
  249. this.hanldUserBeans = this.freightBeansMoney*100
  250. }else{
  251. this.hanldUserBeans = 0
  252. }
  253. // 计算抵扣后的总价
  254. if(this.hanldFreePostFlag == 1){
  255. this.payAllPrice = this.allPrice + this.hanldFreight - this.freightBeansMoney
  256. console.log('抵扣',this.payAllPrice)
  257. }
  258. }else{
  259. this.hanldUserBeans = 0
  260. // 不抵扣时计算总价
  261. if(this.hanldFreePostFlag == 1){
  262. this.payAllPrice = this.allPrice + this.hanldFreight
  263. console.log('不抵扣',this.payAllPrice)
  264. }
  265. }
  266. },
  267. checkedBalabce(){//勾选使用余额
  268. if(this.userMoney > 0){
  269. this.ischecked = !this.ischecked
  270. if(this.ischecked){
  271. this.balanceDeductionFlag =1
  272. this.attributePallPrice()
  273. this.hanldFreightBeans(this.isCheckedBeans)
  274. }else{
  275. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  276. this.payAllPrice = this.allPrice+parseInt(this.freightData.freight)
  277. }else{
  278. this.payAllPrice = this.allPrice
  279. }
  280. this.balanceDeductionFlag = 2
  281. }
  282. }else{
  283. return
  284. }
  285. },
  286. attributePallPrice(){//计算价格
  287. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  288. this.attributeHashfreight(this.freightData.freight)
  289. }else{
  290. this.attributeNofreight()
  291. }
  292. },
  293. attributeNofreight(){//计算没有邮费的支付价格
  294. if(this.ischecked){
  295. if(this.userMoney>this.payAllPrice){
  296. this.payAllPrice = 0.00
  297. this.deductMoney = this.allPrice //勾选后使用抵余额
  298. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  299. }else{
  300. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  301. this.deductMoney = this.userMoney //勾选后使用抵余额
  302. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  303. }
  304. }else{
  305. this.payAllPrice = this.allPrice;
  306. this.deductMoney = 0.00;
  307. this.surplusMoney = this.userMoney;
  308. }
  309. },
  310. attributeHashfreight(freight){//计算需要邮费的支付价格
  311. this.payAllPrice = this.allPrice+parseInt(freight)//计算不包邮的价格 总价等于商品价格+邮费
  312. if(this.ischecked){
  313. if(this.userMoney>this.payAllPrice){ //余额大于支付金额
  314. this.payAllPrice =0.00
  315. this.deductMoney = this.allPrice+parseInt(freight) //勾选后使用抵余额
  316. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  317. }else{
  318. this.payAllPrice = this.allPrice+parseInt(freight) - this.userMoney //勾选后的总价
  319. this.deductMoney = this.userMoney //勾选后使用抵余额
  320. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  321. }
  322. }else{
  323. this.payAllPrice = this.allPrice+parseInt(freight)
  324. this.deductMoney = 0.00
  325. this.surplusMoney = this.userMoney
  326. }
  327. },
  328. orderSubmitMit(){//提交订单
  329. if(this.isSubLoading){ return; }
  330. if(this.addressID == ''){
  331. this.$util.msg('请先添加收货地址~',2000)
  332. return
  333. }
  334. this.orderInfo = this.goodsData.map(el => {
  335. let productInfo = [];
  336. el.cartList.forEach(item => {
  337. productInfo.push({
  338. productId:item.productId,
  339. productNum:item.number,
  340. presentNum:0,
  341. productType:item.productType
  342. })
  343. })
  344. return {shopId:el.id,note:el.note?el.note:'',productInfo:productInfo}
  345. })
  346. //订单信息
  347. this.payInfo = {
  348. clauseId:0,//条款(暂时保留)
  349. orderShouldPayFee:this.payAllPrice.toFixed(2),//提交的总价
  350. balancePayFlag:this.balanceDeductionFlag,//余额抵扣的状态
  351. freight:parseInt(this.hanldFreight).toFixed(2),//邮费
  352. freePostFlag:parseInt(this.hanldFreePostFlag),//运费形式
  353. userBeans:this.hanldUserBeans
  354. }
  355. let param = {
  356. orderSource:6,
  357. clubUserId:this.userID,
  358. cartType:this.cartType,
  359. addressId:this.addressID,
  360. orderInfo:this.orderInfo,
  361. payInfo:this.payInfo, //订单信息
  362. orderInvoice:this.invoiceData
  363. }
  364. console.log(param)
  365. this.isSubLoading = true;
  366. this.OrderService.CreatedOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  367. const data = response.data;
  368. // 友盟埋点收集机构自主提交订单
  369. if(process.env.NODE_ENV != 'development'){
  370. this.$uma.trackEvent('Um_Event_ConfirmOrder', {
  371. Um_Key_PageName: '机构提交订单',
  372. Um_Key_SourcePage: '确认订单',
  373. Um_Key_OrderID:`${data.orderID}`
  374. })
  375. }
  376. if(data.code === '1'){
  377. this.submitState ='success'
  378. setTimeout(()=>{
  379. this.isSubLoading = false;
  380. },2000)
  381. let data = {orderID:response.data.orderID}
  382. this.$api.navigateTo(`/pages/user/order/success?data=${JSON.stringify({data:data})}`)
  383. }else{
  384. this.submitState ='confirm'
  385. this.$util.msg('订单提交成功',3000,true,'success')
  386. setTimeout(()=>{
  387. this.isSubLoading = false;
  388. },2000)
  389. setTimeout(()=>{
  390. this.$api.redirectTo(`/pages/user/order/order-payment?type=${this.submitState}&orderID=${response.data.orderID}`)
  391. },3000)
  392. }
  393. }).catch(error =>{
  394. this.$util.msg(error.msg,3000);
  395. })
  396. },
  397. handFreightAlertShow(){//显示邮费弹窗
  398. this.isfreightTip = true;
  399. },
  400. hideFreight(){//关闭邮费弹窗
  401. this.isfreightTip = false;
  402. },
  403. },
  404. onShow() {
  405. // this.addressID = ''
  406. let pages = getCurrentPages();
  407. let currPage = pages[pages.length-1];
  408. if(currPage.data.select =='select'){
  409. this.isAddress = true
  410. let SelectData = uni.getStorageSync('selectAddress');
  411. this.addressID = SelectData.addressID;
  412. this.addressData = SelectData
  413. this.getFreightData()
  414. }else{
  415. this.getAddressData()
  416. }
  417. }
  418. }
  419. </script>
  420. <style lang="scss">
  421. page {
  422. height: auto;
  423. background:#F7F7F7;
  424. }
  425. .btn-hover{
  426. background: #FFFFFF;
  427. }
  428. .animation{
  429. /* transition: transform 0.3s ease;*/
  430. transition-property: transform;
  431. transition-duration: 0.3s;
  432. transition-timing-function: ease;
  433. }
  434. .order{
  435. padding-bottom: 134rpx;
  436. }
  437. .invoice-freight{
  438. width: 702rpx;
  439. padding: 0 24rpx;
  440. height: auto;
  441. font-size: $font-size-28;
  442. color: $text-color;
  443. background: #FFFFFF;
  444. float: left;
  445. font-weight: bold;
  446. }
  447. .invoice-balance{
  448. width: 702rpx;
  449. height: auto;
  450. padding:0 24rpx;
  451. background: #FFFFFF;
  452. float: left;
  453. margin-top: 24rpx;
  454. margin-bottom: 24rpx;
  455. .balabce-t{
  456. width: 100%;
  457. height: 86rpx;
  458. line-height: 86rpx;
  459. font-size: $font-size-28;
  460. color: $text-color;
  461. float: left;
  462. .balabce-t-le{
  463. float: left;
  464. font-weight: bold;
  465. }
  466. .balabce-t-ri{
  467. float: right;
  468. display: flex;
  469. align-items: center;
  470. .money{
  471. display: flex;
  472. float: left;
  473. }
  474. .checkbox-box{
  475. display: flex;
  476. width: 60rpx;
  477. float: left;
  478. height: 100%;
  479. font-size: $font-size-24;
  480. .checkbox{
  481. width: 40rpx;
  482. text-align: right;
  483. box-sizing: border-box;
  484. text-align: center;
  485. text-decoration: none;
  486. border-radius: 0;
  487. -webkit-tap-highlight-color: transparent;
  488. overflow: hidden;
  489. color: $color-system;
  490. }
  491. }
  492. }
  493. }
  494. .balabce-b{
  495. width: 100%;
  496. float: left;
  497. overflow: hidden;
  498. .balabce-b-text{
  499. width: 100%;
  500. line-height: 58rpx;
  501. font-size: $font-size-24;
  502. color: #FF2A2A;
  503. text-align: right;
  504. float: right;
  505. }
  506. &.balabce-b--hide {
  507. padding: 0 0;
  508. height: 0px;
  509. line-height: 0px;
  510. }
  511. }
  512. }
  513. .footer{
  514. position: fixed;
  515. left: 0;
  516. bottom: 0;
  517. z-index: 995;
  518. display: flex;
  519. align-items: center;
  520. width: 100%;
  521. height: 110rpx;
  522. line-height: 110rpx;
  523. justify-content: space-between;
  524. font-size: $font-size-28;
  525. background-color: #FFFFFF;
  526. z-index: 998;
  527. color: $text-color;
  528. .footer-le{
  529. width:570rpx;
  530. height:100%;
  531. float: left;
  532. }
  533. .footer-count{
  534. float: left;
  535. padding-left: 24rpx;
  536. width:180rpx;
  537. box-sizing: border-box;
  538. }
  539. .footer-price{
  540. width:370rpx;
  541. float: right;
  542. text-align: right;
  543. color: $text-color;
  544. padding: 10rpx 20rpx 10rpx 0;
  545. box-sizing: border-box;
  546. .sum-none{
  547. width: 100%;
  548. height: 45rpx;
  549. line-height: 45rpx;
  550. color: $text-color;
  551. float: left;
  552. text-align: right;
  553. .money{
  554. font-size: $font-size-26;
  555. color: #999999;
  556. text-decoration: line-through;
  557. }
  558. .money-sign{
  559. font-size: $font-size-26;
  560. color: #999999;
  561. text-decoration: line-through;
  562. }
  563. .money-reduced{
  564. margin-left: 10rpx;
  565. font-size: $font-size-26;
  566. color:$color-system;
  567. }
  568. }
  569. .sum{
  570. width: 100%;
  571. height: 45rpx;
  572. line-height: 45rpx;
  573. float: left;
  574. &.none{
  575. height: 90rpx;
  576. line-height: 90rpx;
  577. }
  578. .price{
  579. font-size: $font-size-32;
  580. color: #FF2A2A;
  581. }
  582. }
  583. }
  584. .footer-submit{
  585. display:flex;
  586. align-items:center;
  587. justify-content: center;
  588. width: 180rpx;
  589. height: 100%;
  590. box-sizing: border-box;
  591. padding: 15rpx 5rpx;
  592. .btn{
  593. width: 100%;
  594. height: 100%;
  595. color: #FFFFFF;
  596. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  597. font-size: $font-size-26;
  598. text-align: center;
  599. line-height: 80rpx;
  600. border-radius: 40rpx;
  601. &.disabled{
  602. background: #e4e8eb;
  603. color: #999999;
  604. }
  605. }
  606. }
  607. }
  608. </style>