newRevisit.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. const util = require('../../../utils/util.js');
  2. const api = require('../../../config/api.js');
  3. //获取应用实例
  4. const app = getApp();
  5. Page({
  6. data: {
  7. consultList: [],
  8. questionList: [],
  9. imgList: [],
  10. remark: '',
  11. detail: '',
  12. satisfy: '',
  13. bookTradeNo: '',
  14. type: '',
  15. isFinished: false,
  16. tradeOrder: {
  17. itemName: '',
  18. serviceNumber: '',
  19. beginDate: '',
  20. serviceTime: '',
  21. workerName: ''
  22. },
  23. code: '',
  24. loginShow: false,
  25. },
  26. onLoad: function (options) {
  27. console.log("options", options);
  28. if (options) {
  29. this.setData({
  30. bookTradeNo: options.id,
  31. // type:options.type
  32. });
  33. this.getOrderDetail();
  34. }
  35. // 获取题目
  36. // this.getConsoultType();
  37. // let that=this;
  38. // wx.login({
  39. // success(res) {
  40. // console.log(res);
  41. // let params = {
  42. // code: res.code,
  43. // bookTradeNo:that.data.bookTradeNo
  44. // };
  45. // if (res.code) {
  46. // that.setData({
  47. // code: res.code
  48. // });
  49. // util.request(api.loginCusUnionId, params, 'POST').then(response => {
  50. // if (response.errno === 0) {
  51. // console.log(response);
  52. // if(response.data.tradeOrder==null||response.data.tradeOrder==''){
  53. // wx.showToast({
  54. // title: '您还没有购买过任何商品,如有疑问,欢迎咨询4009218787',
  55. // icon: 'none',
  56. // duration: 2000
  57. // });
  58. // }else{
  59. // that.setData({
  60. // tradeOrder:response.data.tradeOrder
  61. // });
  62. // that.getConsoultType();
  63. // }
  64. // } else {
  65. // wx.login({
  66. // success(res) {
  67. // console.log(res);
  68. // if (res.code) {
  69. // that.setData({
  70. // code: res.code
  71. // });
  72. // }
  73. // }});
  74. // that.setData({
  75. // loginShow: true
  76. // });
  77. // }
  78. // });
  79. // } else {
  80. // console.log('登录失败!' + res.errMsg)
  81. // }
  82. // }
  83. // });
  84. },
  85. getOrderDetail(){
  86. util.request(api.getTradeOrderList, { bookDetailId: this.data.bookTradeNo}, 'GET').then(res => {
  87. if (res.errno === 0) {
  88. console.log(res);
  89. this.setData({
  90. tradeOrder:res.data
  91. });
  92. // 获取题目
  93. this.getConsoultType();
  94. } else {
  95. wx.showToast({
  96. title: res.errmsg,
  97. icon: 'none',
  98. duration: 2000
  99. });
  100. }
  101. }).catch((err)=>{
  102. console.log(err)
  103. });
  104. },
  105. getConsoultType() {
  106. util.request(api.getConsoultType, { type: this.data.tradeOrder.goodsType }, 'GET').then(res => {
  107. if (res.errno === 0) {
  108. console.log(res);
  109. let list = res.data[0].children;
  110. list.forEach(item => {
  111. item.checked = false;
  112. });
  113. this.setData({
  114. consultList: list
  115. });
  116. } else {
  117. wx.showToast({
  118. title: res.errmsg,
  119. icon: 'none',
  120. duration: 2000
  121. });
  122. }
  123. }).catch((err)=>{
  124. console.log(err)
  125. });
  126. },
  127. questionClick(e) {
  128. let checked = e.currentTarget.dataset.checked;
  129. let index = e.currentTarget.dataset.index;
  130. let item = `consultList[${index}].checked`;
  131. this.setData({
  132. [item]: !checked
  133. });
  134. let current = this.data.consultList.filter(item => { return item.checked });
  135. this.setData({
  136. questionList: current
  137. });
  138. },
  139. selectSatisfy(e) {
  140. let result = e.currentTarget.dataset.satisfy;
  141. this.setData({
  142. satisfy: result
  143. });
  144. },
  145. remarkInput(e) {
  146. this.setData({
  147. remark: e.detail.value
  148. });
  149. },
  150. detailInput(e) {
  151. this.setData({
  152. detail: e.detail.value
  153. });
  154. },
  155. previewImg(e) {
  156. let img = e.currentTarget.dataset.img;
  157. let imgs = this.data.imgList
  158. wx.previewImage({
  159. current: img, // 当前显示图片的http链接
  160. urls: imgs // 需要预览的图片http链接列表
  161. })
  162. },
  163. delImg(e) {
  164. let imgs = this.data.imgList;
  165. let index = e.currentTarget.dataset.index;
  166. imgs.splice(index, 1);
  167. this.setData({
  168. imgList: imgs
  169. })
  170. },
  171. uploadImg() {
  172. if (this.data.imgList.length >= 9) {
  173. wx.showToast({
  174. title: '最多上传9张图片',
  175. icon: 'none',
  176. duration: 2000
  177. });
  178. return false;
  179. }
  180. let that = this;
  181. let count = 9 - that.data.imgList.length;
  182. wx.chooseImage({
  183. count: count,
  184. sizeType: ['original', 'compressed'],
  185. sourceType: ['album', 'camera'],
  186. success: function (res) {
  187. console.log(res);
  188. let tempFilePaths = res.tempFilePaths;
  189. // for(let i=0;i<tempFilePaths.length;i++){
  190. // if(imgs.length>=9){
  191. // that.setData({
  192. // imgList:imgs
  193. // });
  194. // return false;
  195. // }else{
  196. // imgs.push(tempFilePaths[i]);
  197. // }
  198. // }
  199. // that.setData({
  200. // imgList:imgs
  201. // });
  202. // console.log(that.data.imgList);
  203. wx.showLoading({
  204. title: '上传中...',
  205. });
  206. for (let i = 0; i < tempFilePaths.length; i++) {
  207. let imgs = that.data.imgList;
  208. if (imgs.length >= 9) {
  209. that.setData({
  210. imgList: imgs
  211. });
  212. return false;
  213. } else {
  214. wx.uploadFile({
  215. url: api.StorageUpload,
  216. filePath: tempFilePaths[i],
  217. name: 'file',
  218. success(res) {
  219. console.log(res);
  220. let data = JSON.parse(res.data);
  221. if (data.errno == 0) {
  222. imgs.push(data.data.url);
  223. that.setData({
  224. imgList: imgs
  225. });
  226. } else {
  227. console.log('上传失败')
  228. }
  229. }
  230. })
  231. }
  232. }
  233. wx.hideLoading();
  234. }
  235. });
  236. },
  237. /**
  238. * 生命周期函数--监听页面显示
  239. */
  240. onShow: function (options) {
  241. // wx.hideHomeButton({
  242. // success(){
  243. // }
  244. // });
  245. },
  246. answerClick(e) {
  247. let index1 = e.currentTarget.dataset.index1;
  248. let answer = e.currentTarget.dataset.answer;
  249. let id = e.currentTarget.dataset.id;
  250. let obj1 = `questionList[${index1}].consultId`;
  251. let obj2 = `questionList[${index1}].consultName`;
  252. this.setData({
  253. [obj1]: id,
  254. [obj2]: answer
  255. });
  256. console.log(this.data.questionList);
  257. },
  258. maskClick(e) {
  259. let answer = e.currentTarget.dataset.answer;
  260. this.setData({
  261. isUnMask: answer
  262. });
  263. },
  264. getPhoneNumber(e) {
  265. console.log(e.detail);
  266. let params = {
  267. // type:'保洁',
  268. code: this.data.code,
  269. encryptedData: e.detail.encryptedData,
  270. iv: e.detail.iv,
  271. bookTradeNo: this.data.bookTradeNo
  272. // loginType: '',
  273. // openId: "",
  274. // sessionKey: "",
  275. // tel: "",
  276. // unionId: "",
  277. // userPassword: ""
  278. };
  279. util.request(api.loginCusTel, params, 'POST').then(res => {
  280. if (res.errno === 0) {
  281. console.log(res);
  282. this.setData({
  283. loginShow: false
  284. });
  285. if (res.data.tradeOrder == null || res.data.tradeOrder == '') {
  286. wx.showToast({
  287. title: '您还没有购买过任何商品,如有疑问,欢迎咨询4009218787',
  288. icon: 'none',
  289. duration: 2000
  290. });
  291. } else {
  292. this.setData({
  293. tradeOrder: res.data.tradeOrder
  294. });
  295. this.getConsoultType();
  296. }
  297. } else {
  298. this.setData({
  299. loginShow: true
  300. });
  301. wx.showToast({
  302. title: res.errmsg,
  303. icon: 'none',
  304. duration: 2000
  305. });
  306. let that = this;
  307. wx.login({
  308. success(res) {
  309. console.log(res);
  310. if (res.code) {
  311. that.setData({
  312. code: res.code
  313. });
  314. }
  315. }
  316. });
  317. }
  318. })
  319. },
  320. sumitRevisit() {
  321. let params = {
  322. bookTime: this.data.tradeOrder.beginDate + ' ' + this.data.tradeOrder.serviceTime,
  323. bookTradeNo: this.data.tradeOrder.bookTradeNo,
  324. cusTel: this.data.tradeOrder.cusPhone,
  325. degree: this.data.satisfy,
  326. type: this.data.tradeOrder.goodsType,
  327. worderNo: this.data.tradeOrder.workerNo,
  328. workerName: this.data.tradeOrder.workerName,
  329. }
  330. if (this.data.satisfy == 2) {
  331. let isEmpty = this.data.questionList.some(item => { return item.consultId == undefined || item.consultId == '' });
  332. if (isEmpty) {
  333. wx.showToast({
  334. title: '请填写完整',
  335. icon: 'none',
  336. duration: 2000
  337. });
  338. return false;
  339. } else if (this.data.detail == '') {
  340. wx.showToast({
  341. title: '请输入具体问题描述',
  342. icon: 'none',
  343. duration: 2000
  344. });
  345. return false;
  346. } else {
  347. let title = [];
  348. let titleId = [];
  349. let consultId = [];
  350. let consultName = [];
  351. this.data.questionList.forEach(item => {
  352. title.push(item.name);
  353. titleId.push(item.id);
  354. consultId.push(item.consultId);
  355. consultName.push(item.consultName);
  356. });
  357. params.title = title.join(',');
  358. params.titleId = titleId.join(',');
  359. params.consultId = consultId.join(',');
  360. params.consultName = consultName.join(',');
  361. params.question = this.data.detail;
  362. params.imgSrc = this.data.imgList.join(',');
  363. }
  364. } else if (this.data.satisfy == 3) {
  365. if (this.data.remark == '') {
  366. wx.showToast({
  367. title: '请填写建议',
  368. icon: 'none',
  369. duration: 2000
  370. });
  371. return false;
  372. } else {
  373. params.question = this.data.remark;
  374. }
  375. }
  376. wx.showLoading({
  377. title: '加载中...',
  378. });
  379. util.request(api.saveVisit, params, 'POST').then(res => {
  380. wx.hideLoading();
  381. if (res.errno === 0) {
  382. console.log(res);
  383. wx.showToast({
  384. title: '提交成功',
  385. icon: 'success',
  386. duration: 2000
  387. });
  388. this.setData({
  389. isFinished: true
  390. });
  391. } else {
  392. wx.showToast({
  393. title: res.errmsg,
  394. icon: 'none',
  395. duration: 2000
  396. });
  397. }
  398. }).catch((err) => {
  399. wx.hideLoading();
  400. });
  401. },
  402. goDetail() {
  403. wx.navigateTo({
  404. url: '/pages/qwOrderDetail/qwOrderDetail?payId=' + this.data.tradeOrder.payId
  405. });
  406. },
  407. onOverlayHide() {
  408. },
  409. })