index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import * as API from '@/apis/buytickets.js'
  2. export default {
  3. data() {
  4. return {
  5. isLoading:true,
  6. initBl:false,
  7. noback:false,
  8. passengerInfo:{},
  9. id: '',
  10. num: 0,
  11. pic: '',
  12. list: [],
  13. selectList: [],
  14. subForm: {
  15. pageIndex: 1,
  16. pageSize: 20,
  17. totalPage: 1
  18. }
  19. }
  20. },
  21. methods: {
  22. gotoHome(){
  23. uni.switchTab({
  24. url: '/pages/index/index'
  25. });
  26. },
  27. submit() {
  28. var obj = this.carhelp.get("form");
  29. obj.oplist = []
  30. for (var i in this.list) {
  31. if (this.list[i].ck) {
  32. obj.oplist.push(this.list[i]);
  33. }
  34. }
  35. this.carhelp.set("form", obj);
  36. uni.navigateTo({
  37. url: '/pages/buytickets/selectSite?select=true&id=' + this.id
  38. })
  39. },
  40. ckBtn(item) {
  41. if(this.num==5&&!item.ck){
  42. this.$refs.common.alert("一次最多选择5名乘车人员");
  43. return
  44. }
  45. item.ck = !item.ck;
  46. if (item.ck) {
  47. var bl=true
  48. for (var i = 0; i < this.selectList.length; i++) {
  49. if (this.selectList[i].upStationId != item.upStationId) {
  50. bl=false;
  51. }
  52. break;
  53. }
  54. if(!bl){
  55. item.ck = !item.ck;
  56. this.$refs.common.alert("所选乘客上车站点不一致,请重新选择。");
  57. return;
  58. }
  59. this.num++;
  60. this.selectList.push(item);
  61. } else {
  62. this.num--;
  63. for (var i = 0; i < this.selectList.length; i++) {
  64. if (this.selectList[i].id == item.id) {
  65. this.selectList.splice(i, 1);
  66. }
  67. }
  68. }
  69. console.log(this.selectList)
  70. },
  71. getPassengerInfo() {
  72. var thisform = {
  73. id: this.id,
  74. openId: this.carhelp.getOpenId()
  75. }
  76. this.$refs.common.showLoading()
  77. API.getPassengerInfo(thisform).then((response) => {
  78. if (!response.result) {
  79. this.$refs.common.goError(response.message)
  80. return
  81. }
  82. this.passengerInfo = response.data
  83. var obj = this.carhelp.get("form");
  84. if(!obj){
  85. obj={}
  86. }
  87. //obj.list = this.passengerInfo.list;
  88. obj.name= 'buytickets';
  89. obj.id= this.id;
  90. this.carhelp.set("form", obj);
  91. if (response.data.supply) {
  92. this.$refs.common.alert('存在需要补票的订单。')
  93. uni.switchTab({
  94. url: '/pages/news/index'
  95. });
  96. return;
  97. //this.$refs.common.goError(response.message)
  98. this.$refs.common.setFnc(()=>{
  99. uni.switchTab({
  100. url: '/pages/news/index'
  101. });
  102. },()=>{
  103. if (!response.data.id) {
  104. uni.redirectTo({
  105. url: '/pages/buytickets/index?id=' + this.id+'&back=true'
  106. })
  107. } else {
  108. this.getShiftInfo()
  109. }
  110. })
  111. this.$refs.common.confirm('存在需要补票的订单,是否前去查看?')
  112. return;
  113. }
  114. this.upBusNoTicketList(true);
  115. }).catch(error => {
  116. if (error) {
  117. this.$refs.common.goError(error)
  118. return
  119. }
  120. //this.$refs.common.showLoading(false,error)
  121. })
  122. },
  123. upBusNoTicketList(bl) {
  124. this.num=0
  125. this.$refs.common.showLoading();
  126. this.subForm.id = this.id;
  127. var obj = this.carhelp.get("form")
  128. //this.list = [];
  129. //this.isLoading=true;
  130. API.upBusNoTicketList(this.subForm).then((res) => {
  131. this.isLoading=false;
  132. this.list = res.data.data;
  133. //this.list = [];
  134. if(!this.list.length){
  135. this.$refs.common.showLoading(false);
  136. if(!bl){
  137. this.$refs.common.alert("刷新成功");
  138. }
  139. return;
  140. }
  141. this.selectList=[];//清空选中
  142. if (this.list.length != 0&&!bl) {
  143. this.$refs.common.showLoading(false, "刷新成功");
  144. } else {
  145. this.$refs.common.showLoading(false);
  146. }
  147. }).catch(error => {
  148. this.$refs.common.showLoading(false, error);
  149. })
  150. }
  151. },
  152. onLoad(op) {
  153. if(op.back){
  154. this.noback=op.back
  155. }
  156. this.id = op.id
  157. },
  158. onReady() {
  159. if (!this.id) {
  160. this.$refs.common.goError()
  161. }
  162. var obj = this.carhelp.get("form")
  163. if (obj && obj.name == 'buytickets' && obj.id == this.id) {
  164. //不创建新订单
  165. obj.buy=null;
  166. this.carhelp.set("form",obj);
  167. } else {
  168. this.carhelp.set("form", {
  169. name: 'buytickets',
  170. id: this.id,
  171. oplist: [], //当前添加的2人
  172. list: [] // 一共添加的人
  173. });
  174. }
  175. if (false&&!this.carhelp.getPersonInfo()) {
  176. this.$refs.common.setFnc(this.confirmBtn)
  177. this.$refs.common.alert2('您还不是车信达用户,注册后再购买车票。', '前往注册', '尚未注册')
  178. } else {
  179. }
  180. if (this.noback) {
  181. this.upBusNoTicketList(true);
  182. } else {
  183. this.getPassengerInfo()
  184. }
  185. //this.upBusNoTicketList();
  186. this.initBl=true;
  187. },onShow(){
  188. if(this.initBl){
  189. this.upBusNoTicketList(true);
  190. }
  191. }
  192. }