xunjian.js 13 KB

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