xunjian.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. success(res) {
  46. let tempFilePath = res.tempFiles[0].tempFilePath
  47. console.log(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. console.log(this.data.xunjianItems)
  126. // this.cz_xunjianItems(listid, checked, jibie);
  127. },
  128. //tab
  129. pagechange: function (e) {
  130. // 通过touch判断,改变tab的下标值
  131. if ("touch" === e.detail.source) {
  132. let currentPageIndex = this.data.tabcurrentIndex;
  133. currentPageIndex = (currentPageIndex + 1) % 2;
  134. // 拿到当前索引并动态改变
  135. this.setData({
  136. tabcurrentIndex: currentPageIndex,
  137. })
  138. }
  139. },
  140. bindbusTrackContent(e) {
  141. let that = this
  142. let jibie = e.currentTarget.dataset.jibie
  143. let listid = e.currentTarget.dataset.listid
  144. this.data.xunjianItems[jibie][1].forEach(function (item, index) {
  145. if (item.listid == listid) {
  146. that.data.xunjianItems[jibie][1][index].busTrackContent = e.detail.value
  147. }
  148. })
  149. },
  150. getTimeLimit(e) {
  151. let that = this
  152. let jibie = e.currentTarget.dataset.jibie
  153. let listid = e.currentTarget.dataset.listid
  154. this.data.xunjianItems[jibie][1].forEach(function (item, index) {
  155. if (item.listid == listid) {
  156. that.data.xunjianItems[jibie][1][index].timeLimit = e.detail.value
  157. }
  158. })
  159. },
  160. titleClick: function (e) {
  161. let that = this
  162. let jibie = e.currentTarget.dataset.jibie
  163. let listid = e.currentTarget.dataset.listid
  164. let itemsType = e.currentTarget.dataset.idx
  165. this.data.xunjianItems[jibie][1].forEach(function (item, index) {
  166. if (item.listid == listid) {
  167. that.data.xunjianItems[jibie][1][index].itemsType = itemsType
  168. let str = 'xunjianItems["' + jibie + '"][1][' + index + '].itemsType'
  169. console.log("str", str)
  170. console.log(that.data.xunjianItems[jibie][1][index].itemsType)
  171. that.setData({
  172. xunjianItems: that.data.xunjianItems
  173. })
  174. }
  175. })
  176. },
  177. //上传图片
  178. // 删除图片
  179. clearImg: function (e) {
  180. var nowList = []; //新数据
  181. var uploaderList = this.data.uploaderList; //原数据
  182. for (let i = 0; i < uploaderList.length; i++) {
  183. if (i == e.currentTarget.dataset.index) {
  184. continue;
  185. } else {
  186. nowList.push(uploaderList[i])
  187. }
  188. }
  189. this.setData({
  190. uploaderNum: this.data.uploaderNum - 1,
  191. uploaderList: nowList,
  192. showUpload: true
  193. })
  194. },
  195. //展示图片
  196. showImg: function (e) {
  197. var that = this;
  198. wx.previewImage({
  199. urls: that.data.uploaderList,
  200. current: that.data.uploaderList[e.currentTarget.dataset.index]
  201. })
  202. },
  203. //上传图片
  204. onLoad: function (options) {
  205. console.log("TAG","onLoad_"+options.isBeforeBack);
  206. this.data.isBeforeBack=options.isBeforeBack;
  207. this.pictureAuthSetting()
  208. this.data.busEnterpriseId = options.busEnterpriseId
  209. // this.getXunjianItems()
  210. this.setData({
  211. //通过bind(this)将函数绑定到this上,以后函数内的this就是指全局页面
  212. //setdata以后,这两个函数就可以传递给mp-uploader了
  213. selectFile: this.selectFile.bind(this),
  214. uplaodFile: this.uplaodFile.bind(this),
  215. })
  216. },
  217. onShow:function(){
  218. let pages = getCurrentPages();
  219. let currPage = pages[pages.length-1];
  220. this.data.isAfterBack=currPage.data.isAfterBack;
  221. // this.data.busEnterpriseId = options.busEnterpriseId
  222. // console.log("TAG","onShow_before_"+this.data.isBeforeBack);
  223. // console.log("TAG","onShow_after_"+this.data.isAfterBack);
  224. if(this.data.isBeforeBack){
  225. this.getXunjianItems()
  226. this.data.isBeforeBack=false
  227. }
  228. if(this.data.isAfterBack){
  229. this.getXunjianItems()
  230. this.data.isAfterBack=false
  231. }
  232. },
  233. //mpuploader选择图片时的过滤函数,返回true表示图片有效
  234. selectFile(files) {
  235. wx.showLoading({
  236. title: '',
  237. })
  238. // 如果有大文件可以压缩一下
  239. // 返回false可以阻止本次文件上传
  240. },
  241. uplaodFile(files) {
  242. // 图片上传的函数,必须返回Promise
  243. //Promise的callback里面必须resolve({urls})表示成功,否则表示失败
  244. return new Promise((resolve, reject) => {
  245. const tempFilePaths = files.tempFilePaths;
  246. const that = this;
  247. let finished = {
  248. url: []
  249. } //本次上次成功的URL存入这个变量,被success方法的e.detail承接
  250. for (var i = 0; i < tempFilePaths.length; i++) {
  251. let filePath = tempFilePaths[i] //原名
  252. let cloudPath = 'qyzj' + new Date().getTime() + '-' + i + filePath.match(/\.[^.]+?$/)[0] //云存储文件名
  253. wx.cloud.uploadFile({
  254. filePath,
  255. cloudPath,
  256. //成功
  257. success: function (res) {
  258. if (res.statusCode != 200 && res.statusCode != 204 && res.statusCode != 205) reject('error') // 可能会有好几个200+的返回码,表示成功
  259. finished.url.push({
  260. url: res.fileID
  261. }) //成功一个存一个到本次上传成功列表
  262. //如果本次上传的文件都完成 或全局已经存满3张,resolve退出
  263. if (finished.urls.length === tempFilePaths.length || that.data.files.length + finished.urls.length == this.data.maximgs)
  264. resolve(finished)
  265. },
  266. //失败
  267. fail: function (err) {
  268. console.log(err)
  269. }
  270. })
  271. }
  272. })
  273. },
  274. uploadError(e) {
  275. console.log('upload error', e.detail)
  276. wx.hideLoading()
  277. this.setData({
  278. error: "上传失败,可能有些照片过大"
  279. })
  280. },
  281. uploadSuccess(e) {
  282. console.log('upload success', e.detail)
  283. this.data.files = this.data.files.concat(e.detail.url)
  284. this.setData({
  285. files: this.data.files,
  286. })
  287. wx.hideLoading()
  288. },
  289. //删除图片 detail为{index, item},index表示删除的图片的下标,item为图片对象。
  290. delimg(e) {
  291. this.data.files.splice(this.data.files.findIndex(item => item == e.detail.item), 1)
  292. },
  293. getXunjianItems() {
  294. // console.log("TAG","getXunjianItems")
  295. var obj = new Object()
  296. obj.busEnterpriseId = this.data.busEnterpriseId
  297. http.post("/system/AppXunjianController/getXunjianItems", obj, this.getXunjianItemsSuccess)
  298. },
  299. getXunjianItemsSuccess(res) {
  300. console.log(res)
  301. this.setData({
  302. xunjianItems: res.xunjianItems
  303. })
  304. },
  305. submitXujian() {
  306. var obj = new Object();
  307. let that = this
  308. wx.getLocation({
  309. type: 'wgs84', //返回可以用于wx.openLocation的经纬度,
  310. success: function (res) {
  311. obj.latitude = res.latitude
  312. obj.longitude = res.longitude
  313. obj.xuanjianItems = that.data.xunjianItems
  314. obj.busEnterpriseId = that.data.busEnterpriseId
  315. http.send_post("/system/AppXunjianController/submitXunjian", obj, that.submitXujianSuccess)
  316. }
  317. })
  318. },
  319. submitXujianSuccess(res) {
  320. if (res.code == 200) {
  321. if (res.data.haveXQZG == true) {
  322. //有限期整改的东西,去通知书页面
  323. wx.redirectTo({
  324. url: '../xqzggzs2/xqzggzs2?logId=' + res.data.logId + "&busEnterpriseId=" + this.data.busEnterpriseId,
  325. })
  326. } else {
  327. // 直接返回详情页
  328. wx.navigateBack({
  329. url: '../details/details?busEnterpriseId=' + this.data.busEnterpriseId,
  330. })
  331. }
  332. } else {
  333. wx.showToast({
  334. title: res.msg,
  335. icon: "none"
  336. })
  337. }
  338. },
  339. cz_xunjianItems(listid, checked, jibie) {
  340. this.data.xunjianItems[jibie][1].forEach(item => {
  341. if (item.listid == listid) {
  342. item.checked = checked
  343. }
  344. })
  345. },
  346. bindViewXunJiancz() {
  347. let obj = new Object()
  348. obj.busEnterpriseId = this.data.busEnterpriseId
  349. http.post('/system/AppXunjianController/getBusInspectionIsRiskByEnterpriseCount',
  350. obj, this.getBusInspectionIsRiskByEnterpriseCountSuccess)
  351. },
  352. getBusInspectionIsRiskByEnterpriseCountSuccess(res) {
  353. console.log(res)
  354. if (res.code == 200) {
  355. wx.navigateTo({
  356. url: '../xunjiancz/xunjiancz?busEnterpriseId=' + this.data.busEnterpriseId,
  357. })
  358. } else {
  359. wx.showToast({
  360. title: res.msg,
  361. icon: "none"
  362. })
  363. }
  364. },
  365. //-------------------悬浮移动---------------------------------------------------
  366. // 触摸开始事件
  367. touchStart: function (e) {
  368. touchStartX = e.touches[0].pageX; // 获取触摸时的原点
  369. touchStartY = e.touches[0].pageY; // 获取触摸时的原点
  370. // 使用js计时器记录时间
  371. interval = setInterval(function () {
  372. time++;
  373. }, 100);
  374. },
  375. // 触摸移动事件
  376. touchMove: function (e) {
  377. touchMoveX = e.touches[0].pageX;
  378. touchMoveY = e.touches[0].pageY;
  379. },
  380. // 触摸结束事件
  381. touchEnd: function (e) {
  382. var moveX = touchMoveX - touchStartX
  383. var moveY = touchMoveY - touchStartY
  384. if (Math.sign(moveX) == -1) {
  385. moveX = moveX * -1
  386. }
  387. if (Math.sign(moveY) == -1) {
  388. moveY = moveY * -1
  389. }
  390. if (moveX <= moveY) { // 上下
  391. // 向上滑动
  392. if (touchMoveY - touchStartY <= -30 && time < 10) {
  393. console.log("向上滑动")
  394. }
  395. // 向下滑动
  396. if (touchMoveY - touchStartY >= 30 && time < 10) {
  397. console.log('向下滑动 ');
  398. }
  399. } else { // 左右
  400. // 向左滑动
  401. if (touchMoveX - touchStartX <= -30 && time < 10) {
  402. console.log("左滑页面")
  403. }
  404. // 向右滑动
  405. if (touchMoveX - touchStartX >= 30 && time < 10) {
  406. console.log('向右滑动');
  407. }
  408. }
  409. clearInterval(interval); // 清除setInterval
  410. time = 0;
  411. },
  412. })
  413. var touchStartX = 0; //触摸时的原点
  414. var touchStartY = 0; //触摸时的原点
  415. var time = 0; // 时间记录,用于滑动时且时间小于1s则执行左右滑动
  416. var interval = ""; // 记录/清理时间记录
  417. var touchMoveX = 0; // x轴方向移动的距离
  418. var touchMoveY = 0; // y轴方向移动的距离