create-order.vue 12 KB

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