order.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. orderList: [],
  7. showType: 0,
  8. orderType:0,//0推广 1自购
  9. page: 1,
  10. limit: 10,
  11. totalPages: 1,
  12. myqr_show:false,//我的分享二维码
  13. myqr_url:null,
  14. myqr_blur:0,//背景模糊值
  15. hasLogin:false,
  16. goodsId:''
  17. },
  18. onLoad: function(options) {
  19. // 页面初始化 options为页面跳转所带来的参数
  20. this.getOrderList();
  21. },
  22. getOrderList() {
  23. wx.showLoading({
  24. title: '加载中',
  25. });
  26. let that = this;
  27. util.request(api.RefereeOrderList, {
  28. orderType: that.data.orderType,
  29. showType: that.data.showType,
  30. page: that.data.page,
  31. limit: that.data.limit
  32. }).then(function(res) {
  33. wx.hideLoading();
  34. if (res.errno === 0) {
  35. console.log(res.data);
  36. that.setData({
  37. orderList: that.data.orderList.concat(res.data.list),
  38. totalPages: res.data.pages
  39. });
  40. }
  41. });
  42. },
  43. goOrderType(e){//切换自购或者推广订单
  44. this.setData({
  45. orderList: [],
  46. orderType:e.currentTarget.dataset.type,
  47. showType: 0,
  48. page: 1,
  49. limit: 10,
  50. totalPages: 1
  51. });
  52. this.getOrderList();
  53. },
  54. onReachBottom() {
  55. if (this.data.totalPages > this.data.page) {
  56. this.setData({
  57. page: this.data.page + 1
  58. });
  59. this.getOrderList();
  60. } else {
  61. wx.showToast({
  62. title: '没有更多订单了',
  63. icon: 'none',
  64. duration: 2000
  65. });
  66. return false;
  67. }
  68. },
  69. onTabChange(e){
  70. let showType = e.detail.name;
  71. let orderType=this.data.orderType;
  72. this.setData({
  73. orderList: [],
  74. showType: showType,
  75. orderType:orderType,
  76. page: 1,
  77. limit: 10,
  78. totalPages: 1
  79. });
  80. this.getOrderList();
  81. },
  82. viewService(e){
  83. let id=e.currentTarget.dataset.id;
  84. wx.navigateTo({
  85. url: '/pages/ucenter/serviceDetail/serviceDetail?orderId=' +id
  86. })
  87. },
  88. qrtouchstart:function(){
  89. this.setData({
  90. myqr_blur:0,
  91. myqr_show:false
  92. });
  93. },
  94. shareFriendOrCircle: function(e) {
  95. let id=e.currentTarget.dataset.id;
  96. this.setData({
  97. goodsId:id
  98. });
  99. if (!app.globalData.hasLogin){
  100. wx.navigateTo({
  101. url: "/pages/auth/login/login"
  102. });
  103. return;
  104. }
  105. //分享 弹出图片
  106. let that=this;
  107. // wx.removeStorageSync(String(that.data.goods.id));
  108. //取出本地缓存中的分享图
  109. // let sUrl=wx.getStorageSync(String(that.data.goodsId));
  110. // if(sUrl!=null&&sUrl!=""){//获取过的分享图 不需要再次获取
  111. // that.setData({
  112. // myqr_url:sUrl,
  113. // myqr_show:true,
  114. // myqr_blur:5
  115. // });
  116. // return;
  117. // }
  118. wx.showLoading({
  119. title: '生成中',
  120. });
  121. util.request(api.QrGoodsCodeCreate, {
  122. goodsId:that.data.goodsId
  123. }).then(function(res) {
  124. wx.hideLoading();
  125. if(res.errno==0){
  126. that.setData({
  127. myqr_url:res.data.imgUrl,
  128. myqr_show:true,
  129. myqr_blur:5
  130. });
  131. //保存分享图url到本地缓存
  132. // wx.setStorageSync(String(that.data.goodsId),res.data.imgUrl);
  133. } else if(res.errno==501){
  134. wx.navigateTo({
  135. url: "/pages/auth/login/login"
  136. });
  137. } else {
  138. wx.showToast({
  139. title: res.errmsg,
  140. duration:5000
  141. })
  142. }
  143. });
  144. //var that = this;
  145. /*if (this.data.openShare === false) {
  146. this.setData({
  147. openShare: !this.data.openShare
  148. });
  149. } else {
  150. return false;
  151. }*/
  152. },
  153. // 保存分享图
  154. saveShare: function() {
  155. let that = this;
  156. wx.showLoading({
  157. title: '图片保存中',
  158. });
  159. console.log(that.data);
  160. wx.downloadFile({
  161. url: that.data.myqr_url,
  162. success: function(res) {
  163. console.log(res)
  164. wx.saveImageToPhotosAlbum({
  165. filePath: res.tempFilePath,
  166. success: function(res) {
  167. wx.hideLoading();
  168. wx.showModal({
  169. title: '存图成功',
  170. content: '图片成功保存到相册了,可以分享到朋友圈了',
  171. showCancel: false,
  172. confirmText: '好的',
  173. confirmColor: '#a78845',
  174. success: function(res) {
  175. if (res.confirm) {
  176. console.log('用户点击确定');
  177. that.setData({
  178. myqr_show:false,
  179. myqr_blur:0
  180. });
  181. }
  182. }
  183. })
  184. },
  185. fail: function(res) {
  186. wx.hideLoading();
  187. wx.showModal({
  188. title: '警告',
  189. content: '不授权无法保存',
  190. showCancel: false
  191. })
  192. that.setData({
  193. myqr_show:false,
  194. myqr_blur:0
  195. });
  196. }
  197. })
  198. },
  199. fail: function(res) {
  200. wx.hideLoading();
  201. console.log(res);
  202. }
  203. })
  204. },
  205. // “去付款”按钮点击效果
  206. payOrder: function(e) {
  207. let that = this;
  208. let id = e.currentTarget.dataset.id;
  209. util.request(api.OrderPrepay, {
  210. orderId: id
  211. }, 'POST').then(function(res) {
  212. if (res.errno === 0) {
  213. const payParam = res.data;
  214. console.log("支付过程开始");
  215. wx.requestPayment({
  216. 'timeStamp': payParam.timeStamp,
  217. 'nonceStr': payParam.nonceStr,
  218. 'package': payParam.packageValue,
  219. 'signType': payParam.signType,
  220. 'paySign': payParam.paySign,
  221. 'success': function(res) {
  222. console.log("支付过程成功");
  223. let orderList=that.data.orderList;
  224. orderList.forEach(item=>{
  225. if(item.id==id){
  226. item.orderStatusText='已支付'
  227. item.bookStatus='待履约'
  228. }
  229. })
  230. that.setData({
  231. orderList:orderList
  232. })
  233. },
  234. 'fail': function(res) {
  235. console.log("支付过程失败");
  236. util.showErrorToast('支付失败');
  237. },
  238. 'complete': function(res) {
  239. console.log("支付过程结束")
  240. }
  241. });
  242. }
  243. });
  244. },
  245. // “删除”点击效果
  246. deleteOrder: function(e) {
  247. let that = this;
  248. let id = e.currentTarget.dataset.id;
  249. wx.showModal({
  250. title: '',
  251. content: '确定要删除此订单?',
  252. success: function(res) {
  253. if (res.confirm) {
  254. util.request(api.OrderDelete, {
  255. orderId: id
  256. }, 'POST').then(function(res) {
  257. if (res.errno === 0) {
  258. wx.showToast({
  259. title: '删除订单成功'
  260. });
  261. let orderList=[];
  262. that.data.orderList.forEach(item=>{
  263. if(item.id!=id){
  264. orderList.push(item)
  265. }
  266. })
  267. that.setData({
  268. orderList:orderList
  269. })
  270. } else {
  271. util.showErrorToast(res.errmsg);
  272. }
  273. });
  274. }
  275. }
  276. });
  277. },
  278. // “取消订单”点击效果
  279. cancelOrder: function(e) {
  280. let that = this;
  281. let id = e.currentTarget.dataset.id;
  282. wx.showModal({
  283. title: '',
  284. content: '确定要取消此订单?',
  285. success: function(res) {
  286. if (res.confirm) {
  287. util.request(api.OrderCancel, {
  288. orderId: id
  289. }, 'POST').then(function(res) {
  290. if (res.errno === 0) {
  291. wx.showToast({
  292. title: '取消订单成功'
  293. });
  294. let orderList=that.data.orderList;
  295. orderList.forEach(item=>{
  296. if(item.id==id){
  297. item.orderStatusText='已取消'
  298. item.bookStatus='已取消'
  299. }
  300. })
  301. that.setData({
  302. orderList:orderList
  303. })
  304. } else {
  305. util.showErrorToast(res.errmsg);
  306. }
  307. });
  308. }
  309. }
  310. });
  311. },
  312. // “取消订单并退款”点击效果
  313. refundOrder: function(e) {
  314. let that = this;
  315. let id = e.currentTarget.dataset.id;
  316. wx.showModal({
  317. title: '',
  318. content: '确定要取消此订单?',
  319. success: function(res) {
  320. if (res.confirm) {
  321. util.request(api.OrderRefund, {
  322. orderId: id
  323. }, 'POST').then(function(res) {
  324. if (res.errno === 0) {
  325. wx.showToast({
  326. title: '取消订单成功'
  327. });
  328. let orderList=that.data.orderList;
  329. orderList.forEach(item=>{
  330. if(item.id==id){
  331. item.orderStatusText='已退款'
  332. item.bookStatus='已退款'
  333. }
  334. })
  335. that.setData({
  336. orderList:orderList
  337. })
  338. } else {
  339. util.showErrorToast(res.errmsg);
  340. }
  341. });
  342. }
  343. }
  344. });
  345. },
  346. onReady: function() {
  347. // 页面渲染完成
  348. },
  349. onShow: function() {
  350. // 页面显示
  351. // if(this.data.orderList.length>0) return;
  352. },
  353. onHide: function() {
  354. // 页面隐藏
  355. },
  356. onUnload: function() {
  357. // 页面关闭
  358. },
  359. goSearch(){
  360. wx.navigateTo({
  361. url: '/pages/referee/search/search',
  362. })
  363. },
  364. goCopyCode(e){
  365. let orderid=e.currentTarget.dataset.orderid
  366. if(orderid){
  367. wx.setClipboardData({
  368. data: orderid,
  369. success: function (res) {
  370. wx.showToast({
  371. title: '订单号复制成功',
  372. icon: 'success',
  373. duration: 2000
  374. });
  375. }
  376. })
  377. }
  378. },
  379. })