problemAdd.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. colorService: '#85868A',
  10. colorChange: '#85868A',
  11. name: '',
  12. problem: {
  13. id: 0,
  14. name: '',
  15. tempMobile:'',
  16. mobile: '',
  17. remark: '',
  18. picUrls: [],
  19. bookTime: "选择服务日期-时间",
  20. changeTime: '选择服务日期-时间',
  21. city: '',
  22. bookTradeNo: ''
  23. },
  24. problemInfo: {},
  25. files: [],
  26. date: [
  27. ["2021-02-01", "2021-02-02", "2021-02-03"],
  28. ["2021-02-04", "2021-02-05", "2021-02-06"]
  29. ],
  30. multiIndex: [0, 2, 0],
  31. multiChangeIndex: 0,
  32. oneHour: ["08:30-09:30", "10:45-11:45", "13:00-14:00", "14:45-15:45", "17:30-18:30", "17:30-19:30", "20:00-21:00"],
  33. twoHour: ["08:00-10:00", "13:00-15:00", "16:00-18:00"],
  34. threeHour: ["08:00-11:00", "12:00-15:00", "13:00-16:00", "17:00-20:00", "17:30-20:30"],
  35. fourHour: ["08:00-12:00", "13:45-17:45", "14:00-18:00", "17:00-21:00", "18:00-22:00"],
  36. sixHour: ["08:00-14:00", "13:00-19:00"],
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. console.info(options)
  43. let that = this
  44. that.setData({
  45. 'problem.id': options.id,
  46. name: options.name,
  47. })
  48. that.initServiceDate();
  49. that.getProblemInfo(options.id);
  50. if (options.bookTradeNo) {
  51. that.setData({
  52. 'problem.bookTradeNo': options.bookTradeNo
  53. })
  54. that.getBookTradeInfo();
  55. }
  56. },
  57. getProblemInfo(id) {
  58. let that = this
  59. wx.showLoading();
  60. util.request(api.ProblemInfo, {
  61. id: id
  62. }).then(function (res) {
  63. wx.hideLoading();
  64. console.info(res.data)
  65. if (res.errno === 0) {
  66. that.setData({
  67. problemInfo: res.data
  68. });
  69. }
  70. });
  71. },
  72. maskPhone(phone) {
  73. if (!phone || phone.length !== 11) return phone; // 确保电话号码有效且长度为11位
  74. return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
  75. },
  76. getBookTradeInfo() {
  77. let that = this
  78. if (that.data.problem.bookTradeNo) {
  79. util.request(api.BookHmTradeInfo, {
  80. bookTradeNo: that.data.problem.bookTradeNo
  81. }).then(function (res) {
  82. if (res.errno === 0) {
  83. var p = that.data.problem;
  84. p.name = res.data.userName;
  85. p.mobile = res.data.userPhone;
  86. p.tempMobile=res.data.userPhone;//that.maskPhone(res.data.userPhone);
  87. if(that.data.problem.bookTradeNo.indexOf("JZ")==-1){
  88. p.tempMobile=that.maskPhone(res.data.userPhone);
  89. }
  90. p.bookTime = res.data.bookTime;
  91. p.changeTime = '选择服务日期-时间',
  92. that.setData({
  93. problem: p,
  94. colorService: '#333'
  95. });
  96. }
  97. });
  98. }
  99. },
  100. initServiceDate() { //构造服务日期及时间段
  101. var date = [];
  102. var now = util.formatDate(new Date());
  103. for (var i = 0; i < 7; i++) {
  104. date.push(util.mathChangeDate(now, '+', i, true));
  105. }
  106. var data = [];
  107. data.push(date, ['1小时', '2小时', '3小时', '4小时', '6小时'], this.data.threeHour);
  108. console.info(data)
  109. this.setData({
  110. date: data
  111. })
  112. },
  113. /**
  114. * 生命周期函数--监听页面初次渲染完成
  115. */
  116. onReady: function () {
  117. },
  118. //服务时间段
  119. bindMultiPickerChange(e) {
  120. console.info(e)
  121. var date = this.data.date[0][e.detail.value[0]]
  122. var time = this.data.date[2][e.detail.value[2]]
  123. this.setData({
  124. 'problem.bookTime': date + ' ' + time,
  125. colorService: '#333'
  126. })
  127. },
  128. bindMultiPickerColumnChange(e) {
  129. console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
  130. let that = this
  131. var data = that.data.date;
  132. if (e.detail.column == 1) { //修改时间段列
  133. switch (e.detail.value) {
  134. case 0: //"1小时"
  135. data[2] = that.data.oneHour;
  136. break;
  137. case 1: //"2小时"
  138. data[2] = that.data.twoHour;
  139. break;
  140. case 2: //"3小时"
  141. data[2] = that.data.threeHour;
  142. break;
  143. case 3: //"4小时"
  144. data[2] = that.data.fourHour;
  145. break;
  146. case 4: //"6小时"
  147. data[2] = that.data.sixHour;
  148. break;
  149. }
  150. this.setData({
  151. date: data
  152. })
  153. }
  154. },
  155. bindNeedFollowed(e){//是否需要客服介入
  156. console.info(e.detail.value)
  157. this.setData({
  158. 'problem.isNeedFollowed': e.detail.value
  159. })
  160. },
  161. //期望服务时间
  162. bindChangePickerChange(e) {
  163. var date = this.data.date[0][e.detail.value[0]]
  164. var time = this.data.date[2][e.detail.value[2]]
  165. this.setData({
  166. 'problem.changeTime': date + ' ' + time,
  167. colorChange: '#333'
  168. })
  169. },
  170. /**
  171. * 生命周期函数--监听页面显示
  172. */
  173. onShow: function () {
  174. this.setData({
  175. 'problem.city': app.globalData.city
  176. })
  177. },
  178. saveProblem() {
  179. console.info("handle saveProblem")
  180. let that = this
  181. if (that.data.problem.tempMobile.length != 11 || that.data.problem.tempMobile.startsWith("1") == false) {
  182. wx.showToast({
  183. title: '请输入正确手机号',
  184. duration: 3000,
  185. icon:'none'
  186. });
  187. return;
  188. }
  189. if(that.data.problem.tempMobile.indexOf("*")==-1){//用输入后的手机
  190. this.setData({
  191. 'problem.mobile': that.data.problem.tempMobile
  192. })
  193. }
  194. if (that.data.problem.bookTime == '选择服务日期-时间') {
  195. wx.showToast({
  196. title: '请选择服务时间',
  197. duration: 3000,
  198. icon:'none'
  199. });
  200. return;
  201. }
  202. if (that.data.problemInfo.isChangeTime && that.data.problem.changeTime == '选择服务日期-时间') {
  203. wx.showToast({
  204. title: '请选择期望改约的服务时间',
  205. duration: 3000,
  206. icon:'none'
  207. });
  208. return;
  209. }
  210. if (that.data.problemInfo.isNeedPic && that.data.problem.picUrls.length == 0) {
  211. wx.showToast({
  212. title: '请上传照片',
  213. duration: 3000,
  214. icon:'none'
  215. });
  216. return;
  217. }
  218. console.log(that.data.problem);
  219. wx.showModal({
  220. title: '提示',
  221. content: '确定要报备此问题吗?',
  222. success: function (sm) {
  223. if (sm.confirm) {
  224. wx.showLoading();
  225. util.request(api.ProblemAdd, that.data.problem, "POST").then(function (res) {
  226. wx.hideLoading();
  227. let msg=typeof that.data.problemInfo.alertMsg=='undefined'? '问题报备成功':that.data.problemInfo.alertMsg;
  228. if (res.errno === 0) {
  229. wx.showModal({
  230. title: '报备成功',
  231. content: msg,
  232. showCancel: false,//是否显示取消按钮
  233. confirmText:"确定",//默认是“确定”
  234. confirmColor: 'skyblue',//确定文字的颜色
  235. success: function (res) {
  236. if (res.cancel) {
  237. //点击取消,默认隐藏弹框
  238. } else {
  239. //点击确定
  240. // wx.switchTab({
  241. // url: '/pages/problem/index',
  242. // })
  243. // wx.navigateTo({
  244. // url: '/pages/new/ticketDetail/ticketDetail?bookTradeNo=' + that.data.problem.bookTradeNo,
  245. // })
  246. wx.navigateBack({
  247. delta: 2,
  248. })
  249. }
  250. },
  251. })
  252. } else {
  253. wx.showToast({
  254. title: res.errmsg,
  255. duration: 3000
  256. });
  257. }
  258. });
  259. }
  260. }
  261. })
  262. },
  263. bindRemark(e) {
  264. this.setData({
  265. 'problem.remark': e.detail.value
  266. })
  267. },
  268. bindName(e) {
  269. this.setData({
  270. 'problem.name': e.detail.value
  271. })
  272. },
  273. bindMobile(e) {
  274. this.setData({
  275. 'problem.tempMobile': e.detail.value
  276. })
  277. },
  278. chooseImage: function (e) {
  279. if (this.data.files.length >= 5) {
  280. util.showErrorToast('只能上传五张图片')
  281. return false;
  282. }
  283. var that = this;
  284. wx.chooseImage({
  285. count: 1,
  286. sizeType: ['original', 'compressed'],
  287. sourceType: ['album', 'camera'],
  288. success: function (res) {
  289. that.setData({
  290. files: that.data.files.concat(res.tempFilePaths)
  291. });
  292. console.info(res.tempFilePaths[0])
  293. //that.compressImage(res.tempFilePaths[0], (res1) => {
  294. that.upload(res)
  295. //})
  296. }
  297. })
  298. },
  299. upload: function (res) {
  300. var that = this;
  301. const uploadTask = wx.uploadFile({
  302. url: api.StorageUpload(),
  303. filePath: res.tempFilePaths[0],
  304. name: 'file',
  305. success: function (res) {
  306. var _res = JSON.parse(res.data);
  307. if (_res.errno === 0) {
  308. var url = _res.data.fileUrl
  309. var pics = that.data.problem.picUrls;
  310. pics.push(url);
  311. that.setData({
  312. hasPicture: true,
  313. 'problem.picUrls': pics
  314. })
  315. }
  316. },
  317. fail: function (e) {
  318. wx.showModal({
  319. title: '错误',
  320. content: '上传失败',
  321. showCancel: false
  322. })
  323. },
  324. })
  325. uploadTask.onProgressUpdate((res) => {
  326. console.log('上传进度', res.progress)
  327. console.log('已经上传的数据长度', res.totalBytesSent)
  328. console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
  329. })
  330. },
  331. previewImage: function (e) {
  332. wx.previewImage({
  333. current: e.currentTarget.id, // 当前显示图片的http链接
  334. urls: this.data.files // 需要预览的图片http链接列表
  335. })
  336. },
  337. compressImage(path, callback) {
  338. var that = this;
  339. //获取图片信息
  340. wx.getImageInfo({
  341. src: path,
  342. success: function (res) {
  343. //如果图片小于1200宽度 不压缩
  344. if (res.width < 1200) {
  345. callback(res.path);
  346. return
  347. }
  348. console.info("开始压缩")
  349. var ctx = wx.createCanvasContext('photo_canvas'); // 创建画布
  350. var towidth = 1200; //设置canvas尺寸,按宽度500px的比例压缩
  351. var toheight = Math.trunc(1200 * res.height / res.width); //根据图片比例换算出图片高度
  352. that.setData({
  353. canvasHeight: toheight
  354. });
  355. console.info("开始压缩2")
  356. ctx.drawImage(path, 0, 0, res.width, res.height, 0, 0, towidth, toheight);
  357. console.info("开始压缩3")
  358. ctx.draw(false, function () {
  359. wx.canvasToTempFilePath({
  360. canvasId: 'photo_canvas',
  361. fileType: "jpg",
  362. quality: 0.8,
  363. success: function (res) {
  364. console.log(res.tempFilePath);
  365. callback(res.tempFilePath);
  366. },
  367. fail: function (res) {
  368. console.info(res)
  369. }
  370. }, this)
  371. })
  372. console.info("开始压缩4")
  373. }
  374. });
  375. },
  376. /**
  377. * 生命周期函数--监听页面隐藏
  378. */
  379. onHide: function () {
  380. },
  381. /**
  382. * 生命周期函数--监听页面卸载
  383. */
  384. onUnload: function () {
  385. },
  386. /**
  387. * 页面相关事件处理函数--监听用户下拉动作
  388. */
  389. onPullDownRefresh: function () {
  390. },
  391. /**
  392. * 页面上拉触底事件的处理函数
  393. */
  394. onReachBottom: function () {
  395. },
  396. /**
  397. * 用户点击右上角分享
  398. */
  399. onShareAppMessage: function () {
  400. }
  401. })