orderDetails.js 23 KB

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