hmList.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. const util = require("../../../utils/util");
  2. const api = require('../../../api/api.js');
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. today: '',
  10. orderList: [],
  11. showType: 0,
  12. page: 1,
  13. limit: 10,
  14. totalPages: 1,
  15. addressInfo: {},
  16. testMobiles: ['132****8272', '173****9375', '182****9968', '130****7996', '131****2586', '138****9808', '151****2510', '178****5726'],
  17. isTest: false
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. let that = this
  24. try {
  25. var tab = wx.getStorageSync('tabQuick');
  26. if (tab) {
  27. this.setData({
  28. showType: tab == 3 ? 0 : tab
  29. });
  30. }
  31. } catch (e) {}
  32. let userInfo = wx.getStorageSync('userInfo');
  33. if (userInfo) {
  34. var isTest = false;
  35. that.data.testMobiles.forEach(item => {
  36. if (item == userInfo.mobile)
  37. isTest = true;
  38. })
  39. that.setData({
  40. isTest: isTest
  41. });
  42. }
  43. },
  44. getOrderList() {
  45. let that = this;
  46. wx.showLoading();
  47. util.request(api.BookHmList, {
  48. showType: that.data.showType,
  49. page: that.data.page,
  50. limit: that.data.limit
  51. }).then(function (res) {
  52. wx.hideLoading();
  53. if (res.errno === 0) {
  54. console.log(res.data);
  55. that.setData({
  56. orderList: that.data.orderList.concat(res.data.list),
  57. totalPages: res.data.pages
  58. });
  59. }
  60. });
  61. },
  62. goArrived(e) { //我已上门
  63. let that = this;
  64. let bookTradeNo = e.currentTarget.dataset.id;
  65. wx.showModal({
  66. title: '我已上门',
  67. content: '确定我已到顾客服务地?',
  68. showCancel: true, //是否显示取消按钮
  69. confirmText: "已上门", //默认是“确定”
  70. confirmColor: '#09afff', //确定文字的颜色
  71. success: function (res) {
  72. wx.showLoading();
  73. util.request(api.HmApiArrived, {
  74. bookTradeNo: bookTradeNo
  75. }).then(res => {
  76. wx.hideLoading();
  77. if (res.errno == 0) {
  78. let selected = that.data.orderList;
  79. selected.forEach(item => {
  80. if (item.bookNo == bookTradeNo) {
  81. item.status = '待履约'
  82. }
  83. })
  84. that.setData({
  85. orderList: selected
  86. })
  87. } else
  88. util.showErrorToast(res.errmsg);
  89. }).catch(res => {
  90. wx.hideLoading();
  91. util.showErrorToast(res.errmsg);
  92. })
  93. }
  94. })
  95. },
  96. goConfirm(e) {
  97. let that = this;
  98. let bookTradeNo = e.currentTarget.dataset.id;
  99. wx.showModal({
  100. title: '服务已完成',
  101. content: '确定我已服务完成?',
  102. showCancel: true, //是否显示取消按钮
  103. confirmText: "完成", //默认是“确定”
  104. confirmColor: '#09afff', //确定文字的颜色
  105. success: function (res) {
  106. wx.showLoading();
  107. util.request(api.HmApiConfirm, {
  108. bookTradeNo: bookTradeNo
  109. }).then(res => {
  110. wx.hideLoading();
  111. if (res.errno == 0) {
  112. let selected = that.data.orderList;
  113. selected.forEach(item => {
  114. if (item.bookTradeNo == bookTradeNo) {
  115. item.status = '服务已完成'
  116. return;
  117. }
  118. })
  119. that.setData({
  120. orderList: selected
  121. })
  122. } else
  123. util.showErrorToast(res.errmsg);
  124. }).catch(res => {
  125. wx.hideLoading();
  126. util.showErrorToast(res.errmsg);
  127. })
  128. }
  129. })
  130. },
  131. switchTab: function (event) {
  132. let showType = event.currentTarget.dataset.index;
  133. wx.setStorageSync('tabQuick', showType);
  134. this.setData({
  135. orderList: [],
  136. showType: showType,
  137. page: 1,
  138. limit: 10,
  139. totalPages: 1
  140. });
  141. this.getOrderList();
  142. },
  143. onReachBottom() {
  144. if (this.data.totalPages > this.data.page) {
  145. this.setData({
  146. page: this.data.page + 1
  147. });
  148. this.getOrderList();
  149. } else {
  150. wx.showToast({
  151. title: '没有更多预检单了',
  152. icon: 'none',
  153. duration: 2000
  154. });
  155. return false;
  156. }
  157. },
  158. makeCall(e) {
  159. wx.makePhoneCall({
  160. phoneNumber: e.currentTarget.dataset.phone,
  161. })
  162. },
  163. goProblemAdd(e) {
  164. let id = e.currentTarget.dataset.id;
  165. if (id) {
  166. wx.navigateTo({
  167. url: '/pages/problem/list/list?bookTradeNo=' + id,
  168. })
  169. } else {
  170. wx.navigateTo({
  171. url: '/pages/problem/list/list',
  172. })
  173. }
  174. },
  175. /**
  176. * 生命周期函数--监听页面初次渲染完成
  177. */
  178. onReady: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面显示
  182. */
  183. onShow: function () {
  184. if (app.globalData.hasLogin == false) {
  185. wx.navigateTo({
  186. url: '/pages/index/index',
  187. })
  188. return;
  189. }
  190. this.setData({
  191. orderList: [],
  192. showType: this.data.showType,
  193. page: 1,
  194. limit: 10,
  195. totalPages: 1,
  196. today: util.formatDate(new Date()),
  197. });
  198. this.getOrderList();
  199. },
  200. openMap(e) { //打开地图
  201. let that = this;
  202. let bookTradeNo = e.currentTarget.dataset.id;
  203. let bookInfo = null;
  204. that.data.orderList.forEach(item => {
  205. if (item.bookTradeNo == bookTradeNo) {
  206. bookInfo = item;
  207. return;
  208. }
  209. })
  210. let address = bookInfo.address;
  211. let lng = bookInfo.position.split(',')[0];
  212. let lat = bookInfo.position.split(',')[1];
  213. wx.openLocation({
  214. latitude:parseFloat(lat),
  215. longitude: parseFloat(lng),
  216. name: address,
  217. address: address,
  218. scale: 28
  219. })
  220. },
  221. /**
  222. * 生命周期函数--监听页面隐藏
  223. */
  224. onHide: function () {
  225. },
  226. /**
  227. * 生命周期函数--监听页面卸载
  228. */
  229. onUnload: function () {
  230. },
  231. /**
  232. * 页面相关事件处理函数--监听用户下拉动作
  233. */
  234. onPullDownRefresh: function () {
  235. },
  236. /**
  237. * 用户点击右上角分享
  238. */
  239. onShareAppMessage: function () {
  240. }
  241. })