order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <template>
  2. <view class="order-home">
  3. <!-- <view class="time">
  4. {{minute? minute:time}}:{{second?second:00}}
  5. </view> -->
  6. <view class="status">
  7. <view class="left">
  8. <view class="text1">
  9. <text>{{orderDetails.work_type_text}}</text>
  10. </view>
  11. <view class="text2">
  12. 吸氢模式
  13. </view>
  14. </view>
  15. <view class="left">
  16. <view class="text1">
  17. {{minute>=10? minute:'0'+minute}}:{{second>=10?second:'0'+second}}
  18. </view>
  19. <view class="text2">
  20. 剩余时长
  21. </view>
  22. </view>
  23. </view>
  24. <view class="shebei">
  25. <view class="title">
  26. 机器状态(编码:{{no}})
  27. </view>
  28. <view class="item-border">
  29. <view class="item" style="border-left: solid 1upx #ececec;">
  30. <image src="../../static/image/water.png" mode=""></image>
  31. <view class="text">
  32. <view class="name">
  33. {{deviceDetail.water_level_warning_text ? deviceDetail.water_level_warning_text :'--'}}
  34. </view>
  35. </view>
  36. </view>
  37. <view class="item">
  38. <image src="../../static/image/wendu.png" mode=""></image>
  39. <view class="text">
  40. <view class="name">
  41. {{deviceDetail.temperature ? deviceDetail.temperature :'--'}}℃
  42. </view>
  43. </view>
  44. </view>
  45. <view class="item">
  46. <image src="../../static/image/shuizhi.png" mode=""></image>
  47. <view class="text">
  48. <view class="name">
  49. {{deviceDetail.water_quality ? deviceDetail.water_quality : '--'}}mg/L
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="submit1">
  56. <view class="suspend" @click="suspendOperation()" v-if="orderDetails.status!==4">
  57. 暂停吸氢
  58. </view>
  59. <view class="restart" @click="reStart()" v-else-if="orderDetails.status==4">
  60. 重新启动
  61. </view>
  62. <view class="stop" @click="stopOperation()">
  63. 结束订单
  64. </view>
  65. </view>
  66. <view class="refresh" @click="refresh()">
  67. <image src="../../static/image/ref.png" mode=""></image>
  68. <view class="ref-text">
  69. 点击刷新
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. var app = getApp()
  76. let counTDown
  77. export default {
  78. data() {
  79. return {
  80. deviceDetail: '',
  81. no: '',
  82. time: uni.getStorageSync('work_time'),
  83. order_no: '',
  84. minute: 0,
  85. second: 0,
  86. buttonStatus: 0,
  87. orderDetails: '',
  88. date6: '',
  89. work_time: '',
  90. }
  91. },
  92. onLoad(options) {
  93. //测试倒计
  94. console.log(options, 'ppppppppp')
  95. let that = this
  96. uni.showLoading()
  97. this.order_no = options.order_no
  98. // this.no = uni.getStorageSync('device_no')
  99. },
  100. onShow() {
  101. clearInterval(counTDown)
  102. this.orderDetail()
  103. },
  104. methods: {
  105. //点击刷新
  106. refresh:function(){
  107. clearInterval(counTDown)
  108. uni.showLoading({
  109. title:'刷新中'
  110. })
  111. this.orderDetail()
  112. },
  113. // 订单情况+根据定单编号查询
  114. orderDetail: function() {
  115. let data = {
  116. no: this.order_no
  117. }
  118. app.request('/orders', data, 'post').then(res => {
  119. console.log(res, '订单详情')
  120. let data = res.data.data.data
  121. this.orderDetails = data
  122. uni.hideLoading()
  123. let endTime = Date.parse(new Date()); //date日期类型
  124. let data1 = data.start_use_time
  125. let data2 = data1.replace(/-/g, '/')
  126. let data3 = new Date(data2)
  127. let startTime = data3.getTime()
  128. this.work_time = data.work_time
  129. this.countTime(startTime, endTime);
  130. let no = data.device.no
  131. this.no = data.device.no
  132. this.deviceMess(no)
  133. })
  134. },
  135. //设备信息
  136. deviceMess: function(no) {
  137. let params = {
  138. no: no
  139. }
  140. app.request('/device', params, 'get').then(res => {
  141. this.deviceDetail = res.data.data.data
  142. console.log(res, '--------------------------------------')
  143. uni.hideLoading()
  144. })
  145. },
  146. //倒计时
  147. countTime: function(startTime, endTime) {
  148. let that = this
  149. let date3 = endTime - startTime;
  150. //计算出相差天数
  151. var days = Math.floor(date3 / (24 * 3600 * 1000));
  152. //计算出小时数
  153. var leave1 = date3 % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
  154. var hours = Math.floor(leave1 / (3600 * 1000));
  155. //计算相差分钟数
  156. var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
  157. var minutes = Math.floor(leave2 / (60 * 1000));
  158. //计算相差秒数
  159. var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
  160. var seconds = Math.round(leave3 / 1000);
  161. let workTime = that.work_time
  162. that.minute = minutes
  163. that.second = seconds
  164. that.time = workTime * 60 - (hours * 3600 + minutes * 60 + seconds)
  165. counTDown = setInterval(function() {
  166. that.time = that.time - 1
  167. // that.minute = that.time;
  168. // that.second =that.time;
  169. that.minute = parseInt(that.time / 60);
  170. that.second = parseInt(that.time % 60);
  171. console.log(that.minute + ':' + that.second, '+++++++++++++++重启服务')
  172. if (that.minute == 0 && that.second == 0) {
  173. clearInterval(counTDown)
  174. uni.showModal({
  175. content: "本次吸氢服务已经结束",
  176. confirmText: "返回首页",
  177. success: (res) => {
  178. if (res.confirm) {
  179. uni.reLaunch({
  180. url: './index'
  181. })
  182. }
  183. }
  184. })
  185. } else if (that.second < 0) {
  186. clearInterval(counTDown)
  187. that.minute = "0"
  188. that.second = "0"
  189. uni.showModal({
  190. content: "本次吸氢服务已经结束",
  191. confirmText: "返回首页",
  192. success: (res) => {
  193. if (res.confirm) {
  194. uni.reLaunch({
  195. url: './index'
  196. })
  197. }
  198. }
  199. })
  200. }
  201. }, 1000)
  202. console.log(workTime, '++++++++++++暂停服务')
  203. console.log(this.time + this.minute + "分 " + this.second)
  204. console.log(days + "天 " + hours + "小时 " + minutes + "分钟" + seconds)
  205. },
  206. //暂停吸氢
  207. suspendOperation: function() {
  208. uni.showModal({
  209. content: "即将暂停服务,暂停之后仍持续计费,是否继续?",
  210. success: (res) => {
  211. if (res.confirm) {
  212. console.log(this.minute)
  213. let data = {
  214. order_no: this.order_no,
  215. device_no: this.no
  216. }
  217. app.request('/device/close', data, 'post').then(res => {
  218. if (res.statusCode == 200) {
  219. uni.showToast({
  220. title: '服务暂停',
  221. icon: 'none'
  222. })
  223. this.orderDetails.status = 4
  224. } else {
  225. uni.showToast({
  226. title: '暂停失败',
  227. icon: 'none'
  228. })
  229. }
  230. console.log(res, '=============================')
  231. })
  232. } else if (res.cancel) {
  233. }
  234. }
  235. })
  236. },
  237. //重新启动
  238. reStart: function() {
  239. let that = this
  240. uni.showModal({
  241. content: "即将重新启动机器吸氢",
  242. success: (res) => {
  243. if (res.confirm) {
  244. let data = {
  245. order_no: that.order_no
  246. }
  247. app.request('/device/start', data, 'post').then(res => {
  248. if (res.statusCode == 200) {
  249. // clearInterval(counTDown)
  250. uni.showToast({
  251. title: '重启成功'
  252. })
  253. this.orderDetails.status = 2
  254. // this.orderDetail()
  255. } else {
  256. console.log(res, '重启失败')
  257. uni.showToast({
  258. title: '设备重启失败,请联系门店管理员',
  259. icon: 'none'
  260. })
  261. }
  262. })
  263. } else if (res.cancel) {
  264. uni.showToast({
  265. title: '操作取消~',
  266. icon: 'none'
  267. })
  268. }
  269. }
  270. })
  271. },
  272. //关闭设备
  273. stopOperation: function() {
  274. let that = this
  275. console.log(that.order_no, 'order_no-------------------------')
  276. uni.showModal({
  277. title: '提示',
  278. content: '您即将结束本次吸氢服务,结束之后将无法继续,是否继续?',
  279. success: function(res) {
  280. if (res.confirm) {
  281. uni.showLoading()
  282. let params = {
  283. order_no: that.order_no, //订单编号
  284. device_no: that.no //设备编号
  285. }
  286. app.request('/order/close', params, 'post').then(res => {
  287. console.log(res)
  288. if (res.statusCode == 200) {
  289. clearInterval(counTDown)
  290. uni.hideLoading()
  291. uni.reLaunch({
  292. url: './index'
  293. })
  294. } else {
  295. uni.hideLoading()
  296. uni.showToast({
  297. title: res.data.message,
  298. icon: 'none'
  299. })
  300. }
  301. })
  302. } else if (res.cancel) {
  303. console.log('用户点击取消');
  304. }
  305. }
  306. })
  307. }
  308. }
  309. }
  310. </script>
  311. <style lang="scss" scoped>
  312. .order-home {
  313. height: 100vh;
  314. background-color: #FFFFFF;
  315. width: 100%;
  316. .time {
  317. width: 200upx;
  318. height: 200upx;
  319. background-color: #ff781e;
  320. border-radius: 50%;
  321. color: #FFFFFF;
  322. font-size: 26upx;
  323. padding: 30upx;
  324. }
  325. .status {
  326. display: flex;
  327. text-align: center;
  328. padding: 0 30upx;
  329. margin-top: 30upx;
  330. .left {
  331. flex: 1;
  332. margin: 30upx;
  333. padding: 20upx;
  334. box-shadow: 0upx 2upx 13upx 0upx rgba(150, 150, 150, 0.35);
  335. .text1 {
  336. font-size: 40upx;
  337. color: $mine-background-color;
  338. font-weight: bold;
  339. line-height: 70upx;
  340. // font-style: italic;
  341. .text3 {
  342. font-size: 26upx;
  343. font-weight: 500;
  344. margin-left: 5upx;
  345. }
  346. }
  347. .text2 {
  348. font-size: 26upx;
  349. line-height: 50upx;
  350. color: #808080;
  351. }
  352. }
  353. }
  354. .shebei {
  355. padding: 0 50upx;
  356. margin-top: 60upx;
  357. .title {
  358. height: 50upx;
  359. line-height: 50upx;
  360. font-size: 26upx;
  361. font-weight: 500;
  362. border-left: solid 6upx $mine-background-color;
  363. padding-left: 15upx;
  364. margin-bottom: 10upx;
  365. // border-bottom: solid 1upx #e3e3e3;
  366. }
  367. .item-border {
  368. display: flex;
  369. .item {
  370. margin-top: 30upx;
  371. padding: 30upx 0;
  372. flex: 1;
  373. text-align: center;
  374. border-right: solid 1upx #ececec;
  375. border-top: solid 1upx #ececec;
  376. border-bottom: solid 1upx #ececec;
  377. image {
  378. flex: 0 0 50upx;
  379. height: 50upx;
  380. width: 50upx;
  381. }
  382. .text {
  383. margin-top: 20upx;
  384. }
  385. .name {
  386. font-size: 26upx;
  387. color: #808080;
  388. }
  389. }
  390. }
  391. }
  392. .submit1 {
  393. display: flex;
  394. margin-top: 100upx;
  395. .suspend {
  396. flex: 1;
  397. height: 70upx;
  398. line-height: 70upx;
  399. text-align: center;
  400. color: #FFFFFF;
  401. background-color: #f98975;
  402. font-size: 26upx;
  403. width: 30%;
  404. margin: 50upx 5% 50upx 15%;
  405. border-radius: 18upx;
  406. }
  407. .stop {
  408. width: 30%;
  409. margin: 50upx 15% 50upx 5%;
  410. flex: 1;
  411. height: 70upx;
  412. line-height: 70upx;
  413. text-align: center;
  414. color: #FFFFFF;
  415. background-color: $mine-background-color;
  416. font-size: 26upx;
  417. border-radius: 18upx;
  418. // width: 50%;
  419. // margin: 0 auto;
  420. // margin-top: 30%;
  421. }
  422. .restart {
  423. flex: 1;
  424. height: 70upx;
  425. line-height: 70upx;
  426. text-align: center;
  427. color: #FFFFFF;
  428. background-color: #40dc69;
  429. font-size: 26upx;
  430. width: 30%;
  431. margin: 50upx 5% 50upx 15%;
  432. border-radius: 18upx;
  433. }
  434. }
  435. .refresh {
  436. position: fixed;
  437. right: 0;
  438. bottom:15%;
  439. background-color: $mine-background-color;
  440. padding: 10upx 20upx;
  441. border-radius: 50upx 0 0 50upx;
  442. image{
  443. display: inline-block;
  444. vertical-align: middle;
  445. height: 50upx;
  446. width: 50upx;
  447. margin-right: 10upx;
  448. }
  449. .ref-text{
  450. display: inline-block;
  451. vertical-align: middle;
  452. line-height: 70upx;
  453. font-size: 30upx;
  454. color: #FFFFFF;
  455. }
  456. }
  457. }
  458. </style>