details.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. import * as echarts from '../../ec-canvas/echarts';
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. details: {
  9. chainName: '-',
  10. chainCode: '-',
  11. packageTypeName: '-',
  12. productName: '-',
  13. num: '-',
  14. startTime: '-',
  15. transportStatusName: '-',
  16. userName: '-',
  17. telephone: '-',
  18. productId: '',
  19. status: '',
  20. chainId: '',
  21. },
  22. boundDevice: {},
  23. ec: {
  24. lazyLoad: true,
  25. },
  26. nav: 0,
  27. startDate: "", //开始时间
  28. endDate: "", //结束时间
  29. isshow: true,
  30. isShowText: '显示冷链',
  31. deviceCode: '',
  32. modalHidden: true,
  33. modalVal: '', // 解除预警信息
  34. deptType: '',
  35. seleteType: [{
  36. transportStatus: '00',
  37. transportStatusName: '已入库'
  38. }, {
  39. transportStatus: '10',
  40. transportStatusName: '已出库'
  41. }, {
  42. transportStatus: '20',
  43. transportStatusName: '已结束'
  44. }],
  45. region: [],
  46. allMoer: false,
  47. chainBoundId: '',
  48. tableCoin: [{
  49. name: 'X201',
  50. img: '../../img/work_icon11.png',
  51. status: true,
  52. type: 'lableX201'
  53. },
  54. {
  55. name: 'X202',
  56. img: '../../img/X202.png',
  57. status: true,
  58. type: 'lableX202'
  59. },
  60. {
  61. name: 'X203',
  62. img: '../../img/work_icon11.png',
  63. status: true,
  64. type: 'lableX203'
  65. },
  66. {
  67. name: 'X101',
  68. img: '../../img/x1.png',
  69. status: true,
  70. type: 'lableX101'
  71. },
  72. {
  73. name: 'X102',
  74. img: '../../img/x102.png',
  75. status: true,
  76. type: 'lableX102'
  77. },
  78. {
  79. name: 'X103',
  80. img: '../../img/x2.png',
  81. status: true,
  82. type: 'lableX103'
  83. },
  84. {
  85. name: 'X104',
  86. img: '../../img/x1.png',
  87. status: true,
  88. type: 'lableX104'
  89. },
  90. {
  91. name: 'X105',
  92. img: '../../img/rfid.png',
  93. status: true,
  94. type: 'lableX105'
  95. },
  96. {
  97. name: 'X106',
  98. img: '../../img/x1.png',
  99. status: true,
  100. type: 'lableX106'
  101. },
  102. {
  103. name: 'X107',
  104. img: '../../img/x2.png',
  105. status: true,
  106. type: 'lableX107'
  107. },
  108. ],
  109. showDialog: false, //扫码弹窗
  110. },
  111. /**
  112. * 生命周期函数--监听页面加载
  113. */
  114. onLoad: function (options) {
  115. console.log(options);
  116. const that = this;
  117. //获取用户信息,判断userInfo是否过期
  118. let userInfo = wx.getStorageSync('userInfo');
  119. /**
  120. * status: 用户角色审核状态
  121. * 0 没有选择任何角色也没做任何认证
  122. * 10 审核中
  123. * 20 审核通过
  124. * ifOverFlow:是否通过验证
  125. * N 没有选择角色
  126. * Y 已选择角色
  127. * 非register时,如果是Y说明已经处于认证状态
  128. * admin创建企业,personnel选择了企业
  129. * loginRole:用户权限
  130. * admin 管理员
  131. * doctor 医生
  132. * register 自由注册 可申请为操作员
  133. * personnel 操作员 已选择企业未认证
  134. *
  135. */
  136. const {loginRole,ifOverFlow,status} = userInfo;
  137. that.setData({
  138. ispdfBut: loginRole == 'admin' ? true : loginRole == 'personnel' ? true : false,
  139. options,
  140. userInfo: wx.getStorageSync('userInfo')
  141. });
  142. //获取定位信息
  143. wx.getLocation({
  144. altitude: 'altitude',
  145. success(res) {
  146. that.setData({
  147. latitude: res.latitude,
  148. longitude: res.longitude,
  149. userLatitude: res.latitude,
  150. userLongitude: res.longitude,
  151. })
  152. },
  153. error() {
  154. app.showToptip(that, "worning", "获取位置信息失败")
  155. }
  156. })
  157. },
  158. onShow() {
  159. var options = this.data.options;
  160. this.getInfo(options);
  161. this.getBoundDevice(options);
  162. var coinStatus = JSON.parse(wx.getStorageSync('labelStatus'));
  163. var tableCoin = this.data.tableCoin;
  164. var temp = '';
  165. tableCoin.map((coinType, index) => {
  166. Object.keys(coinStatus).forEach(key => {
  167. if (key == coinType.type) {
  168. temp = 'tableCoin[' + index + '].status'
  169. this.setData({
  170. [temp]: coinStatus[key]
  171. })
  172. }
  173. })
  174. })
  175. },
  176. getInfo(params = {}) {
  177. var that = this;
  178. const { deviceType, deviceCode, pid, chainBoundId } = params;
  179. var seleteType = that.data.seleteType;
  180. wx.showLoading({
  181. title: '正在加载...',
  182. mask: true
  183. })
  184. app.requestP({
  185. url: "/chain/info",
  186. method: "post",
  187. data: {
  188. chainId: params.id || '',
  189. parentId: pid || 0,
  190. }
  191. }).then(res => {
  192. var data = res.data.data;
  193. const {
  194. chainId
  195. } = data;
  196. that.setData({
  197. details: data,
  198. // deptType:that.setTransportStatus(data.transportStatus),
  199. seleteType: that.setSeleteType(data.transportStatus),
  200. deviceCode,
  201. chainBoundId,
  202. })
  203. that.getHistory({
  204. chainId,
  205. searchTag: '0',
  206. deviceCode,
  207. chainBoundId,
  208. });
  209. that.getTempLine({
  210. chainId,
  211. searchTag: '0',
  212. deviceCode,
  213. deviceType,
  214. chainBoundId
  215. })
  216. }).catch(err => {
  217. app.showToptip(that, "error", "数据获取失败,请稍后再试")
  218. // 隐藏导航栏加载框
  219. wx.hideNavigationBarLoading();
  220. // 停止下拉动作
  221. wx.stopPullDownRefresh();
  222. })
  223. },
  224. setTransportStatus(transportStatus) {
  225. var seleteType = this.data.seleteType;
  226. var deptType;
  227. for (var i = 0; i < seleteType.length; i++) {
  228. if (seleteType[i].transportStatus == transportStatus) {
  229. deptType = i;
  230. break;
  231. }
  232. }
  233. return deptType;
  234. },
  235. setSeleteType(transportStatus) {
  236. var seleteType = this.data.seleteType;
  237. var type;
  238. for (var i = 0; i < seleteType.length; i++) {
  239. if (seleteType[i].transportStatus == transportStatus) {
  240. seleteType.splice(i, 1);
  241. break;
  242. }
  243. }
  244. this.setTransportStatus(transportStatus); //暂时不用
  245. return seleteType;
  246. },
  247. setType(e) {
  248. //数据
  249. var value = e.detail.value;
  250. var that = this;
  251. var chainId = that.data.details.chainId;
  252. var seleteType = that.data.seleteType;
  253. that.setData({
  254. deptType: value + ""
  255. })
  256. // app.requestP({
  257. // url:'/chain/editTransport',
  258. // method:'post',
  259. // data:{
  260. // addr:'',
  261. // chainId,
  262. // transportStatus:seleteType[value].transportStatus,
  263. // }
  264. // }).then(res=>{
  265. // that.setData({
  266. // deptType:value+''
  267. // })
  268. // app.showToptip(that,'success',res.data.msg)
  269. // }).catch(err=>{
  270. // app.showToptip(that,'error',err.data.msg)
  271. // })
  272. },
  273. setTransportStatus(transportStatus) {
  274. var seleteType = this.data.seleteType;
  275. var deptType;
  276. for (var i = 0; i < seleteType.length; i++) {
  277. if (seleteType[i].transportStatus == transportStatus) {
  278. deptType = i;
  279. break;
  280. }
  281. }
  282. return deptType;
  283. },
  284. getBoundDevice(params = {}) {
  285. var that = this;
  286. wx.showLoading({
  287. title: '正在加载...',
  288. mask: true
  289. })
  290. app.requestP({
  291. url: "/chainBound/boundDevice",
  292. method: 'post',
  293. data: {
  294. chainId: params.id
  295. }
  296. }).then(res => {
  297. const data = res.data.data;
  298. var bound = [];
  299. var name = ''
  300. Object.keys(data).forEach(key => {
  301. name = ''
  302. if (data[key].length == 0) {
  303. delete data[key]
  304. }else{
  305. if(key == 'childNum'){
  306. bound.push({title:'子冷链',info:data[key],isChild:true,code:key})
  307. }else if(key.indexOf('X') == -1 ){
  308. if(key == '10'){
  309. name = '追溯标签'
  310. }else if(key == '11'){
  311. name = '全程温控'
  312. }else if(key == '20'){
  313. name = '实时追溯'
  314. }
  315. bound.push({title:name,info:data[key],isChild:false,code:key})
  316. }else{
  317. bound.push({title:key,info:data[key],isChild:false,code:key})
  318. }
  319. }
  320. })
  321. that.setData({
  322. boundDevice: bound
  323. })
  324. }).catch(err => {
  325. app.showToptip(that, 'error', err.data.msg)
  326. })
  327. },
  328. goDetails(e) {
  329. var that = this;
  330. var type = e.currentTarget.dataset.code;
  331. var ischild = e.currentTarget.dataset.ischild;
  332. var info = e.currentTarget.dataset.details.info;
  333. if(ischild){
  334. this.goChainCold();
  335. }
  336. if(type == 10 || type == 11 || type == 20){
  337. app.showToptip(this,'error','暂不支持查看!')
  338. return;
  339. }
  340. var json = encodeURIComponent(JSON.stringify({details:info,devicetype:type}));
  341. wx.navigateTo({
  342. url: '/pages/query/vvmInfo?details=' + json + '&id=' + that.data.options.id,
  343. })
  344. },
  345. getHistory(params = {}) {
  346. var that = this;
  347. //chainId,deviceCode,endTime,searchTag,startTime
  348. app.requestP({
  349. url: '/chainLocal/localHistory',
  350. method: 'post',
  351. contentType: ' application/json',
  352. data: {
  353. ...params,
  354. }
  355. }).then(res => {
  356. that.setData({
  357. deviceCode: res.data.data.deviceCode || that.data.deviceCode || 'N/A',
  358. })
  359. that.setLocus(res.data.data);
  360. }).catch(err => {
  361. that.setLocus({
  362. points: []
  363. });
  364. // app.showToptip(that, 'error', err.data.msg)
  365. })
  366. },
  367. goChainCold() {
  368. var that = this;
  369. wx.navigateTo({
  370. url: '/pages/query/childlist/childlist?chainId=' + that.data.details.chainId
  371. })
  372. },
  373. setLocus(data) {
  374. const that = this;
  375. const {
  376. status,
  377. transportType,
  378. points
  379. } = data;
  380. let locations = points;
  381. for (let i in locations) { //设置起始marker
  382. locations[i].id = i - 0
  383. if (i == 0) {
  384. locations[i].iconPath = "/img/map_icon1.png";
  385. locations[i].width = 38;
  386. locations[i].height = 40;
  387. }
  388. if (i == locations.length - 1) {
  389. locations[i].iconPath = "/img/index_icon_" + transportType + '' + status + '' + ".png";
  390. locations[i].width = 54;
  391. locations[i].height = 54;
  392. }
  393. locations[i].latitude = locations[i].lat;
  394. locations[i].longitude = locations[i].lng;
  395. }
  396. that.mapCtx = wx.createMapContext('index_map');
  397. if (locations.length) {
  398. that.setData({
  399. latitude: locations[0].lat || that.data.userLatitude,
  400. longitude: locations[0].lng || that.data.userLongitude,
  401. markers: [locations[0], locations[locations.length - 1]],
  402. polyline: [{
  403. color: '#2D59E6',
  404. width: 2,
  405. points: points,
  406. // arrowLine:true
  407. }]
  408. })
  409. that.mapCtx.includePoints({
  410. points: points,
  411. padding: [50, 50, 50, 50]
  412. })
  413. } else {
  414. that.setData({
  415. latitude: that.data.userLatitude,
  416. longitude: that.data.userLongitude,
  417. markers: [{
  418. iconPath: '/img/index_icon_5000.png',
  419. width: '54',
  420. height: '54',
  421. latitude: that.data.latitude,
  422. longitude: that.data.longitude
  423. }],
  424. polyline: [{
  425. color: '#2D59E6',
  426. width: 2,
  427. points: [],
  428. // arrowLine:true
  429. }]
  430. })
  431. }
  432. that.data.locations = locations
  433. },
  434. getTempLine(params = {}) {
  435. const that = this;
  436. app.requestP({
  437. url: '/chain/tempLine',
  438. method: 'post',
  439. contentType: ' application/json',
  440. data: {
  441. ...params
  442. }
  443. }).then(res => {
  444. var data = res.data.data.temps;
  445. that.setData({
  446. temperature: data
  447. })
  448. if (data.length != 0) {
  449. that.setTemp(data);
  450. } else {
  451. // app.showToptip(that, 'error', '暂无温度数据');
  452. }
  453. }).catch(err => {
  454. // app.showToptip(that, 'error', '暂无温度数据');
  455. })
  456. },
  457. setTemp(data) {
  458. const that = this;
  459. that.ecWen = that.selectComponent('#ecDomWen');
  460. that.ecWen.init((canvas, width, height, dpr) => {
  461. const chart = echarts.init(canvas, null, {
  462. width: width,
  463. height: height,
  464. devicePixelRatio: dpr // new
  465. });
  466. var option = that.getOption();
  467. option.xAxis.data = data.map(v => v.createTime.replace(" ", "\n"))
  468. option.series[0].data = data.map(v => v.temp)
  469. option.dataZoom = [{
  470. type: "slider",
  471. start: 0,
  472. end: (100 / data.length) * 15, //显示五个
  473. },
  474. {
  475. type: "inside",
  476. start: 0,
  477. end: (100 / data.length) * 15, //显示五个
  478. },
  479. ]
  480. chart.setOption(option);
  481. return chart;
  482. })
  483. },
  484. getOption() {
  485. return {
  486. tooltip: {
  487. show: true,
  488. formatter: '{b}\n{c}℃',
  489. trigger: "axis",
  490. position: "top"
  491. },
  492. grid: {
  493. top: '5%',
  494. left: '0%',
  495. right: '5%',
  496. bottom: '18%',
  497. containLabel: true
  498. },
  499. xAxis: {
  500. type: 'category',
  501. nameTextStyle: {
  502. color: "#77869E",
  503. fontSize: 10
  504. },
  505. axisLabel: {
  506. color: "#cccccc",
  507. fontSize: 8,
  508. },
  509. axisLine: {
  510. onZero: false,
  511. lineStyle: {
  512. color: "#cccccc"
  513. }
  514. },
  515. axisTick: {
  516. show: false
  517. },
  518. splitLine: {
  519. show: true,
  520. },
  521. data: ['16:00 \n 2021-06-30', '16:00 \n 2021-06-30', '16:00 \n 2021-06-30', '16:00 \n 2021-06-30', '16:00 \n 2021-06-30', '16:00 \n 2021-06-30', '16:00 \n 2021-06-30']
  522. },
  523. yAxis: {
  524. type: 'value',
  525. splitNumber: 10,
  526. max: 40,
  527. axisLine: {
  528. lineStyle: {
  529. color: "#cccccc"
  530. },
  531. show: true
  532. },
  533. },
  534. series: [{
  535. type: 'line',
  536. showSymbol: false,
  537. smooth: true,
  538. lineStyle: {
  539. width: 1,
  540. color: "#328EFD", //#D4D4D4
  541. },
  542. markLine: {
  543. lineStyle: {
  544. color: "#F22424",
  545. },
  546. data: [{
  547. yAxis: 40
  548. }]
  549. },
  550. markPoint: {
  551. symbolSize: 30,
  552. //symbol:'diamond',
  553. label: {
  554. fontSize: 8,
  555. },
  556. data: [{
  557. type: 'max',
  558. name: '最大值'
  559. },
  560. {
  561. type: 'min',
  562. name: '最小值'
  563. }
  564. ]
  565. },
  566. areaStyle: {
  567. origin: "start",
  568. color: {
  569. type: 'linear',
  570. x: 0,
  571. y: 0,
  572. x2: 0,
  573. y2: 1,
  574. colorStops: [{
  575. offset: 0,
  576. color: '#FFFFFF' //
  577. }, {
  578. offset: 1,
  579. color: '#4C96FE' //#D4D4D4
  580. }],
  581. global: false
  582. }
  583. },
  584. data: [18, 36, 25, 30, -20, 40, 33]
  585. }]
  586. }
  587. },
  588. endDateChange(e) {
  589. this.setData({
  590. endDate: e.detail.value
  591. })
  592. },
  593. startDateChange(e) {
  594. this.setData({
  595. startDate: e.detail.value
  596. })
  597. },
  598. submitDate() {
  599. this.getTemp(1, this.data.options);
  600. },
  601. getTemp(type, params = {}) {
  602. var that = this;
  603. const {deviceCode,deviceType} = params;
  604. const chainId = that.data.details.chainId;
  605. var endDate = that.data.endDate;
  606. var startDate = that.data.startDate;
  607. if (type == 1) {
  608. if (endDate && startDate) {} else {
  609. app.showToptip(that, "worning", "请选择起止时间")
  610. return
  611. }
  612. }
  613. wx.showLoading({
  614. mask: true
  615. })
  616. this.getHistory({
  617. chainId,
  618. searchTag: 1,
  619. deviceCode,
  620. endTime: endDate + ' 23:59:59',
  621. startTime: startDate + ' 00:00:00'
  622. });
  623. this.getTempLine({
  624. chainId,
  625. searchTag: 1,
  626. deviceCode,
  627. deviceType,
  628. endTime: endDate + ' 23:59:59',
  629. startTime: startDate + ' 00:00:00'
  630. })
  631. },
  632. setNav(e) {
  633. var nav = e.currentTarget.dataset.val;
  634. const { deviceCode, deviceType, chainBoundId } = this.data.options;
  635. this.setData({
  636. nav,
  637. temperature: []
  638. });
  639. if (nav == 0 || nav == 2) {
  640. const chainId = this.data.details.chainId;
  641. this.getHistory({
  642. chainId,
  643. searchTag: nav,
  644. deviceCode,
  645. chainBoundId: chainBoundId || ''
  646. });
  647. this.getTempLine({
  648. chainId,
  649. searchTag: nav,
  650. deviceCode,
  651. deviceType,
  652. chainBoundId: chainBoundId || ''
  653. })
  654. }
  655. },
  656. isShow() {
  657. if (this.data.isshow) {
  658. this.setData({
  659. isShowText: '隐藏冷链',
  660. isshow: false
  661. })
  662. } else {
  663. this.setData({
  664. isShowText: '显示冷链',
  665. isshow: true
  666. })
  667. }
  668. },
  669. isAllMoer() {
  670. this.setData({
  671. allMoer: !this.data.allMoer
  672. })
  673. },
  674. cleanWarning(e) { // 解除预警
  675. const {
  676. details: {
  677. chainId
  678. },
  679. userInfo: {
  680. loginRole
  681. }
  682. } = this.data;
  683. var status = e.currentTarget.dataset.status;
  684. if (status == 10 || status == 20) {
  685. if (loginRole !== "doctor") {
  686. wx.navigateTo({
  687. url: '/pages/query/clearWarning/clearWarning?chainId=' + chainId, //details
  688. })
  689. } else {
  690. app.showToptip(this, 'error', '暂无权限');
  691. }
  692. }
  693. },
  694. goPdf(e) {
  695. var chainId = e.currentTarget.dataset.id;
  696. wx.navigateTo({
  697. url: '/pages/workbench/scanningType/reportPdf/reportPdf?id=' + chainId+'&orderid='+'',
  698. })
  699. },
  700. regionChange: function (e) {
  701. this.setData({
  702. region: e.detail.value
  703. })
  704. },
  705. setModalVal(e) {
  706. this.setData({
  707. modalVal: e.detail.value
  708. })
  709. },
  710. setmodalHidden(e) {
  711. var transportStatus = e.currentTarget.dataset.transportstatus;
  712. if (transportStatus == '00' || transportStatus == '10') {
  713. this.setData({
  714. modalHidden: !this.data.modalHidden,
  715. })
  716. } else if (transportStatus == '20') {
  717. app.showToptip(this, 'error', '冷链已结束,请勿修改运输状态')
  718. }
  719. },
  720. //取消按钮点击事件
  721. modalBindcancel: function () {
  722. this.setData({
  723. modalHidden: !this.data.modalHidden,
  724. region: [],
  725. modalVal: '',
  726. iodepId: '',
  727. })
  728. },
  729. modalBindaconfirm() { //二型保存地址
  730. var that = this;
  731. var {
  732. region,
  733. modalVal,
  734. iodepId,
  735. seleteType,
  736. deptType
  737. } = that.data;
  738. var {
  739. chainId,
  740. transportStatus
  741. } = that.data.details;
  742. var addr = region.join('') + modalVal;
  743. if (region.join('') && modalVal) {
  744. app.requestP({
  745. url: '/chain/editTransport',
  746. // contentType:' application/json',
  747. method: 'post',
  748. data: {
  749. addr,
  750. chainId, // 00 已入库 //10 已出库 //20 已结束
  751. transportStatus: seleteType[deptType].transportStatus,
  752. }
  753. }).then(res => {
  754. that.setData({
  755. modalHidden: !that.data.modalHidden,
  756. region: [],
  757. modalVal: '',
  758. iodepId: '',
  759. })
  760. that.getInfo({
  761. id: chainId
  762. });
  763. app.showToptip(that, 'success', res.data.msg);
  764. }).catch(err => {
  765. app.showToptip(that, 'error', err.data.msg);
  766. })
  767. } else {
  768. app.showToptip(that, 'error', '地址和运输状态不能为空');
  769. }
  770. },
  771. goTempDetail() {
  772. var {
  773. chainId
  774. } = this.data.details;
  775. var nav = this.data.nav;
  776. wx.navigateTo({
  777. url: '/pages/query/tempDetails/tempDetails?chainId=' + chainId + '&searchTag=' + nav,
  778. })
  779. },
  780. //查一查弹框控制
  781. showChaWin() {
  782. this.setData({
  783. showChaType: true
  784. })
  785. },
  786. closeChaWin() {
  787. this.setData({
  788. showChaType: false,
  789. })
  790. },
  791. chainCode(e) {
  792. var that = this;
  793. var chainId = e.currentTarget.dataset.id;
  794. var type = e.currentTarget.dataset.type;
  795. var code = e.currentTarget.dataset.code;
  796. that.scanCode().then(result => {
  797. app.requestP({
  798. url: '/chainSource/add',
  799. method: 'post',
  800. contentType: 'application/json',
  801. data: {
  802. chainId,
  803. [type]: result.code
  804. }
  805. }).then(res => {
  806. app.showToptip(that, 'success', res.data.msg);
  807. that.getInfo({
  808. id: chainId,
  809. pid: 0
  810. });
  811. }).catch(err => {
  812. app.showToptip(that, 'error', err.data.msg);
  813. })
  814. })
  815. },
  816. scanCode() {
  817. var that = this;
  818. return new Promise((resolve, reject) => {
  819. wx.scanCode({
  820. scanType: ['barCode', 'qrCode'],
  821. success: function (res) {
  822. var {result} = res;
  823. resolve({
  824. code: result
  825. })
  826. },
  827. fail: function (err) {
  828. app.showToptip(that, 'error', '扫码失败');
  829. }
  830. })
  831. })
  832. },
  833. copyCode(e) {
  834. wx.setClipboardData({
  835. data: e.currentTarget.dataset.code
  836. })
  837. },
  838. goScanSetting() {
  839. wx.navigateTo({
  840. url: '/pages/setting/scanSetting/scanSetting',
  841. })
  842. },
  843. addChain(e) {
  844. const type = e.currentTarget.dataset.type;
  845. var details = this.data.details;
  846. const noAdd = ['lableX101', 'lableX102', 'lableX103', 'lableX105', 'lableX106', 'lableX107','NFC'];
  847. if (noAdd.indexOf(type) != -1) {
  848. app.showToptip(this, 'error', '该标签暂不支持在小程序添加,请移动到APP操作!')
  849. return;
  850. }
  851. // 104 一型无源
  852. switch (type) {
  853. case 'lableX104':
  854. wx.navigateTo({
  855. url: '/pages/nfc/zhuisu2?id='+details.chainId+'&type=X104&addLabel=20',
  856. })
  857. break;
  858. default:
  859. this.setData({
  860. showDialog: !this.data.showDialog,
  861. devicetype:type
  862. })
  863. break;
  864. }
  865. },
  866. toggleDialog() { //弹窗关闭
  867. this.setData({
  868. showDialog: !this.data.showDialog,
  869. devicetype:''
  870. });
  871. },
  872. chainBind() {
  873. var that = this;
  874. wx.scanCode({
  875. success: function (res) {
  876. var { result } = res;
  877. if (result.indexOf('imei=') != -1) {
  878. result = result.slice(result.indexOf('imei=') + 5, result.length)
  879. }
  880. that.setchainBoundBind(result);
  881. },
  882. fail: function (err) {
  883. app.showToptip(that, 'error', '二维码无效');
  884. }
  885. })
  886. },
  887. setchainBoundBind(result) {
  888. var that = this;
  889. var options = this.data.options;
  890. const {details,devicetype,latitude,longitude} = that.data;
  891. app.requestP({
  892. url: '/chainBound/checkBind',
  893. method: 'post',
  894. data: {
  895. deviceCode: result,
  896. }
  897. }).then(res => {
  898. if (res.data.data == 0) {
  899. app.requestP({
  900. url: '/chainBound/bind',
  901. method: 'post',
  902. contentType: ' application/json',
  903. data: {
  904. chainId: details.chainId,
  905. deviceCode: result,
  906. type: devicetype.substr(5),
  907. lat: latitude,
  908. lng: longitude
  909. }
  910. }).then(response => {
  911. app.showToptip(that, 'success', '绑定成功!');
  912. that.getInfo(options);
  913. that.getBoundDevice(options);
  914. }).catch(error => {
  915. app.showToptip(that, 'error', error.data.msg)
  916. })
  917. } else {
  918. app.showToptip(that, 'error', res.data.msg)
  919. }
  920. }).catch(err => {
  921. app.showToptip(that, 'error', err.data.msg)
  922. })
  923. },
  924. inputBind() {
  925. var that = this
  926. wx.showModal({
  927. title: '请输入标签编号',
  928. editable: true,
  929. success(res) {
  930. if (res.confirm) {
  931. var numreg = /^[0-9]*$/;
  932. if (res.content) {
  933. // if (!numreg.test(res.content)) {
  934. // app.showToptip(that, "error", "标签编号只能为数字!");
  935. // that.inputBind()
  936. // return;
  937. // }
  938. that.setchainBoundBind(res.content)
  939. } else {
  940. app.showToptip(that, "error", '标签编号不能为空!')
  941. that.inputBind()
  942. }
  943. } else {
  944. //pass
  945. }
  946. }
  947. })
  948. },
  949. })