booklist.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. const util = require("../../../utils/util");
  2. const api = require('../../../api/api.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. orderList: [],
  9. showType: 0,
  10. page: 1,
  11. limit: 10,
  12. totalPages: 1,
  13. addressInfo:{},
  14. myqr_show:false,//我的分享二维码
  15. myqr_url:null,
  16. myqr_blur:0,//背景模糊值
  17. code:'',
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. let that = this
  24. try {
  25. var tab = wx.getStorageSync('tab');
  26. this.setData({
  27. showType: tab
  28. });
  29. } catch (e) {
  30. }
  31. },
  32. getOrderList() {
  33. wx.showLoading({
  34. title: '查询中',
  35. })
  36. let that = this;
  37. util.request(api.BookDetailList, {
  38. showType: that.data.showType,
  39. page: that.data.page,
  40. limit: that.data.limit
  41. }).then(function(res) {
  42. wx.hideLoading();
  43. if (res.errno === 0) {
  44. console.log(res.data);
  45. that.setData({
  46. orderList: that.data.orderList.concat(res.data.list),
  47. totalPages: res.data.pages
  48. });
  49. }
  50. });
  51. },
  52. onReachBottom() {
  53. if (this.data.totalPages > this.data.page) {
  54. this.setData({
  55. page: this.data.page + 1
  56. });
  57. this.getOrderList();
  58. } else {
  59. wx.showToast({
  60. title: '没有更多订单了',
  61. icon: 'none',
  62. duration: 2000
  63. });
  64. return false;
  65. }
  66. },
  67. switchTab: function(event) {
  68. let showType = event.currentTarget.dataset.index;
  69. this.setData({
  70. orderList: [],
  71. showType: showType,
  72. page: 1,
  73. limit: 10,
  74. totalPages: 1
  75. });
  76. this.getOrderList();
  77. },
  78. makeCall(e){
  79. let mobile = e.currentTarget.dataset.mobile;
  80. wx.makePhoneCall({
  81. phoneNumber: mobile,
  82. })
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow: function () {
  93. this.setData({
  94. orderList: [],
  95. showType: this.data.showType,
  96. page: 1,
  97. limit: 10,
  98. totalPages: 1
  99. });
  100. this.getOrderList();
  101. },
  102. goProvideBook(e){//完成服务
  103. let that=this;
  104. let id=e.currentTarget.dataset.id;
  105. wx.showModal({
  106. title: '完成服务',
  107. confirmColor: '#b4282d',
  108. content: '确定完成此服务?完成后,无法修改',
  109. success: function (res) {
  110. if (!res.confirm) {
  111. return;
  112. }
  113. util.request(api.BookDetailProvice,{id:id}).then(res=>{
  114. if(res.errno==0){
  115. wx.showToast({
  116. title: '服务完成',
  117. icon: 'success',
  118. });
  119. var list=that.data.orderList;
  120. list.forEach(item=>{
  121. item.details.forEach(dt=>{
  122. if(dt.id==id){
  123. dt.status="服务已提供";
  124. dt.statusId=3;
  125. }
  126. })
  127. })
  128. that.setData({
  129. orderList:list
  130. })
  131. }
  132. })
  133. }
  134. })
  135. },
  136. openMap(e){//打开地图
  137. let address=e.currentTarget.dataset.address;
  138. let lng=e.currentTarget.dataset.lng;
  139. let lat=e.currentTarget.dataset.lat;
  140. // console.info(lng)
  141. // console.info(lat)
  142. // console.info(address)
  143. wx.openLocation({
  144. latitude: lat,
  145. longitude: lng,
  146. name: address,
  147. address:address,
  148. scale: 28
  149. })
  150. },
  151. /**
  152. * 生命周期函数--监听页面隐藏
  153. */
  154. onHide: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面卸载
  158. */
  159. onUnload: function () {
  160. },
  161. /**
  162. * 页面相关事件处理函数--监听用户下拉动作
  163. */
  164. onPullDownRefresh: function () {
  165. },
  166. /**
  167. * 用户点击右上角分享
  168. */
  169. onShareAppMessage: function () {
  170. },
  171. shareGoods(e){
  172. let that=this;
  173. wx.showLoading({title: '生成中',});
  174. util.request(api.GoodsShare, {
  175. goodsId:e.currentTarget.dataset.id
  176. }).then(function(res) {
  177. console.info(res)
  178. wx.hideLoading();
  179. if(res.errno==0){
  180. that.setData({
  181. myqr_url:res.data.imgUrl,
  182. myqr_show:true,
  183. myqr_blur:5
  184. });
  185. } else if(res.errno==501){
  186. // wx.navigateTo({
  187. // url: "/pages/index/index"
  188. // });
  189. } else {
  190. wx.showToast({
  191. title: res.errmsg,
  192. duration:5000
  193. })
  194. }
  195. });
  196. },
  197. qrtouchstart:function(){
  198. this.setData({
  199. myqr_blur:0,
  200. myqr_show:false
  201. });
  202. },
  203. saveShare: function() {
  204. let that = this;
  205. wx.showLoading({
  206. title: '图片保存中',
  207. });
  208. console.log(that.data);
  209. wx.downloadFile({
  210. url: that.data.myqr_url,
  211. success: function(res) {
  212. console.log(res)
  213. wx.saveImageToPhotosAlbum({
  214. filePath: res.tempFilePath,
  215. success: function(res) {
  216. wx.hideLoading();
  217. wx.showModal({
  218. title: '存图成功',
  219. content: '图片成功保存到相册了,可以分享到朋友圈了',
  220. showCancel: false,
  221. confirmText: '好的',
  222. confirmColor: '#a78845',
  223. success: function(res) {
  224. if (res.confirm) {
  225. console.log('用户点击确定');
  226. that.setData({
  227. myqr_show:false,
  228. myqr_blur:0
  229. });
  230. }
  231. }
  232. })
  233. },
  234. fail: function(res) {
  235. wx.hideLoading();
  236. wx.showModal({
  237. title: '警告',
  238. content: '未授权无法保存',
  239. showCancel: false
  240. })
  241. that.setData({
  242. myqr_show:false,
  243. myqr_blur:0
  244. });
  245. }
  246. })
  247. },
  248. fail: function(res) {
  249. wx.hideLoading();
  250. console.log(res);
  251. }
  252. })
  253. },
  254. })