index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <view class="content">
  3. <View :style="{'paddingTop':menuButtonBottom}">
  4. <u-tabs :list="tabList" :scrollable="false" lineWidth="30" lineColor="#FFE05C" :activeStyle="{
  5. color: '#333333',
  6. fontWeight: 'bold',
  7. transform: 'scale(1.05)'
  8. }" :current="tabIndex" @click="clickTab"></u-tabs>
  9. </View>
  10. <!-- 订单列表 -->
  11. <view :style="{'height':windowHeight}">
  12. <swiper :style="{'height':windowHeight}" :current="tabIndex" @change="swiperChange">
  13. <swiper-item class="swiperItem" v-for="(item,index) in tabList" :key="index">
  14. <view>
  15. <mescroll-item ref="MescrollItem" :i="index" :index="tabIndex" :tabs="tabList" :height="windowHeight" @serialNumber="serialNumber" @openPay="openPay" @openPayAppointment="openPayAppointment">
  16. </mescroll-item>
  17. </view>
  18. </swiper-item>
  19. </swiper>
  20. </view>
  21. <view class="tabBarView">
  22. <tab-bar :tabIndex="tabBarIndex"></tab-bar>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import MescrollItem from "./module/mescrollUni-item.vue";
  28. import tabBar from "../../components/tabBar/tabBar";
  29. export default {
  30. components: {
  31. tabBar,
  32. MescrollItem
  33. },
  34. data() {
  35. return {
  36. orderNumberData:{},
  37. num: 0,
  38. title: 'Hello',
  39. tabIndex: 0,
  40. tabBarIndex:3,
  41. currentTab: 0,
  42. currentServiceTab: 'orderTab1',
  43. tabList: [{
  44. name: '全部'
  45. }, {
  46. name: '当前订单'
  47. }, {
  48. name: '待付款'
  49. }, {
  50. name: '已完成'
  51. }],
  52. windowHeight: '',
  53. userInfo:{},
  54. curServiceTab:2,
  55. tradeNo:'',
  56. password:'',
  57. openType:0,//开启的支付类型:1一键支付子订单费用,2:支付预约费用
  58. appointmentOrder:{},
  59. requestStatus : false,
  60. menuButtonBottom:'',
  61. }
  62. },
  63. onLoad() {
  64. uni.hideTabBar({
  65. animation: false
  66. })
  67. let menuButton = uni.getMenuButtonBoundingClientRect()
  68. console.log(menuButton)
  69. this.menuButtonBottom = menuButton.bottom + 'px'
  70. let sysInfo = uni.getSystemInfoSync()
  71. this.windowHeight = sysInfo.windowHeight - menuButton.bottom - 74 + 'px' //除标题栏栏外的屏幕可用高度
  72. this.$off()
  73. this.$on('orderListIndex',this.listenerIndex)
  74. },
  75. onShow(){
  76. this.userInfo = uni.getStorageSync('userInfo')
  77. if (uni.getStorageSync('orderListIndex')){
  78. this.tabIndex = uni.getStorageSync('orderListIndex')
  79. }
  80. uni.removeStorageSync('orderListIndex');
  81. this.$refs.MescrollItem[this.tabIndex].downCallback()
  82. },
  83. methods: {
  84. serialNumber(order){
  85. this.$api.viewNumber(order.orderId).then(res=>{
  86. this.orderNumberData = res.data.data
  87. })
  88. this.$refs.serialNumber.open()
  89. },
  90. openPayAppointment(order,number){
  91. console.log(order)
  92. console.log(number)
  93. this.appointmentOrder = order
  94. this.openType=number
  95. this.$refs.popup.open()
  96. },
  97. //微信支付预约费用
  98. wechatPay(){
  99. let that = this;
  100. // 发起微信支付
  101. this.$api.wechatPay({
  102. orderNo:this.appointmentOrder.subOrderNo
  103. }).then((res)=>{
  104. var param = res.data.data;
  105. uni.requestPayment({
  106. appId: param.appid,
  107. timeStamp: param.timestamp+"",
  108. nonceStr: param.noncestr,
  109. package: "prepay_id="+param.prepayid,
  110. signType: "RSA",
  111. paySign: param.sign,
  112. success: res => {
  113. this.requestStatus=false
  114. uni.hideLoading();
  115. that.$refs.popup.close()
  116. uni.showToast({
  117. title: '支付成功!'
  118. });
  119. that.$refs.MescrollItem[that.tabIndex].downCallback()
  120. that.getUserInfo()
  121. },
  122. fail: res => {
  123. this.requestStatus=false
  124. uni.hideLoading();
  125. that.$refs.popup.close()
  126. console.log(res)
  127. uni.showToast({
  128. title: '支付失败',
  129. icon: 'error'
  130. });
  131. that.$refs.MescrollItem[that.tabIndex].downCallback()
  132. that.getUserInfo()
  133. }
  134. });
  135. })
  136. },
  137. balancePay(){
  138. let that = this;
  139. // if(this.password.length< 6 ){
  140. // uni.showToast({
  141. // title: "交易密码不能小于6位"
  142. // })
  143. // return ;
  144. // }
  145. // this.$refs.passwordPopup.close()
  146. // 用户信息
  147. if (this.openType == 2){
  148. //支付预约费用
  149. this.$api.balancePay({
  150. orderNo: this.appointmentOrder.subOrderNo,
  151. password: ''
  152. }).then((res)=>{
  153. this.requestStatus=false
  154. uni.hideLoading();
  155. that.$refs.popup.close()
  156. uni.showToast({
  157. title: '支付成功'
  158. })
  159. that.$refs.MescrollItem[that.tabIndex].downCallback()
  160. that.getUserInfo()
  161. that.password = ''
  162. }).catch((err) =>{
  163. this.requestStatus=false
  164. uni.hideLoading();
  165. that.$refs.popup.close()
  166. uni.showToast({
  167. title: err.msg,
  168. icon:'error'
  169. })
  170. that.password = ''
  171. });
  172. }else {
  173. //支付子订单费用
  174. this.$api.trade({
  175. tradeNo: this.tradeNo,
  176. password: ''
  177. }).then((res)=>{
  178. this.requestStatus=false
  179. uni.hideLoading();
  180. that.$refs.popup.close()
  181. uni.showToast({
  182. title: '支付成功'
  183. })
  184. that.$refs.MescrollItem[that.tabIndex].downCallback()
  185. that.getUserInfo()
  186. that.password = ''
  187. }).catch((err) =>{
  188. this.requestStatus=false
  189. uni.hideLoading();
  190. that.$refs.popup.close()
  191. uni.showToast({
  192. title: err.msg,
  193. icon:'error'
  194. })
  195. that.password = ''
  196. });
  197. }
  198. },
  199. payItem(num){
  200. console.log(this.userInfo.balance*1,this.appointmentOrder.totalAmount*1)
  201. if (this.userInfo.balance*1 < this.appointmentOrder.totalAmount*1){
  202. return
  203. }
  204. this.curServiceTab = num
  205. },
  206. closePayPopup(){
  207. this.$refs.popup.close()
  208. },
  209. //一键支付子订单
  210. openPay(order,number){
  211. console.log(order)
  212. console.log(number)
  213. this.openType=number
  214. this.appointmentOrder = order
  215. this.$api.oneClickPay({
  216. orderId:order.orderId
  217. }).then(res=>{
  218. this.tradeNo = res.data.data.tradeNo
  219. this.$refs.popup.open()
  220. })
  221. },
  222. commonGeneralOrder(){
  223. if(this.requestStatus){
  224. return;
  225. }
  226. this.requestStatus=true
  227. uni.showLoading({
  228. title: '支付中'
  229. });
  230. let that =this
  231. if (this.curServiceTab===1){
  232. // this.$refs.popup.close()
  233. // that.password = ''
  234. // this.$refs.passwordPopup.open()
  235. this.balancePay()
  236. }else {
  237. if (this.openType == 2){
  238. //支付预约费用
  239. this.wechatPay()
  240. }else{
  241. //支付子订单费用
  242. this.$api.wechatPayTradeNo({tradeNo:this.tradeNo}).then(res=>{
  243. var param = res.data.data;
  244. uni.requestPayment({
  245. appId: param.appid,
  246. timeStamp: param.timestamp+"",
  247. nonceStr: param.noncestr,
  248. package: "prepay_id="+param.prepayid,
  249. signType: "RSA",
  250. paySign: param.sign,
  251. success: res => {
  252. this.requestStatus=false
  253. uni.hideLoading();
  254. uni.showToast({
  255. title: '支付成功!'
  256. });
  257. that.$refs.popup.close()
  258. that.$refs.MescrollItem[that.tabIndex].downCallback()
  259. that.getUserInfo()
  260. },
  261. fail: res => {
  262. console.log(res)
  263. this.requestStatus=false
  264. uni.hideLoading();
  265. uni.showToast({
  266. title: '支付失败',
  267. icon: 'error'
  268. });
  269. that.$refs.popup.close()
  270. that.$refs.MescrollItem[that.tabIndex].downCallback()
  271. that.getUserInfo()
  272. }
  273. });
  274. })
  275. }
  276. }
  277. },
  278. getUserInfo() {
  279. let that = this
  280. this.$api.getUserInfo().then(res => {
  281. that.userInfo = res.data.data
  282. uni.setStorageSync('userInfo', res.data.data);
  283. });
  284. },
  285. clickTab(e) {
  286. this.tabIndex = e.index
  287. },
  288. swiperChange(e) {
  289. this.tabIndex = e.detail.current
  290. },
  291. changeTab(currentTab) {
  292. this.currentTab = currentTab
  293. },
  294. }
  295. }
  296. </script>
  297. <style scoped lang="scss">
  298. @import '/common/css/common.css';
  299. @import './index.rpx.scss';
  300. </style>