xunjian.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. // pages/xunjian/xunjian.js
  2. import http from '../../base/httputil'
  3. import tools from '../../base/tools'
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. host: app.globalData.host,
  11. busEnterpriseId: null,
  12. xunjianItems: null,
  13. hui: "block",
  14. currentIndex: "block",
  15. tabcurrentIndex: 0, //默认是活动项
  16. currentItemId: "0",
  17. //上传图片
  18. //mp-uploader
  19. maximgs: 5, //最大上传数
  20. files: [], //上传组件绑定的文件urls
  21. sizeType: ['compressed'], //压缩上传,可以是['original', 'compressed']
  22. sourceType: ['album', 'camera'], //相册,或拍照
  23. listdata: [{
  24. info: "建立安全防火制度,明确防火责任人及其职责",
  25. checked: true,
  26. listid: "0"
  27. },
  28. {
  29. info: "建立安全防火制度,明确防火责任人及其职责,建立安全防火制度,明确防火责任人及其职责,建立安全防火制度,明确防火责任人及其职责",
  30. checked: true,
  31. listid: "1"
  32. },
  33. ],
  34. isBeforeBack: false,
  35. isAfterBack: false,
  36. },
  37. takePicture: function (e) {
  38. // 拍照
  39. let jibie = e.currentTarget.dataset.jibie
  40. let listid = e.currentTarget.dataset.listid
  41. let from = e.currentTarget.dataset.picfrom
  42. let that = this
  43. wx.chooseMedia({
  44. sourceType: ['album', 'camera'],
  45. count: 1,
  46. success(res) {
  47. let tempFilePath = res.tempFiles[0].tempFilePath
  48. //
  49. that.data.xunjianItems[jibie][1].forEach(function (item, index) {
  50. if (item.listid == listid) {
  51. let uuid = tools.uuid()
  52. let picutre = {
  53. "pic_key": uuid,
  54. "pic_value": tempFilePath,
  55. "pic_base64": wx.getFileSystemManager().readFileSync(tempFilePath, 'base64')
  56. }
  57. if (from == "before") {
  58. that.data.xunjianItems[jibie][1][index].picturesBefore.push(picutre)
  59. }
  60. if (from == "after") {
  61. that.data.xunjianItems[jibie][1][index].picturesAfter.push(picutre)
  62. }
  63. // let str = 'xunjianItems["' + jibie + '"][1][' + index + '].checked'
  64. that.setData({
  65. xunjianItems: that.data.xunjianItems
  66. })
  67. }
  68. })
  69. }
  70. })
  71. this.setData({
  72. show: false
  73. })
  74. },
  75. deletePic(e) {
  76. let that = this
  77. let jibie = e.currentTarget.dataset.jibie
  78. let listid = e.currentTarget.dataset.listid
  79. let pickey = e.currentTarget.dataset.pickey
  80. let from = e.currentTarget.dataset.picfrom
  81. // console.log(jibie, listid, pickey, from)
  82. this.data.xunjianItems[jibie][1].forEach(function (item, index) {
  83. if (item.listid == listid) {
  84. if (from == "before") {
  85. that.data.xunjianItems[jibie][1][index].picturesBefore.forEach(function (it, inx) {
  86. if (it.pic_key == pickey) {
  87. that.data.xunjianItems[jibie][1][index].picturesBefore.splice(inx, 1)
  88. }
  89. })
  90. } else if (from == "after") {
  91. that.data.xunjianItems[jibie][1][index].picturesAfter.forEach(function (it, inx) {
  92. if (it.pic_key == pickey) {
  93. that.data.xunjianItems[jibie][1][index].picturesAfter.splice(inx, 1)
  94. }
  95. })
  96. }
  97. that.setData({
  98. xunjianItems: that.data.xunjianItems
  99. })
  100. }
  101. })
  102. },
  103. pictureAuthSetting() {
  104. wx.authorize({
  105. scope: 'scope.camera',
  106. success(res) {
  107. console.log("申请使用摄像头成功,", res)
  108. }
  109. })
  110. },
  111. changeme: function (e) {
  112. let that = this
  113. let checked = e.detail.value;
  114. let jibie = e.currentTarget.dataset.jibie
  115. let listid = e.currentTarget.dataset.index
  116. this.data.xunjianItems[jibie][1].forEach(function (item, index) {
  117. if (item.listid == listid) {
  118. that.data.xunjianItems[jibie][1][index].checked = checked
  119. let str = 'xunjianItems["' + jibie + '"][1][' + index + '].checked'
  120. that.setData({
  121. xunjianItems: that.data.xunjianItems
  122. })
  123. }
  124. })
  125. // this.cz_xunjianItems(listid, checked, jibie);
  126. },
  127. //tab
  128. pagechange: function (e) {
  129. // 通过touch判断,改变tab的下标值
  130. if ("touch" === e.detail.source) {
  131. let currentPageIndex = this.data.tabcurrentIndex;
  132. currentPageIndex = (currentPageIndex + 1) % 2;
  133. // 拿到当前索引并动态改变
  134. this.setData({
  135. tabcurrentIndex: currentPageIndex,
  136. })
  137. }
  138. },
  139. bindbusTrackContent(e) {
  140. let that = this
  141. let jibie = e.currentTarget.dataset.jibie
  142. let listid = e.currentTarget.dataset.listid
  143. this.data.xunjianItems[jibie][1].forEach(function (item, index) {
  144. if (item.listid == listid) {
  145. that.data.xunjianItems[jibie][1][index].busTrackContent = e.detail.value
  146. }
  147. })
  148. },
  149. getTimeLimit(e) {
  150. let that = this
  151. let jibie = e.currentTarget.dataset.jibie
  152. let listid = e.currentTarget.dataset.listid
  153. this.data.xunjianItems[jibie][1].forEach(function (item, index) {
  154. if (item.listid == listid) {
  155. that.data.xunjianItems[jibie][1][index].timeLimit = e.detail.value
  156. }
  157. })
  158. },
  159. titleClick: function (e) {
  160. let that = this
  161. let jibie = e.currentTarget.dataset.jibie
  162. let listid = e.currentTarget.dataset.listid
  163. let itemsType = e.currentTarget.dataset.idx
  164. this.data.xunjianItems[jibie][1].forEach(function (item, index) {
  165. if (item.listid == listid) {
  166. that.data.xunjianItems[jibie][1][index].itemsType = itemsType
  167. let str = 'xunjianItems["' + jibie + '"][1][' + index + '].itemsType'
  168. that.setData({
  169. xunjianItems: that.data.xunjianItems
  170. })
  171. }
  172. })
  173. },
  174. //上传图片
  175. // 删除图片
  176. clearImg: function (e) {
  177. var nowList = []; //新数据
  178. var uploaderList = this.data.uploaderList; //原数据
  179. for (let i = 0; i < uploaderList.length; i++) {
  180. if (i == e.currentTarget.dataset.index) {
  181. continue;
  182. } else {
  183. nowList.push(uploaderList[i])
  184. }
  185. }
  186. this.setData({
  187. uploaderNum: this.data.uploaderNum - 1,
  188. uploaderList: nowList,
  189. showUpload: true
  190. })
  191. },
  192. //展示图片
  193. showImg: function (e) {
  194. var that = this;
  195. wx.previewImage({
  196. urls: that.data.uploaderList,
  197. current: that.data.uploaderList[e.currentTarget.dataset.index]
  198. })
  199. },
  200. //上传图片
  201. onLoad: function (options) {
  202. //console.log("TAG", "onLoad_" + options.isBeforeBack);
  203. this.data.isBeforeBack = options.isBeforeBack;
  204. this.pictureAuthSetting()
  205. this.data.busEnterpriseId = options.busEnterpriseId
  206. // this.getXunjianItems()
  207. // this.setData({
  208. // //通过bind(this)将函数绑定到this上,以后函数内的this就是指全局页面
  209. // //setdata以后,这两个函数就可以传递给mp-uploader了
  210. // selectFile: this.selectFile.bind(this),
  211. // uplaodFile: this.uplaodFile.bind(this),
  212. // })
  213. },
  214. onShow: function () {
  215. let pages = getCurrentPages();
  216. let currPage = pages[pages.length - 1];
  217. this.data.isAfterBack = currPage.data.isAfterBack;
  218. // this.data.busEnterpriseId = options.busEnterpriseId
  219. // console.log("TAG","onShow_before_"+this.data.isBeforeBack);
  220. // console.log("TAG","onShow_after_"+this.data.isAfterBack);
  221. if (this.data.isBeforeBack) {
  222. this.getXunjianItems()
  223. this.data.isBeforeBack = false
  224. }
  225. if (this.data.isAfterBack) {
  226. this.getXunjianItems()
  227. this.data.isAfterBack = false
  228. }
  229. },
  230. //mpuploader选择图片时的过滤函数,返回true表示图片有效
  231. // selectFile(files) {
  232. // wx.showLoading({
  233. // title: '',
  234. // })
  235. // // 如果有大文件可以压缩一下
  236. // // 返回false可以阻止本次文件上传
  237. // },
  238. // uplaodFile(files) {
  239. // // 图片上传的函数,必须返回Promise
  240. // //Promise的callback里面必须resolve({urls})表示成功,否则表示失败
  241. // return new Promise((resolve, reject) => {
  242. // const tempFilePaths = files.tempFilePaths;
  243. // const that = this;
  244. // let finished = {
  245. // url: []
  246. // } //本次上次成功的URL存入这个变量,被success方法的e.detail承接
  247. // for (var i = 0; i < tempFilePaths.length; i++) {
  248. // let filePath = tempFilePaths[i] //原名
  249. // let cloudPath = 'qyzj' + new Date().getTime() + '-' + i + filePath.match(/\.[^.]+?$/)[0] //云存储文件名
  250. // wx.cloud.uploadFile({
  251. // filePath,
  252. // cloudPath,
  253. // //成功
  254. // success: function (res) {
  255. // if (res.statusCode != 200 && res.statusCode != 204 && res.statusCode != 205) reject('error') // 可能会有好几个200+的返回码,表示成功
  256. // finished.url.push({
  257. // url: res.fileID
  258. // }) //成功一个存一个到本次上传成功列表
  259. // //如果本次上传的文件都完成 或全局已经存满3张,resolve退出
  260. // if (finished.urls.length === tempFilePaths.length || that.data.files.length + finished.urls.length == this.data.maximgs)
  261. // resolve(finished)
  262. // },
  263. // //失败
  264. // fail: function (err) {
  265. // }
  266. // })
  267. // }
  268. // })
  269. // },
  270. // uploadError(e) {
  271. // wx.hideLoading()
  272. // this.setData({
  273. // error: "上传失败,可能有些照片过大"
  274. // })
  275. // },
  276. // uploadSuccess(e) {
  277. // this.data.files = this.data.files.concat(e.detail.url)
  278. // this.setData({
  279. // files: this.data.files,
  280. // })
  281. // wx.hideLoading()
  282. // },
  283. //删除图片 detail为{index, item},index表示删除的图片的下标,item为图片对象。
  284. // delimg(e) {
  285. // this.data.files.splice(this.data.files.findIndex(item => item == e.detail.item), 1)
  286. // },
  287. getXunjianItems() {
  288. // console.log("TAG","getXunjianItems")
  289. var obj = new Object()
  290. obj.busEnterpriseId = this.data.busEnterpriseId
  291. http.post("/system/AppXunjianController/getXunjianItems", obj, this.getXunjianItemsSuccess)
  292. },
  293. getXunjianItemsSuccess(res) {
  294. this.setData({
  295. xunjianItems: res.xunjianItems
  296. })
  297. },
  298. submitXujian() {
  299. var obj = new Object();
  300. let that = this
  301. wx.getLocation({
  302. type: 'wgs84', //返回可以用于wx.openLocation的经纬度,
  303. success: function (res) {
  304. obj.latitude = res.latitude
  305. obj.longitude = res.longitude
  306. obj.xuanjianItems = that.data.xunjianItems
  307. obj.busEnterpriseId = that.data.busEnterpriseId
  308. http.send_post("/system/AppXunjianController/submitXunjian", obj, that.submitXujianSuccess)
  309. }
  310. })
  311. },
  312. submitXujianSuccess(res) {
  313. wx.showToast({
  314. title: res.msg,
  315. icon: "none"
  316. })
  317. setTimeout(() => {
  318. if (res.code == 200) {
  319. if (res.data.haveXQZG == true) {
  320. //有限期整改的东西,去通知书页面
  321. wx.redirectTo({
  322. url: '../xqzggzs2/xqzggzs2?logId=' + res.data.logId + "&busEnterpriseId=" + this.data.busEnterpriseId,
  323. })
  324. } else {
  325. // 直接返回详情页
  326. wx.navigateBack({
  327. url: '../details/details?busEnterpriseId=' + this.data.busEnterpriseId,
  328. })
  329. }
  330. }
  331. }, 500);
  332. },
  333. cz_xunjianItems(listid, checked, jibie) {
  334. this.data.xunjianItems[jibie][1].forEach(item => {
  335. if (item.listid == listid) {
  336. item.checked = checked
  337. }
  338. })
  339. },
  340. bindViewXunJiancz() {
  341. let obj = new Object()
  342. obj.busEnterpriseId = this.data.busEnterpriseId
  343. http.post('/system/AppXunjianController/getBusInspectionIsRiskByEnterpriseCount',
  344. obj, this.getBusInspectionIsRiskByEnterpriseCountSuccess)
  345. },
  346. getBusInspectionIsRiskByEnterpriseCountSuccess(res) {
  347. if (res.code == 200) {
  348. wx.navigateTo({
  349. url: '../xunjiancz/xunjiancz?busEnterpriseId=' + this.data.busEnterpriseId,
  350. })
  351. } else {
  352. wx.showToast({
  353. title: res.msg,
  354. icon: "none"
  355. })
  356. }
  357. },
  358. //-------------------悬浮移动---------------------------------------------------
  359. // 触摸开始事件
  360. touchStart: function (e) {
  361. touchStartX = e.touches[0].pageX; // 获取触摸时的原点
  362. touchStartY = e.touches[0].pageY; // 获取触摸时的原点
  363. // 使用js计时器记录时间
  364. interval = setInterval(function () {
  365. time++;
  366. }, 100);
  367. },
  368. // 触摸移动事件
  369. touchMove: function (e) {
  370. touchMoveX = e.touches[0].pageX;
  371. touchMoveY = e.touches[0].pageY;
  372. },
  373. // 触摸结束事件
  374. touchEnd: function (e) {
  375. var moveX = touchMoveX - touchStartX
  376. var moveY = touchMoveY - touchStartY
  377. if (Math.sign(moveX) == -1) {
  378. moveX = moveX * -1
  379. }
  380. if (Math.sign(moveY) == -1) {
  381. moveY = moveY * -1
  382. }
  383. if (moveX <= moveY) { // 上下
  384. // 向上滑动
  385. if (touchMoveY - touchStartY <= -30 && time < 10) {
  386. console.log("向上滑动")
  387. }
  388. // 向下滑动
  389. if (touchMoveY - touchStartY >= 30 && time < 10) {
  390. console.log('向下滑动 ');
  391. }
  392. } else { // 左右
  393. // 向左滑动
  394. if (touchMoveX - touchStartX <= -30 && time < 10) {
  395. console.log("左滑页面")
  396. }
  397. // 向右滑动
  398. if (touchMoveX - touchStartX >= 30 && time < 10) {
  399. console.log('向右滑动');
  400. }
  401. }
  402. clearInterval(interval); // 清除setInterval
  403. time = 0;
  404. },
  405. })
  406. var touchStartX = 0; //触摸时的原点
  407. var touchStartY = 0; //触摸时的原点
  408. var time = 0; // 时间记录,用于滑动时且时间小于1s则执行左右滑动
  409. var interval = ""; // 记录/清理时间记录
  410. var touchMoveX = 0; // x轴方向移动的距离
  411. var touchMoveY = 0; // y轴方向移动的距离