create-order.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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.freightData = response.data
  177. this.hanldFreePostFlag = response.data.freePostFlag
  178. this.hanldFreight = response.data.freight
  179. if(this.hanldFreePostFlag == 1){
  180. this.freightBeansMoney = response.data.freight
  181. this.payAllPrice = this.allPrice + response.data.freight
  182. this.attributePallPrice()
  183. }else{
  184. this.freightBeansMoney = 30
  185. this.payAllPrice = this.allPrice
  186. this.attributePallPrice()
  187. }
  188. })
  189. },
  190. getAddressData(){//获取地址信息
  191. this.$api.getStorage().then((resolve) => {
  192. this.UserService.QueryAddressList({pageNum:1,pageSize:1,userID:resolve.userId}).then(response =>{
  193. this.isAddress = true
  194. this.addressData = {}
  195. if(response.data.results != ''){
  196. this.addressID = response.data.results[0].addressID;
  197. this.townID = response.data.results[0].townID;
  198. this.addressData = response.data.results[0];
  199. this.getFreightData()
  200. }else{
  201. this.addressData = this.addressData;
  202. }
  203. })
  204. })
  205. },
  206. handChangeInputGoodsList(data){//对应供应商的留言信息
  207. this.goodsData = data;
  208. },
  209. handleChoiceaInvoiceData(data){//获取发票信息
  210. this.invoiceData = data
  211. },
  212. hanldFreightFn(data){//显示邮费弹窗
  213. console.log(data)
  214. switch(data.freePostFlag){
  215. case 1:
  216. this.hanldFreight = this.freightData.freight
  217. this.hanldFreePostFlag = data.freePostFlag
  218. this.freightBeansMoney = data.freightBeansMoney
  219. this.payAllPrice =this.allPrice + this.hanldFreight
  220. this.attributePallPrice()
  221. this.hanldFreightBeans(this.isCheckedBeans)
  222. break
  223. case -1:
  224. this.hanldFreight = 0
  225. this.hanldFreePostFlag = data.freePostFlag
  226. this.freightBeansMoney = data.freightBeansMoney
  227. this.payAllPrice = this.allPrice
  228. this.attributePallPrice()
  229. this.hanldFreightBeans(this.isCheckedBeans)
  230. break
  231. }
  232. },
  233. hanldFreightBeans(data){//是否勾选采美豆抵扣
  234. this.isCheckedBeans = data;
  235. if(this.isCheckedBeans){
  236. this.hanldUserBeans = this.freightBeansMoney*100
  237. if(this.hanldFreePostFlag == 1){
  238. this.payAllPrice = this.allPrice + this.hanldFreight - this.freightBeansMoney
  239. console.log('抵扣',this.payAllPrice)
  240. }
  241. }else{
  242. this.hanldUserBeans = 0
  243. if(this.hanldFreePostFlag == 1){
  244. this.payAllPrice = this.allPrice + this.hanldFreight
  245. console.log('不抵扣',this.payAllPrice)
  246. }
  247. }
  248. },
  249. checkedBalabce(){//勾选使用余额
  250. if(this.userMoney > 0){
  251. this.ischecked = !this.ischecked
  252. if(this.ischecked){
  253. this.balanceDeductionFlag =1
  254. this.attributePallPrice()
  255. }else{
  256. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  257. this.payAllPrice = this.allPrice+parseInt(this.freightData.freight)
  258. }else{
  259. this.payAllPrice = this.allPrice
  260. }
  261. this.balanceDeductionFlag = 2
  262. }
  263. }else{
  264. return
  265. }
  266. },
  267. attributePallPrice(){//计算价格
  268. if(this.hanldFreePostFlag == 1 || this.hanldFreePostFlag == '1'){
  269. this.attributeHashfreight(this.freightData.freight)
  270. }else{
  271. this.attributeNofreight()
  272. }
  273. },
  274. attributeNofreight(){//计算没有邮费的支付价格
  275. if(this.ischecked){
  276. if(this.userMoney>this.payAllPrice){
  277. this.payAllPrice = 0.00
  278. this.deductMoney = this.allPrice //勾选后使用抵余额
  279. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  280. }else{
  281. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  282. this.deductMoney = this.userMoney //勾选后使用抵余额
  283. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  284. }
  285. }else{
  286. this.payAllPrice = this.allPrice;
  287. this.deductMoney = 0.00;
  288. this.surplusMoney = this.userMoney;
  289. }
  290. },
  291. attributeHashfreight(freight){//计算需要邮费的支付价格
  292. this.payAllPrice = this.allPrice+parseInt(freight)//计算不包邮的价格 总价等于商品价格+邮费
  293. if(this.ischecked){
  294. if(this.userMoney>this.payAllPrice){ //余额大于支付金额
  295. this.payAllPrice =0.00
  296. this.deductMoney = this.allPrice+parseInt(freight) //勾选后使用抵余额
  297. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  298. }else{
  299. this.payAllPrice = this.allPrice+parseInt(freight) - this.userMoney //勾选后的总价
  300. this.deductMoney = this.userMoney //勾选后使用抵余额
  301. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  302. }
  303. }else{
  304. this.payAllPrice = this.allPrice+parseInt(freight)
  305. this.deductMoney = 0.00
  306. this.surplusMoney = this.userMoney
  307. }
  308. },
  309. orderSubmitMit(){//提交订单
  310. if(this.isSubLoading){ return; }
  311. if(this.addressID == ''){
  312. this.$util.msg('请先添加收货地址~',2000)
  313. return
  314. }
  315. this.orderInfo = this.goodsData.map(el => {
  316. let productInfo = [];
  317. el.cartList.forEach(item => {
  318. productInfo.push({
  319. productId:item.productId,
  320. productNum:item.number,
  321. presentNum:0,
  322. productType:item.productType
  323. })
  324. })
  325. return {shopId:el.id,note:el.note?el.note:'',productInfo:productInfo}
  326. })
  327. //订单信息
  328. this.payInfo = {
  329. clauseId:0,//条款(暂时保留)
  330. orderShouldPayFee:this.payAllPrice.toFixed(2),//提交的总价
  331. balancePayFlag:this.balanceDeductionFlag,//余额抵扣的状态
  332. freight:parseInt(this.hanldFreight).toFixed(2),//邮费
  333. freePostFlag:parseInt(this.hanldFreePostFlag),//运费形式
  334. userBeans:this.hanldUserBeans
  335. }
  336. let param = {
  337. orderSource:6,
  338. clubUserId:this.userID,
  339. cartType:this.cartType,
  340. addressId:this.addressID,
  341. orderInfo:this.orderInfo,
  342. payInfo:this.payInfo, //订单信息
  343. orderInvoice:this.invoiceData
  344. }
  345. console.log(param)
  346. this.isSubLoading = true;
  347. this.OrderService.CreatedOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  348. const data = response.data;
  349. // 友盟埋点收集机构自主提交订单
  350. if(process.env.NODE_ENV != 'development'){
  351. this.$uma.trackEvent('Um_Event_ConfirmOrder', {
  352. Um_Key_PageName: '机构提交订单',
  353. Um_Key_SourcePage: '确认订单',
  354. Um_Key_OrderID:`${data.orderID}`
  355. })
  356. }
  357. if(data.code === '1'){
  358. this.submitState ='success'
  359. setTimeout(()=>{
  360. this.isSubLoading = false;
  361. },2000)
  362. let data = {orderID:response.data.orderID}
  363. this.$api.navigateTo(`/pages/user/order/success?data=${JSON.stringify({data:data})}`)
  364. }else{
  365. this.submitState ='confirm'
  366. this.$util.msg('订单提交成功',3000,true,'success')
  367. setTimeout(()=>{
  368. this.isSubLoading = false;
  369. },2000)
  370. setTimeout(()=>{
  371. this.$api.redirectTo(`/pages/user/order/order-payment?type=${this.submitState}&orderID=${response.data.orderID}`)
  372. },3000)
  373. }
  374. }).catch(error =>{
  375. this.$util.msg(error.msg,3000);
  376. })
  377. },
  378. handFreightAlertShow(){//显示邮费弹窗
  379. this.isfreightTip = true;
  380. },
  381. hideFreight(){//关闭邮费弹窗
  382. this.isfreightTip = false;
  383. },
  384. },
  385. onShow() {
  386. // this.addressID = ''
  387. let pages = getCurrentPages();
  388. let currPage = pages[pages.length-1];
  389. if(currPage.data.select =='select'){
  390. this.isAddress = true
  391. let SelectData = uni.getStorageSync('selectAddress');
  392. this.addressID = SelectData.addressID;
  393. this.addressData = SelectData
  394. this.getFreightData()
  395. }else{
  396. this.getAddressData()
  397. }
  398. }
  399. }
  400. </script>
  401. <style lang="scss">
  402. page {
  403. height: auto;
  404. background:#F7F7F7;
  405. }
  406. .btn-hover{
  407. background: #FFFFFF;
  408. }
  409. .animation{
  410. /* transition: transform 0.3s ease;*/
  411. transition-property: transform;
  412. transition-duration: 0.3s;
  413. transition-timing-function: ease;
  414. }
  415. .order{
  416. padding-bottom: 134rpx;
  417. }
  418. .invoice-freight{
  419. width: 702rpx;
  420. padding: 0 24rpx;
  421. height: auto;
  422. font-size: $font-size-28;
  423. color: $text-color;
  424. background: #FFFFFF;
  425. float: left;
  426. font-weight: bold;
  427. }
  428. .invoice-balance{
  429. width: 702rpx;
  430. height: auto;
  431. padding:0 24rpx;
  432. background: #FFFFFF;
  433. float: left;
  434. margin-top: 24rpx;
  435. margin-bottom: 24rpx;
  436. .balabce-t{
  437. width: 100%;
  438. height: 86rpx;
  439. line-height: 86rpx;
  440. font-size: $font-size-28;
  441. color: $text-color;
  442. float: left;
  443. .balabce-t-le{
  444. float: left;
  445. font-weight: bold;
  446. }
  447. .balabce-t-ri{
  448. float: right;
  449. display: flex;
  450. align-items: center;
  451. .money{
  452. display: flex;
  453. float: left;
  454. }
  455. .checkbox-box{
  456. display: flex;
  457. width: 60rpx;
  458. float: left;
  459. height: 100%;
  460. font-size: $font-size-24;
  461. .checkbox{
  462. width: 40rpx;
  463. text-align: right;
  464. box-sizing: border-box;
  465. text-align: center;
  466. text-decoration: none;
  467. border-radius: 0;
  468. -webkit-tap-highlight-color: transparent;
  469. overflow: hidden;
  470. color: $color-system;
  471. }
  472. }
  473. }
  474. }
  475. .balabce-b{
  476. width: 100%;
  477. float: left;
  478. overflow: hidden;
  479. .balabce-b-text{
  480. width: 100%;
  481. line-height: 58rpx;
  482. font-size: $font-size-24;
  483. color: #FF2A2A;
  484. text-align: right;
  485. float: right;
  486. }
  487. &.balabce-b--hide {
  488. padding: 0 0;
  489. height: 0px;
  490. line-height: 0px;
  491. }
  492. }
  493. }
  494. .footer{
  495. position: fixed;
  496. left: 0;
  497. bottom: 0;
  498. z-index: 995;
  499. display: flex;
  500. align-items: center;
  501. width: 100%;
  502. height: 110rpx;
  503. line-height: 110rpx;
  504. justify-content: space-between;
  505. font-size: $font-size-28;
  506. background-color: #FFFFFF;
  507. z-index: 998;
  508. color: $text-color;
  509. .footer-le{
  510. width:570rpx;
  511. height:100%;
  512. float: left;
  513. }
  514. .footer-count{
  515. float: left;
  516. padding-left: 24rpx;
  517. width:180rpx;
  518. box-sizing: border-box;
  519. }
  520. .footer-price{
  521. width:370rpx;
  522. float: right;
  523. text-align: right;
  524. color: $text-color;
  525. padding: 10rpx 20rpx 10rpx 0;
  526. box-sizing: border-box;
  527. .sum-none{
  528. width: 100%;
  529. height: 45rpx;
  530. line-height: 45rpx;
  531. color: $text-color;
  532. float: left;
  533. text-align: right;
  534. .money{
  535. font-size: $font-size-26;
  536. color: #999999;
  537. text-decoration: line-through;
  538. }
  539. .money-sign{
  540. font-size: $font-size-26;
  541. color: #999999;
  542. text-decoration: line-through;
  543. }
  544. .money-reduced{
  545. margin-left: 10rpx;
  546. font-size: $font-size-26;
  547. color:$color-system;
  548. }
  549. }
  550. .sum{
  551. width: 100%;
  552. height: 45rpx;
  553. line-height: 45rpx;
  554. float: left;
  555. &.none{
  556. height: 90rpx;
  557. line-height: 90rpx;
  558. }
  559. .price{
  560. font-size: $font-size-32;
  561. color: #FF2A2A;
  562. }
  563. }
  564. }
  565. .footer-submit{
  566. display:flex;
  567. align-items:center;
  568. justify-content: center;
  569. width: 180rpx;
  570. height: 100%;
  571. box-sizing: border-box;
  572. padding: 15rpx 5rpx;
  573. .btn{
  574. width: 100%;
  575. height: 100%;
  576. color: #FFFFFF;
  577. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  578. font-size: $font-size-26;
  579. text-align: center;
  580. line-height: 80rpx;
  581. border-radius: 40rpx;
  582. &.disabled{
  583. background: #e4e8eb;
  584. color: #999999;
  585. }
  586. }
  587. }
  588. }
  589. </style>