create-order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <view class="container order clearfix">
  3. <!-- 透明模态层 -->
  4. <modal-layer v-if='modallayer'></modal-layer>
  5. <!-- 地址选择 -->
  6. <choice-address ref="choiceAddress" v-if="isAddress" :addressData="addressData"></choice-address>
  7. <!-- 商品 -->
  8. <goods-list ref='goods' v-if="isRequest" :goodsData="goodsData" @handleGoodList="handChangeInputGoodsList"></goods-list>
  9. <!-- 发票信息 -->
  10. <invoice-tent ref="invoice"
  11. v-if="isRequest"
  12. :invoiceData="invoiceData"
  13. @handleChoiceaInvoice="handleChoiceaInvoiceData">
  14. </invoice-tent>
  15. <!-- 运费 -->
  16. <freight ref="freight" v-if="isRequest" :freightData="freightData" @showFreightAlert="handFreightAlertShow"></freight>
  17. <freight-alert v-if="isfreightTip" ref="csPhone"></freight-alert>
  18. <!-- 余额抵扣 -->
  19. <view class="invoice-balance">
  20. <view class="balabce-t">
  21. <view class="balabce-t-le">余额抵扣</view>
  22. <view class="balabce-t-ri">
  23. <view class="money">
  24. <text>可用余额:</text>
  25. <text>¥{{userMoney.toFixed(2)}}</text>
  26. </view>
  27. <view class="checkbox-box">
  28. <button class="checkbox iconfont"
  29. hover-class="btn-hover"
  30. v-if="userMoney!=0"
  31. @click.stop="checkedBalabce"
  32. :class="[ischecked ?'icon-gouxuanl':'icon-weigouxuan']"
  33. >
  34. </button>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="balabce-b" :class="{'balabce-b--hide':!ischecked}">
  39. <view class="balabce-b-text animation" :style="{'transform':ischecked?'translateY(0)':'translateY(-50%)','-webkit-transform':ischecked?'translateY(0)':'translateY(-50%)'}">
  40. <text>当前使用:¥{{deductMoney.toFixed(2)}},剩余:¥{{surplusMoney.toFixed(2)}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 底部 -->
  45. <view class="footer" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
  46. <view class="footer-le">
  47. <view class="footer-count">
  48. <text>共{{allCount}}件商品</text>
  49. </view>
  50. <view class="footer-price">
  51. <text>总价:<text class="price">¥{{payAllPrice.toFixed(2)}}</text></text>
  52. </view>
  53. </view>
  54. <view class="footer-submit" @click.stop="orderSubmitMit">提交订单</view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import choiceAddress from '@/components/module/creatOrder/choiceAddress'
  60. import goodsList from '@/components/module/creatOrder/goodsList'
  61. import invoiceTent from '@/components/module/creatOrder/invoiceTent'
  62. import freight from '@/components/module/creatOrder/freight'
  63. import freightAlert from '@/components/module/modelAlert/freightAlert'
  64. import modalLayer from "@/components/modal-layer"
  65. import { queryAddressList } from "@/api/cart.js"
  66. import { createOrderInfo,createOrderSubmit,getOrderPostage } from "@/api/order.js"
  67. export default {
  68. components:{
  69. choiceAddress,
  70. goodsList,
  71. invoiceTent,
  72. freight,
  73. freightAlert,
  74. modalLayer
  75. },
  76. data() {
  77. return {
  78. modallayer:false,
  79. orderID:0,
  80. productIds:'', //获取上一级页面商品信息
  81. productCount:'', //获取上一级页面商品数量
  82. classifyIDS:'', //获取上一级页面商品分类
  83. userID:'', //用户ID
  84. cartType:'', //购买类型(1购物车提交,2直接购买提交)
  85. submitState:'', //提交状态
  86. balanceDeductionFlag:2, //勾选余额的状态(1使用,2不使用)
  87. allCount:1, //订单提交总数量
  88. payAllPrice:0.00, //订单提交总金额
  89. allPrice:0.00, //订单总金额
  90. surplusMoney:0.00, //显示勾选后的剩余抵扣
  91. userMoney:0.00, //显示可使用余额
  92. deductMoney:0.00, //显示已使用的余额
  93. addressID:'', //地址ID
  94. townID:'', //区ID
  95. isRequest:false, //是否加载完成渲染子组件
  96. isAddress:false, //是否加载完成地址
  97. isfreightTip:false, //控制邮费弹窗
  98. ischecked:false, //是否勾选余额
  99. addressData:{}, //初始化地址信息
  100. goodsData:[], //初始化商品信息
  101. invoiceData:{}, //初始化发票信息
  102. freightData:{}, //邮费数据
  103. orderInfo:[], //提交的商品信息
  104. payInfo:{}, //订单信息
  105. isIphoneX:this.$store.state.isIphoneX
  106. }
  107. },
  108. onLoad(option){//商品数据
  109. let data = JSON.parse(option.data);
  110. console.log(data)
  111. this.allPrice = data.data.allPrice;
  112. this.allCount = data.data.allCount;
  113. this.payAllPrice = this.allPrice;
  114. // console.log(data)
  115. if(option.type =='prodcut'){
  116. this.cartType = 2
  117. this.productCount = data.data.productCount
  118. this.productIds = data.data.productID
  119. // this.classifyIDS = data.data.classifyID
  120. }else{
  121. this.cartType = 1
  122. this.productCount = data.data.productCount
  123. this.productIds = data.data.productID
  124. // this.classifyIDS = data.data.classifyID
  125. }
  126. this.getInitCrearOrder(option);
  127. // this.getAddressData()
  128. },
  129. methods: {
  130. getInitCrearOrder(option){//获取订单商品信息
  131. this.$api.getStorage().then((resolve) =>{
  132. this.userID = resolve.userID
  133. let params ={userId:this.userID,count:this.productCount,productIds:this.productIds}
  134. createOrderInfo(params).then(response =>{
  135. let resData = response.data
  136. this.isRequest = true
  137. this.goodsData = resData.shopList
  138. this.userMoney = resData.userMoney
  139. this.getUseFindInvoice()
  140. }).catch(response =>{
  141. this.$util.msg(response.msg,2000)
  142. })
  143. })
  144. },
  145. getFreightData(){//获取邮费信息
  146. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  147. let params ={
  148. userId:resolve.userID,
  149. productIds:this.productIds,
  150. totalPrice:this.allPrice,
  151. townId:this.addressData.townID
  152. }
  153. getOrderPostage(params).then(response =>{
  154. console.log(response)
  155. this.isFreight = true
  156. this.freightData = response.data
  157. if(response.data.freePostFlag== 1){
  158. this.payAllPrice = this.payAllPrice+response.data.freight
  159. }
  160. })
  161. })
  162. },
  163. getUseFindInvoice(){//获取发票信息
  164. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  165. getFindInvoice({userID:resolve.userID}).then(response =>{
  166. if(response.data == null){
  167. this.invoiceData = Object.assign(this.invoiceData,'',{type:0})
  168. }else{
  169. this.invoiceData = response.data
  170. }
  171. })
  172. })
  173. },
  174. getAddressData(){//获取地址信息
  175. this.$api.getStorage().then((resolve) =>{
  176. queryAddressList({pageNum:1,pageSize:1,userID:resolve.userID}).then(response =>{
  177. this.isAddress = true
  178. this.addressData = {}
  179. if(response.data.results != ''){
  180. this.addressID = response.data.results[0].addressID;
  181. this.townID = response.data.results[0].townID;
  182. this.addressData = response.data.results[0];
  183. this.getFreightData()
  184. }else{
  185. this.addressData = this.addressData;
  186. }
  187. })
  188. })
  189. },
  190. handChangeInputGoodsList(data){//对应供应商的留言信息
  191. this.goodsData = data;
  192. // console.log(this.goodsData)
  193. },
  194. handleChoiceaInvoiceData(data){//获取发票信息
  195. console.log(data)
  196. this.invoiceData = data
  197. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  198. let params =Object.assign(data,'',{userID:resolve.userID})
  199. updateInvoice(params).then(response =>{
  200. console.log(response)
  201. })
  202. })
  203. },
  204. checkedBalabce(){//勾选使用余额
  205. if(this.userMoney == 0){
  206. return
  207. }else{
  208. this.ischecked = !this.ischecked
  209. if(this.ischecked){
  210. this.balanceDeductionFlag =1
  211. if(this.userMoney>this.payAllPrice){
  212. this.payAllPrice =0.00
  213. this.deductMoney = this.allPrice //勾选后使用抵余额
  214. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  215. }else{
  216. this.payAllPrice = this.allPrice - this.userMoney //勾选后的总价
  217. this.deductMoney = this.userMoney //勾选后使用抵余额
  218. this.surplusMoney = this.userMoney - this.deductMoney //勾选后的剩余抵扣
  219. }
  220. }else{
  221. this.payAllPrice = this.allPrice
  222. this.balanceDeductionFlag = 2
  223. }
  224. }
  225. },
  226. orderSubmitMit(){//提交订单
  227. if(this.addressID == ''){
  228. this.$util.msg('请先添加收货地址~',2000)
  229. return
  230. }
  231. this.orderInfo = this.goodsData.map(el => {
  232. let productInfo = [];
  233. el.productsList.forEach(item => {
  234. productInfo.push({
  235. productId:item.productID,
  236. productNum:item.productCount,
  237. presentNum:0
  238. })
  239. })
  240. if(el.note == null){
  241. el.note = ''
  242. }else{
  243. el.note = el.note
  244. }
  245. return {shopId:el.shopID,note:el.note,productInfo:productInfo}
  246. })
  247. //订单信息
  248. this.payInfo = {
  249. clauseId:0,//条款(暂时保留)
  250. orderShouldPayFee:this.payAllPrice,//提交的总价
  251. balancePayFlag:this.balanceDeductionFlag,//余额抵扣的状态
  252. freight:this.freightData.freight,//邮费
  253. freePostFlag:this.freightData.freePostFlag//运费形式
  254. }
  255. let param = {
  256. orderSource:1,
  257. clubUserId:this.userID,
  258. cartType:this.cartType,
  259. addressId:this.addressID,
  260. orderInfo:this.orderInfo,
  261. payInfo:this.payInfo, //订单信息
  262. orderInvoice:this.invoiceData
  263. }
  264. this.modalLayer = true;
  265. // console.log(JSON.stringify(param))
  266. createOrderSubmit({'params':JSON.stringify(param)}).then(response =>{
  267. if(response.code === 1){
  268. this.submitState ='success'
  269. let data = {orderID:response.data.orderID}
  270. this.$api.navigateTo(`/pages/user/order/order-cashier?type=${this.submitState}&data=${JSON.stringify({data:data})}`)
  271. }else if(response.code === 2){
  272. this.submitState ='nosuccess'
  273. let data = {
  274. orderID:response.data.orderID,
  275. orderNo:response.data.orderNo,
  276. orderMark:response.data.orderMark,
  277. payableAmount:response.data.payableAmount
  278. }
  279. this.$api.navigateTo(`/pages/user/order/order-cashier?type=${this.submitState}&data=${JSON.stringify({data:data})}`)
  280. }else{
  281. this.$util.msg(response.msg,2000);
  282. }
  283. }).catch(response =>{})
  284. },
  285. handFreightAlertShow(){//显示邮费弹窗
  286. this.isfreightTip = true;
  287. },
  288. hideFreight(){//关闭邮费弹窗
  289. this.isfreightTip = false;
  290. },
  291. },
  292. onShow() {
  293. // this.addressID = ''
  294. let pages = getCurrentPages();
  295. let currPage = pages[pages.length-1];
  296. if(currPage.data.select =='select'){
  297. this.isAddress = true
  298. let SelectData = uni.getStorageSync('selectAddress');
  299. this.addressID = SelectData.addressID;
  300. this.addressData = SelectData
  301. this.getFreightData()
  302. }else{
  303. this.getAddressData()
  304. }
  305. }
  306. }
  307. </script>
  308. <style lang="scss">
  309. page {
  310. height: auto;
  311. background:#F7F7F7;
  312. }
  313. .btn-hover{
  314. background: #FFFFFF;
  315. }
  316. .animation{
  317. /* transition: transform 0.3s ease;*/
  318. transition-property: transform;
  319. transition-duration: 0.3s;
  320. transition-timing-function: ease;
  321. }
  322. .order{
  323. padding-bottom: 134rpx;
  324. }
  325. .invoice-freight{
  326. width: 702rpx;
  327. padding: 0 24rpx;
  328. height: 86rpx;
  329. line-height: 86rpx;
  330. font-size: $font-size-28;
  331. color: $text-color;
  332. background: #FFFFFF;
  333. float: left;
  334. font-weight: bold;
  335. .freight-left{
  336. float: left;
  337. .icon-yunfeishuoming{
  338. height: 100%;
  339. padding: 0 15rpx;
  340. color: $color-system;
  341. font-weight: normal;
  342. }
  343. }
  344. .freight-right{
  345. float: right;
  346. color: #2A81FF;
  347. }
  348. }
  349. .invoice-balance{
  350. width: 702rpx;
  351. height: auto;
  352. padding:0 24rpx;
  353. background: #FFFFFF;
  354. float: left;
  355. margin-top: 24rpx;
  356. margin-bottom: 24rpx;
  357. .balabce-t{
  358. width: 100%;
  359. height: 86rpx;
  360. line-height: 86rpx;
  361. font-size: $font-size-28;
  362. color: $text-color;
  363. float: left;
  364. .balabce-t-le{
  365. float: left;
  366. font-weight: bold;
  367. }
  368. .balabce-t-ri{
  369. float: right;
  370. display: flex;
  371. align-items: center;
  372. .money{
  373. display: flex;
  374. float: left;
  375. }
  376. .checkbox-box{
  377. display: flex;
  378. width: 60rpx;
  379. float: left;
  380. height: 100%;
  381. font-size: $font-size-24;
  382. .checkbox{
  383. width: 40rpx;
  384. text-align: right;
  385. box-sizing: border-box;
  386. text-align: center;
  387. text-decoration: none;
  388. border-radius: 0;
  389. -webkit-tap-highlight-color: transparent;
  390. overflow: hidden;
  391. color: $color-system;
  392. }
  393. }
  394. }
  395. }
  396. .balabce-b{
  397. width: 100%;
  398. float: left;
  399. overflow: hidden;
  400. .balabce-b-text{
  401. width: 100%;
  402. line-height: 58rpx;
  403. font-size: $font-size-24;
  404. color: #FF2A2A;
  405. text-align: right;
  406. float: right;
  407. }
  408. &.balabce-b--hide {
  409. padding: 0 0;
  410. height: 0px;
  411. line-height: 0px;
  412. }
  413. }
  414. }
  415. .footer{
  416. position: fixed;
  417. left: 0;
  418. bottom: 0;
  419. z-index: 995;
  420. display: flex;
  421. align-items: center;
  422. width: 100%;
  423. height: 110rpx;
  424. line-height: 110rpx;
  425. justify-content: space-between;
  426. font-size: $font-size-28;
  427. background-color: #FFFFFF;
  428. z-index: 998;
  429. color: $text-color;
  430. .footer-le{
  431. width:550rpx;
  432. height:100%;
  433. float: left;
  434. }
  435. .footer-count{
  436. float: left;
  437. padding-left: 24rpx;
  438. font-weight: bold;
  439. }
  440. .footer-price{
  441. float: right;
  442. text-align: right;
  443. color: $text-color;
  444. font-weight: bold;
  445. padding-right: 24rpx;
  446. .price{
  447. font-size: $font-size-32;
  448. color: #FF2A2A;
  449. }
  450. }
  451. .footer-submit{
  452. display:flex;
  453. align-items:center;
  454. justify-content: center;
  455. width: 200rpx;
  456. height: 100%;
  457. color: #FFFFFF;
  458. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  459. }
  460. }
  461. </style>