detail.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. const app = getApp();
  2. const CONFIG = require('../../config.js')
  3. const WXAPI = require('apifm-wxapi')
  4. import wxbarcode from 'wxbarcode'
  5. Page({
  6. data:{
  7. orderId:0,
  8. goodsList:[],
  9. fileList: [],
  10. membersSelectIndex: -1,
  11. membersSelectStr: '请选择分配配送员',
  12. },
  13. onLoad:function(e){
  14. // e.peisongOrderId = 54
  15. var peisongOrderId = e.peisongOrderId;
  16. this.setData({
  17. peisongOrderId
  18. });
  19. this.peisongOrderDetail()
  20. this.peisongMemberInfo()
  21. },
  22. async peisongOrderDetail() {
  23. const res = await WXAPI.peisongOrderDetail(wx.getStorageSync('token'), this.data.peisongOrderId)
  24. if (res.code == 0) {
  25. this.setData({
  26. peisongOrderDetail: res.data
  27. })
  28. }
  29. },
  30. async peisongMemberInfo() {
  31. const res = await WXAPI.peisongMemberInfo(wx.getStorageSync('token'))
  32. if (res.code == 0) {
  33. this.setData({
  34. peisongMemberInfo: res.data
  35. })
  36. if (res.data.type == 2) {
  37. this.peisongMembers()
  38. }
  39. }
  40. },
  41. async peisongMembers() {
  42. const res = await WXAPI.peisongMembers({
  43. token: wx.getStorageSync('token')
  44. })
  45. if (res.code == 0) {
  46. res.data.result.forEach(ele => {
  47. ele.showStr = ele.name + ' ' + ele.mobile + ' ' + ele.statusStr
  48. })
  49. this.setData({
  50. peisongMembers: res.data.result
  51. })
  52. }
  53. },
  54. onShow : function () {
  55. var that = this;
  56. WXAPI.orderDetail(wx.getStorageSync('token'), 0, '', that.data.peisongOrderId).then(function (res) {
  57. if (res.code != 0) {
  58. wx.showModal({
  59. title: '错误',
  60. content: res.msg,
  61. showCancel: false
  62. })
  63. return;
  64. }
  65. // 绘制核销码
  66. if (res.data.orderInfo.hxNumber && res.data.orderInfo.status > 0) {
  67. wxbarcode.qrcode('qrcode', res.data.orderInfo.hxNumber, 650, 650);
  68. }
  69. that.setData({
  70. orderDetail: res.data
  71. });
  72. })
  73. },
  74. wuliuDetailsTap:function(e){
  75. var orderId = e.currentTarget.dataset.id;
  76. wx.navigateTo({
  77. url: "/pages/wuliu/index?id=" + orderId
  78. })
  79. },
  80. confirmBtnTap:function(e){
  81. let that = this;
  82. let orderId = this.data.orderId;
  83. wx.showModal({
  84. title: '确认服务已完成?',
  85. content: '',
  86. success: function(res) {
  87. if (res.confirm) {
  88. WXAPI.orderDelivery(wx.getStorageSync('token'), orderId).then(function (res) {
  89. if (res.code == 0) {
  90. that.onShow();
  91. }
  92. })
  93. }
  94. }
  95. })
  96. },
  97. submitReputation: function (e) {
  98. let that = this;
  99. let postJsonString = {};
  100. postJsonString.token = wx.getStorageSync('token');
  101. postJsonString.orderId = this.data.orderId;
  102. let reputations = [];
  103. let i = 0;
  104. while (e.detail.value["orderGoodsId" + i]) {
  105. let orderGoodsId = e.detail.value["orderGoodsId" + i];
  106. let goodReputation = e.detail.value["goodReputation" + i];
  107. let goodReputationRemark = e.detail.value["goodReputationRemark" + i];
  108. let reputations_json = {};
  109. reputations_json.id = orderGoodsId;
  110. reputations_json.reputation = goodReputation;
  111. reputations_json.remark = goodReputationRemark;
  112. reputations.push(reputations_json);
  113. i++;
  114. }
  115. postJsonString.reputations = reputations;
  116. WXAPI.orderReputation({
  117. postJsonString: JSON.stringify(postJsonString)
  118. }).then(function (res) {
  119. if (res.code == 0) {
  120. that.onShow();
  121. }
  122. })
  123. },
  124. afterRead(event) {
  125. console.log(event.detail);
  126. const fileList = this.data.fileList
  127. event.detail.file.forEach(ele => {
  128. fileList.push({
  129. url: ele.path,
  130. name: '图片'
  131. })
  132. })
  133. this.setData({
  134. fileList
  135. });
  136. },
  137. deletePic(event) {
  138. const fileList = this.data.fileList
  139. fileList.splice(event.detail.index, 1)
  140. this.setData({
  141. fileList
  142. });
  143. },
  144. async startService() {
  145. const extJsonStr = {}
  146. wx.showLoading({
  147. title: '提交中',
  148. })
  149. const res = await WXAPI.peisongStartService({
  150. token: wx.getStorageSync('token'),
  151. id: this.data.peisongOrderId,
  152. extJsonStr: JSON.stringify(extJsonStr)
  153. })
  154. wx.hideLoading({
  155. complete: (res) => {},
  156. })
  157. if (res.code != 0) {
  158. wx.showToast({
  159. title: res.msg,
  160. icon: 'none'
  161. })
  162. } else {
  163. wx.showToast({
  164. title: '提交成功',
  165. icon: 'success'
  166. })
  167. this.peisongOrderDetail()
  168. this.onShow()
  169. }
  170. },
  171. async endService() {
  172. const extJsonStr = {}
  173. let picNumber = 0
  174. wx.showLoading({
  175. title: '提交中',
  176. })
  177. const res = await WXAPI.peisongEndService({
  178. token: wx.getStorageSync('token'),
  179. id: this.data.peisongOrderId,
  180. extJsonStr: JSON.stringify(extJsonStr)
  181. })
  182. wx.hideLoading({
  183. complete: (res) => {},
  184. })
  185. if (res.code != 0) {
  186. wx.showToast({
  187. title: res.msg,
  188. icon: 'none'
  189. })
  190. } else {
  191. wx.showToast({
  192. title: '提交成功',
  193. icon: 'success'
  194. })
  195. this.setData({
  196. fileList: []
  197. })
  198. this.peisongOrderDetail()
  199. this.onShow()
  200. }
  201. },
  202. previewImage(e) {
  203. const logid = e.currentTarget.dataset.logid
  204. const current = e.currentTarget.dataset.current
  205. const urls = []
  206. this.data.peisongOrderDetail.logs.forEach(ele => {
  207. if (ele.id == logid) {
  208. Object.values(ele.extJson).forEach(_ele => {
  209. urls.push(_ele)
  210. })
  211. }
  212. })
  213. wx.previewImage({
  214. urls,
  215. current
  216. })
  217. },
  218. bindPickerChange: function(e) {
  219. const obj = this.data.peisongMembers[e.detail.value]
  220. this.setData({
  221. membersSelectIndex: e.detail.value,
  222. membersSelectStr: obj.name + ' ' + obj.mobile
  223. })
  224. },
  225. async paidan() {
  226. if (this.data.membersSelectIndex == -1) {
  227. wx.showToast({
  228. title: '请选择洗车工',
  229. icon: 'none'
  230. })
  231. return
  232. }
  233. const member = this.data.peisongMembers[this.data.membersSelectIndex]
  234. const res = await WXAPI.peisongOrderAllocation(wx.getStorageSync('token'), this.data.peisongOrderId, member.id)
  235. if (res.code != 0) {
  236. wx.showToast({
  237. title: res.msg,
  238. icon: 'none'
  239. })
  240. } else {
  241. wx.showToast({
  242. title: '派单成功',
  243. icon: 'success'
  244. })
  245. wx.navigateBack({
  246. complete: (res) => {},
  247. })
  248. }
  249. },
  250. callMobile() {
  251. wx.makePhoneCall({
  252. phoneNumber: this.data.orderDetail.peisongMember.mobile,
  253. })
  254. },
  255. callMobile2() {
  256. wx.makePhoneCall({
  257. phoneNumber: this.data.orderDetail.logistics.mobile,
  258. })
  259. },
  260. goMap() {
  261. const _this = this
  262. const latitude = this.data.orderDetail.logistics.latitude
  263. const longitude = this.data.orderDetail.logistics.longitude
  264. wx.openLocation({
  265. latitude,
  266. longitude,
  267. scale: 18
  268. })
  269. },
  270. estimatedCompletionTimeChange(value) {
  271. this.data.estimatedCompletionTimeChange = value.detail
  272. },
  273. async estimatedCompletionTime(){
  274. if (!this.data.estimatedCompletionTimeChange) {
  275. wx.showToast({
  276. title: '填写预计完成时间',
  277. icon: 'none'
  278. })
  279. return;
  280. }
  281. const res = await WXAPI.peisongOrderEstimatedCompletionTime({
  282. token: wx.getStorageSync('token'),
  283. id: this.data.peisongOrderId,
  284. estimatedCompletionTime: this.data.estimatedCompletionTimeChange
  285. })
  286. if (res.code == 0) {
  287. wx.showToast({
  288. title: '设置成功',
  289. icon: 'success'
  290. })
  291. this.peisongOrderDetail()
  292. this.onShow()
  293. } else {
  294. wx.showToast({
  295. title: res.msg,
  296. icon: 'none'
  297. })
  298. }
  299. },
  300. async peisongOrderGrab(){
  301. if (!this.data.estimatedCompletionTimeChange) {
  302. wx.showToast({
  303. title: '填写预计完成时间',
  304. icon: 'none'
  305. })
  306. return;
  307. }
  308. const res = await WXAPI.peisongOrderGrab({
  309. token: wx.getStorageSync('token'),
  310. id: this.data.peisongOrderId,
  311. estimatedCompletionTime: this.data.estimatedCompletionTimeChange
  312. })
  313. if (res.code == 0) {
  314. wx.showToast({
  315. title: '抢单成功',
  316. icon: 'success'
  317. })
  318. this.peisongOrderDetail()
  319. this.onShow()
  320. } else {
  321. wx.showToast({
  322. title: res.msg,
  323. icon: 'none'
  324. })
  325. }
  326. },
  327. })