newRevisit.js 11 KB

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