xunjian.js 12 KB

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