create-order.vue 17 KB

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