search.js 9.3 KB

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