humiture.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <!-- 温湿度 -->
  3. <view>
  4. <u-navbar title="温湿度记录" autoBack placeholder></u-navbar>
  5. <view class="card_qiucharts" v-if="userType == 'customer'">
  6. <view class="card_echart">
  7. <qiun-data-charts type="gauge" :opts="opts" :chartData="chartData" />
  8. </view>
  9. <view class="card_echart">
  10. <qiun-data-charts type="gauge" :opts="opts1" :chartData="chartData1" />
  11. </view>
  12. </view>
  13. <view v-else>
  14. <view v-if="humitureList.length > 0">
  15. <view class="card_particulars" v-for="(item,index) in humitureList" :key="index">
  16. <view class="card_describe">
  17. <view @click="selectChangeil(item)">
  18. <x-checkbox :label="item.title" :isChecked="item.isChecked"></x-checkbox>
  19. </view>
  20. <!-- <view class="describe_title">{{item.title}}</view> -->
  21. <!-- <view class="describe_time">{{item.startTime}}</view>
  22. <view class="describe_time">{{item.endTime}}</view> -->
  23. </view>
  24. <view class="dateTime_card" style="margin: 20rpx 10rpx;">
  25. <uni-datetime-picker v-model="item.datetimeRange" type="datetimerange"
  26. @change="changeDatetime($event,item)" />
  27. </view>
  28. <view class="humiture_details" @click="foldingPanel(item)">
  29. <view class="title_details">温湿度</view>
  30. <view style="display: flex;">
  31. <view class="title_blue title_details">查看详情</view>
  32. <u-icon name="arrow-down"></u-icon>
  33. </view>
  34. </view>
  35. <view v-show="item.collapseil">
  36. <x-humiture ref="humiture" :startTime="item.datetimeRange[0]" :endTime="item.datetimeRange[1]"
  37. :taskId="item.id" :waybillNo="waybillNo" :current="item.presentNum"
  38. :probeList="item.deviceSensorList"></x-humiture>
  39. </view>
  40. </view>
  41. </view>
  42. <view style="margin-top: 30%;" v-else>
  43. <u-empty mode="data" text="当前没有温湿度记录"></u-empty>
  44. </view>
  45. </view>
  46. <view style="width: 100%;height: 230rpx;"></view>
  47. <view class="card_btn"
  48. v-if="humitureList.length > 0 && waybillData.status != 1 || waybillData.status != 2 || waybillData.status != 3 || waybillData.status != 9">
  49. <u-button style="margin-bottom: 20rpx;" type="primary"
  50. @click="humidityRecording('send')">发送温湿度记录PDF</u-button>
  51. <u-button style="margin-bottom: 20rpx;" type="success"
  52. @click="humidityRecording('print')">打印温湿度记录</u-button>
  53. </view>
  54. <u-modal :show="show" confirmText="停止" showCancelButton :buttonReverse="true" @cancel="cancel"
  55. @confirm="confirm">
  56. <view class="slot-content">
  57. <view>{{stoprecording}}</view>
  58. </view>
  59. </u-modal>
  60. <u-popup :show="shareShow" mode="center" round="5" closeable @close="shareShow = false">
  61. <view style="padding: 0rpx 30rpx 30rpx 30rpx;margin-top: 50rpx; width: 400rpx;">
  62. <u-button style="margin: 20rpx 0rpx;" type="success" text="发送邮箱" @click="sendingMailbox"></u-button>
  63. <u-button type="primary" text="分享微信好友" @click="shareWechatFriends"></u-button>
  64. </view>
  65. </u-popup>
  66. <u-popup :show="emailShow" mode="center" round="5" closeable @close="emailShow = false">
  67. <view style="padding: 30rpx;">
  68. <view style="margin-top: 20rpx;width: 600rpx;">
  69. <view class="email_title" style="margin-bottom: 10rpx;">运单号:{{waybillNo}}</view>
  70. <view class="card_email">
  71. <span class="email_title">邮箱地址:</span>
  72. <view style="margin-top: 20rpx;">
  73. <u--input v-model="email" placeholder="请输入邮箱" border="surround"></u--input>
  74. </view>
  75. </view>
  76. </view>
  77. <view style="margin-top: 20rpx;">
  78. <u-button type="primary" :loading="sendLoading" text="发送" @click="confirmSend"></u-button>
  79. </view>
  80. </view>
  81. </u-popup>
  82. </view>
  83. </template>
  84. <script>
  85. const FileShare = uni.requireNativePlugin('life-FileShare');
  86. export default {
  87. data() {
  88. return {
  89. show: false,
  90. orderList: {},
  91. humitureList: [],
  92. userType: '',
  93. myChart: null,
  94. chartData: {},
  95. chartData1: {},
  96. opts: {
  97. color: ["#3592FE"],
  98. padding: undefined,
  99. title: {
  100. // name: "66℃",
  101. fontSize: 25,
  102. color: "#3592FE",
  103. offsetY: 0
  104. },
  105. subtitle: {
  106. name: "当前温度",
  107. fontSize: 15,
  108. color: "#1890ff",
  109. offsetY: 0
  110. },
  111. extra: {
  112. gauge: {
  113. type: "progress",
  114. width: 20,
  115. labelColor: "#666666",
  116. startAngle: 0.75,
  117. endAngle: 0.25,
  118. // startNumber: 5,
  119. // endNumber: 35,
  120. labelFormat: "",
  121. splitLine: {
  122. fixRadius: -10,
  123. splitNumber: 10,
  124. width: 15,
  125. color: "#FFFFFF",
  126. childNumber: 5,
  127. childWidth: 12
  128. },
  129. pointer: {
  130. width: 24,
  131. color: "auto"
  132. }
  133. }
  134. },
  135. },
  136. opts1: {
  137. color: ["#67C23A"],
  138. padding: 20,
  139. title: {
  140. // name: "66℃",
  141. fontSize: 25,
  142. color: "#2fc25b",
  143. offsetY: 0
  144. },
  145. subtitle: {
  146. name: "当前湿度",
  147. fontSize: 15,
  148. color: "#67C23A",
  149. offsetY: 0
  150. },
  151. extra: {
  152. gauge: {
  153. type: "progress",
  154. width: 20,
  155. labelColor: "#000000",
  156. startAngle: 0.75,
  157. endAngle: 0.25,
  158. // startNumber: 0,
  159. // endNumber: 100,
  160. labelFormat: "",
  161. splitLine: {
  162. fixRadius: -10,
  163. splitNumber: 10,
  164. width: 15,
  165. color: "#67C23A",
  166. childNumber: 5,
  167. childWidth: 12
  168. },
  169. labelOffset: 20,
  170. pointer: {
  171. width: 24,
  172. color: "auto"
  173. }
  174. }
  175. },
  176. },
  177. datetimeRange: [],
  178. waybillNo: '',
  179. waybillData: [],
  180. shareShow: false,
  181. stoprecording: '打印前需停止记录,是否继续?',
  182. humitureType: '',
  183. checkboxValue: [],
  184. emailShow: false,
  185. email: '',
  186. sendLoading: false,
  187. humidityFlag: false,
  188. }
  189. },
  190. onLoad(option) {
  191. this.waybillNo = option.waybillNo
  192. // 获取运单详情
  193. this.waybillDetails(option.waybillNo)
  194. },
  195. mounted() {
  196. var userInfo = this.$cache.getCache('userInfo')
  197. this.userType = userInfo.userType
  198. var orderList = this.$cache.getCache('orderDetails')
  199. this.orderList = orderList
  200. if (this.userType == 'customer') {
  201. this.getServerData();
  202. } else {
  203. this.getList()
  204. }
  205. },
  206. methods: {
  207. getList() {
  208. this.$api.get('/api/waybill-task', {
  209. waybillNo: this.waybillNo,
  210. }).then(res => {
  211. if (res.code == 200) {
  212. this.humitureList = JSON.parse(JSON.stringify(res.data.list))
  213. this.humitureList.forEach((item, index) => {
  214. this.checkboxValue.push(item.id)
  215. item.isChecked = true
  216. item.title = ''
  217. item.collapseil = false
  218. item.datetimeRange = []
  219. item.datetimeRange.push(item.startTime)
  220. if (item.endTime) {
  221. item.datetimeRange.push(item.endTime)
  222. } else {
  223. item.datetimeRange.push(this.getDateTime(new Date()))
  224. }
  225. if (item.car.id) {
  226. item.title = item.car.carNo
  227. } else if (item.warehouse.id) {
  228. item.title = item.warehouse.name
  229. } else if (item.coolerBox.id) {
  230. item.title = item.coolerBox.name
  231. }
  232. })
  233. }
  234. })
  235. },
  236. // 获取运单详情
  237. waybillDetails(waybillNo) {
  238. this.$api.get('/api/waybill/' + waybillNo).then(res => {
  239. if (res.code == 200) {
  240. this.waybillData = res.data
  241. }
  242. })
  243. },
  244. // 发送邮箱
  245. sendingMailbox() {
  246. this.shareShow = false
  247. this.emailShow = true
  248. },
  249. // 分享微信好友
  250. shareWechatFriends() {
  251. uni.showLoading({
  252. title: '获取温湿度记录中,请稍等',
  253. mask: true,
  254. });
  255. this.$api.post('/api/waybill/temperature-pdf-url', {
  256. waybillNo: this.waybillNo,
  257. waybillTaskIds: this.checkboxValue,
  258. }).then(res => {
  259. if (res.code == 200) {
  260. let arrData = res.data.split("/");
  261. var dtask = plus.downloader.createDownload(res.data, {
  262. filename: "_doc/pdf/" + arrData[3]
  263. }, function(d, status) {
  264. // 下载完成
  265. if (status == 200) {
  266. FileShare.render({
  267. type: "WX", //QQ为QQ,微信为WX,系统默认是SYSTEM,不填写默认SYSTEM
  268. filePath: plus.io.convertLocalFileSystemURL(d.filename),
  269. }, result => {
  270. uni.hideLoading()
  271. });
  272. } else {
  273. console.log("Download failed: " + status);
  274. }
  275. });
  276. dtask.start();
  277. }
  278. uni.hideLoading()
  279. }).catch(() => {
  280. uni.hideLoading()
  281. })
  282. return
  283. },
  284. // 发送邮箱
  285. confirmSend() {
  286. if (this.email) {
  287. let flag = validateEmail(this.email)
  288. if (flag) {
  289. if (!this.sendLoading) {
  290. this.sendLoading = true
  291. let arrTo = []
  292. arrTo.push(this.email)
  293. this.$api.post('/api/waybill/send-mail', {
  294. waybillNo: this.waybillNo,
  295. humidityShow: this.humidityFlag,
  296. to: arrTo,
  297. waybillTaskIds: this.checkboxValue,
  298. }).then(res => {
  299. if (res.code == 200) {
  300. uni.$u.toast(res.msg)
  301. this.email = ''
  302. this.emailShow = false
  303. }
  304. this.sendLoading = false
  305. }).catch(() => {
  306. this.sendLoading = false
  307. })
  308. }
  309. } else {
  310. uni.$u.toast('邮箱格式错误')
  311. }
  312. } else {
  313. uni.$u.toast('请输入邮箱')
  314. }
  315. // 如果邮箱格式正确,输出 true,否则输出 false
  316. function validateEmail(email) {
  317. const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
  318. return emailRegex.test(email);
  319. }
  320. },
  321. // 打印温湿度记录
  322. humidityRecording(type) {
  323. this.humitureType = type
  324. if ([4, 5, 10].includes(this.waybillData.status)) {
  325. if (type == 'send') {
  326. this.stoprecording = '发送温湿度记录前需停止记录,是否继续?'
  327. } else {
  328. this.stoprecording = '打印前需停止记录,是否继续?'
  329. }
  330. this.show = true
  331. } else {
  332. if (type == 'send') {
  333. this.shareShow = true
  334. } else {
  335. if (this.waybillData.id) {
  336. this.$cache.setCache('commodity', JSON.stringify(this.waybillData))
  337. uni.navigateTo({
  338. url: '/pages/order/quantum?waybillNo=' + this.waybillData.waybillNo +
  339. '&printType=record'
  340. });
  341. } else {
  342. uni.$u.toast('暂无运单详情数据,无法打印!')
  343. }
  344. }
  345. }
  346. },
  347. cancel() {
  348. this.show = false
  349. },
  350. confirm() {
  351. this.$api.post('/api/waybill/stop-record', {
  352. waybillNo: this.waybillData.waybillNo,
  353. startTime: this.getDateTime(new Date()),
  354. }).then(res => {
  355. if (res.code == 200) {
  356. if (this.humitureType == 'send') {
  357. this.show = false
  358. this.shareShow = true
  359. } else {
  360. if (this.waybillData.id) {
  361. this.$cache.setCache('commodity', JSON.stringify(this.waybillData))
  362. uni.navigateTo({
  363. url: '/pages/order/quantum?waybillNo=' + this.waybillData.waybillNo +
  364. '&printType=record'
  365. });
  366. } else {
  367. uni.$u.toast('暂无运单详情数据,无法打印!')
  368. }
  369. }
  370. }
  371. this.show = false
  372. }).catch(() => {
  373. this.show = false
  374. })
  375. },
  376. // 折叠面板
  377. foldingPanel(value) {
  378. this.humitureList.forEach((item, index) => {
  379. if (item.id == value.id) {
  380. if (item.collapseil) {
  381. item.collapseil = false
  382. } else {
  383. this.$refs.humiture[index].getlistil(item.deviceSensorList[0].T_id)
  384. item.collapseil = true
  385. }
  386. }
  387. })
  388. this.$forceUpdate()
  389. },
  390. change(e) {
  391. if (e[0].status == 'open') {
  392. this.humitureList.forEach((item, index) => {
  393. this.$refs.humiture[index].getlistil(item.deviceSensorList[0].T_id)
  394. })
  395. }
  396. },
  397. getServerData() {
  398. this.$api.post('/api/waybill-task/newest-locus', {
  399. waybillNo: this.waybillNo,
  400. }).then((res) => {
  401. if (res.code == 200) {
  402. this.opts.title.name = res.data.T_t + '℃'
  403. this.opts.extra.gauge.startNumber = res.data.T_tl
  404. this.opts.extra.gauge.endNumber = res.data.T_tu
  405. this.opts1.title.name = res.data.T_rh + '℃'
  406. this.opts1.extra.gauge.startNumber = res.data.T_rhl
  407. this.opts1.extra.gauge.endNumber = res.data.T_rhu
  408. let arr = (res.data.T_t - res.data.T_tl) / (res.data.T_tu - res.data.T_tl)
  409. let arr1 = (res.data.T_rh - res.data.T_rhl) / (res.data.T_rhu - res.data.T_rhl)
  410. let value = {
  411. categories: [{
  412. "value": 0.2,
  413. "color": "#1890ff"
  414. }, {
  415. "value": 0.8,
  416. "color": "#2fc25b"
  417. }, {
  418. "value": 1,
  419. "color": "#f04864"
  420. }],
  421. series: [{
  422. data: arr.toFixed(1)
  423. }]
  424. };
  425. let value1 = {
  426. categories: [{
  427. "value": 0.2,
  428. "color": "#1890ff"
  429. }, {
  430. "value": 0.8,
  431. "color": "#2fc25b"
  432. }, {
  433. "value": 1,
  434. "color": "#f04864"
  435. }],
  436. series: [{
  437. data: arr1.toFixed(1)
  438. }]
  439. };
  440. this.chartData = JSON.parse(JSON.stringify(value));
  441. this.chartData1 = JSON.parse(JSON.stringify(value1));
  442. }
  443. })
  444. },
  445. // 选择某段温湿度数据
  446. selectChangeil(value) {
  447. this.humitureList.forEach((item, index) => {
  448. if (value.id == item.id) {
  449. if (value.isChecked) {
  450. item.isChecked = false
  451. } else {
  452. item.isChecked = true
  453. }
  454. }
  455. })
  456. this.selectChange(value.id)
  457. this.$forceUpdate()
  458. },
  459. // 选择打印
  460. selectChange(stingId) {
  461. const result = this.checkboxValue
  462. const index = result.indexOf(stingId)
  463. if (index > -1) {
  464. result.splice(index, 1)
  465. } else {
  466. result.push(stingId)
  467. }
  468. this.checkboxValue = result
  469. },
  470. // 时间范围选择
  471. changeDatetime(value, item) {
  472. this.humitureList.forEach((item1, index) => {
  473. if (item1.id == item.id) {
  474. setTimeout(() => {
  475. item.datetimeRange = value
  476. // this.getDatas()
  477. this.$refs.humiture[index].getlistil(item.deviceSensorList[0].T_id)
  478. }, 500)
  479. }
  480. })
  481. this.$forceUpdate()
  482. },
  483. getDateTime(date, addZero = true) {
  484. return `${this.getDate(date, addZero)} ${this.getTime(date, addZero)}`
  485. },
  486. getDate(date, addZero = true) {
  487. date = new Date(date)
  488. const year = date.getFullYear()
  489. const month = date.getMonth() + 1
  490. const day = date.getDate()
  491. return `${year}-${addZero ? this.addZero(month) : month}-${addZero ? this.addZero(day) : day}`
  492. },
  493. getTime(date, addZero = true) {
  494. date = new Date(date)
  495. const hour = date.getHours()
  496. const minute = date.getMinutes()
  497. const second = date.getSeconds()
  498. return this.hideSecond ?
  499. `${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}` :
  500. `${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}:${addZero ? this.addZero(second) : second}`
  501. },
  502. addZero(num) {
  503. if (num < 10) {
  504. num = `0${num}`
  505. }
  506. return num
  507. }
  508. }
  509. }
  510. </script>
  511. <style lang="scss">
  512. .card_particulars {
  513. display: flex;
  514. flex-direction: column;
  515. padding-top: 20rpx;
  516. margin: 30rpx 20rpx 20rpx 20rpx;
  517. border-radius: 20rpx;
  518. background-color: #fff;
  519. }
  520. .card_describe {
  521. padding-left: 20rpx;
  522. padding-bottom: 20rpx;
  523. border-bottom: 1rpx solid #EBEEF5;
  524. }
  525. .describe_title {
  526. font-size: 30rpx;
  527. font-weight: 600;
  528. }
  529. .describe_time {
  530. font-size: 28rpx;
  531. }
  532. .humiture_details {
  533. display: flex;
  534. justify-content: space-between;
  535. align-items: center;
  536. padding: 20rpx;
  537. }
  538. .title_blue {
  539. color: #2979ff;
  540. margin-right: 10rpx;
  541. }
  542. .title_details {
  543. font-size: 28rpx;
  544. }
  545. ::v-deep .u-collapse-item__content__text {
  546. padding: 0rpx 0rpx 30rpx 0rpx;
  547. }
  548. ::v-deep .u-line {
  549. display: none;
  550. }
  551. .card_qiucharts {
  552. display: flex;
  553. align-items: center;
  554. flex-direction: column;
  555. }
  556. .card_echart {
  557. width: 80%;
  558. height: 500rpx;
  559. }
  560. .card_echart {
  561. width: 80%;
  562. height: 500rpx;
  563. }
  564. .dateTime_card ::v-deep .icon-calendar {
  565. display: none;
  566. }
  567. .card_btn {
  568. position: fixed;
  569. left: 0;
  570. right: 0;
  571. bottom: 0;
  572. padding-left: 30rpx;
  573. padding-right: 30rpx;
  574. padding-top: 20rpx;
  575. background-color: #fff;
  576. padding-bottom: constant(safe-area-inset-bottom); //兼容 IOS<11.2
  577. padding-bottom: env(safe-area-inset-bottom); //兼容 IOS>11.2
  578. }
  579. </style>