index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <!--
  2. * @Author: liuzhenlin 461480418@qq.ocm
  3. * @Date: 2023-01-12 11:57:48
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-09-22 14:38:38
  6. * @Description: file content
  7. * @FilePath: \labsop小程序\pages\schedule\myAppoint\index.vue
  8. -->
  9. <template>
  10. <div class="panel-wrap">
  11. <van-empty v-if="appointList.length == 0" mode="list" description="暂无正在上机"></van-empty>
  12. <van-list v-else v-model:loading="listloading" class="data-list" :finished="finished" finished-text="没有更多了" @load="onLoad">
  13. <div class="inst-item mb40" v-for="(v, index) in appointList" :key="index" @click="toDetail(v)">
  14. <div class="flex flex-between mb20">
  15. <div>
  16. <div class="mr10">
  17. <span class="fontSize14 primary-color bold">{{ v.instName }}</span>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="flex mb20">
  22. <div class="equ-tit">
  23. <span class="fontSize14 bold">设备型号:</span>
  24. </div>
  25. <div>
  26. <span class="fontSize14">{{ v.instNameEn }}</span>
  27. </div>
  28. </div>
  29. <div class="flex mb20" v-if="v.projectName">
  30. <div class="equ-tit">
  31. <span class="fontSize14 bold">课题组:</span>
  32. </div>
  33. <div>
  34. <span class="fontSize14">{{ v.projectName }}</span>
  35. </div>
  36. </div>
  37. <div class="flex mb20" v-if="v.serviceName">
  38. <div class="equ-tit">
  39. <span class="fontSize14 bold">服务:</span>
  40. </div>
  41. <div>
  42. <span class="fontSize14">{{ v.serviceName }}</span>
  43. </div>
  44. </div>
  45. <div class="flex mb20">
  46. <div class="equ-tit">
  47. <span class="fontSize14 bold">所在位置:</span>
  48. </div>
  49. <div>
  50. <span class="fontSize14">{{ v.placeAddress + '(' + (v.laboratoryName || '') + ')' }}</span>
  51. </div>
  52. </div>
  53. <div class="flex">
  54. <div class="equ-tit">
  55. <span class="fontSize14 bold">开始时间:</span>
  56. </div>
  57. <div>
  58. <span class="fontSize14">{{ v.startTime }}</span>
  59. </div>
  60. </div>
  61. <div class="flex mt20">
  62. <van-button
  63. style="width: 70px; height: 30px; margin: 0; font-size: 14px"
  64. class="scan-txt"
  65. type="danger"
  66. size="small"
  67. @click.native.stop="handleIsGetOff(v)"
  68. >
  69. 下机
  70. </van-button>
  71. </div>
  72. </div>
  73. </van-list>
  74. <!-- <blue-tooth ref="bluetoothRef" @getOff="callbackOff"></blue-tooth> -->
  75. </div>
  76. </template>
  77. <script>
  78. // import BlueTooth from '../../../components/BlueTooth'
  79. import { useMyAppointApi } from '/@/api/appoint'
  80. const myAppointApi = useMyAppointApi()
  81. import { useInstrApi } from '/@/api/instr'
  82. const instApi = useInstrApi()
  83. import instAppointApi from '/@/api/instr/instAppoint'
  84. import to from 'await-to-js'
  85. import { showConfirmDialog, showNotify } from 'vant'
  86. export default {
  87. // components: { BlueTooth },
  88. data() {
  89. return {
  90. appointList: [],
  91. queryForm: {
  92. pageNum: 1,
  93. pageSize: 10
  94. },
  95. curAppointInfo: 0,
  96. total: 0,
  97. listloading: false,
  98. finished: false
  99. }
  100. },
  101. created() {},
  102. mounted() {
  103. this.queryForm.pageNum = 1
  104. this.getInstList()
  105. },
  106. methods: {
  107. // 重新加载
  108. onLoad() {
  109. this.queryForm.pageNum++
  110. this.getInstList()
  111. },
  112. // 查询列表
  113. async getInstList() {
  114. this.listloading = true
  115. const [err, res] = await to(myAppointApi.inProgressList(this.queryForm))
  116. this.listloading = false
  117. if (err) return
  118. if (res?.code === 200) {
  119. this.appointList = this.queryForm.pageNum == 1 ? [...(res?.data?.list || [])] : [...this.appointList, ...(res?.data?.list || [])]
  120. this.total = res?.data?.total
  121. if (this.queryForm.pageNum * this.queryForm.pageSize >= res.data.total) {
  122. this.finished = true
  123. }
  124. }
  125. },
  126. async handleIsGetOff(row) {
  127. const [err, res] = await to(instApi.getSettingDetail({ instId: row.instId, code: 'InstCfgUse' }))
  128. if (err) return
  129. // 上机时间
  130. const useTime = this.calcTimeDiff(row.usedStartTime)
  131. // 是否进行上机时间太短的提示
  132. // 需要
  133. if (res?.data?.config.shortWarningEnable) {
  134. const shortWraningTime = this.getShortWraningTime(res?.data?.config.shortWarning, res?.data?.config.shortWarningUnit)
  135. if (useTime > shortWraningTime) {
  136. if (row.controlMode === '30') {
  137. this.$refs.bluetoothRef.initBlue('close', row)
  138. } else {
  139. this.curAppointInfo = row
  140. showConfirmDialog({
  141. title: '提示',
  142. message: `本次上机时长共计${useTime}分钟,确定要下机吗?`
  143. })
  144. .then((e) => {
  145. console.log(e)
  146. this.getOff()
  147. })
  148. .catch(() => {
  149. console.log('ssss')
  150. })
  151. }
  152. } else {
  153. if (row.controlMode === '30') {
  154. this.$refs.bluetoothRef.initBlue('close', row)
  155. } else {
  156. this.curAppointInfo = row
  157. showConfirmDialog({
  158. title: '提示',
  159. message: `本次上机时长共计${useTime}分钟,不足${shortWraningTime}分钟,确定要下机吗?`
  160. })
  161. .then((e) => {
  162. console.log(e)
  163. this.getOff()
  164. })
  165. .catch(() => {
  166. console.log('ssss')
  167. })
  168. }
  169. }
  170. } else {
  171. if (row.controlMode === '30') {
  172. this.$refs.bluetoothRef.initBlue('close', row)
  173. } else {
  174. this.curAppointInfo = row
  175. showConfirmDialog({
  176. title: '提示',
  177. message: `本次上机时长共计${useTime}分钟,确定要下机吗?`
  178. })
  179. .then((e) => {
  180. console.log(e)
  181. this.getOff()
  182. })
  183. .catch(() => {
  184. console.log('ssss')
  185. })
  186. }
  187. }
  188. },
  189. // 计算时间转分钟
  190. getShortWraningTime(time, unit) {
  191. if (unit == 'hour') {
  192. return time * 60
  193. } else if (unit == 'minute') {
  194. return time
  195. }
  196. },
  197. calcTimeDiff(date) {
  198. var new_date = new Date() //新建一个日期对象,默认现在的时间
  199. var old_date = new Date(date) //设置过去的一个时间点,"yyyy-MM-dd HH:mm:ss"格式化日期
  200. var difftime = new_date - old_date //计算时间差
  201. return Math.round(difftime / 60000)
  202. },
  203. async getOff() {
  204. const params = { appointId: this.curAppointInfo.id }
  205. const [err, res] = await to(instAppointApi.getOff({ ...params }))
  206. if (err) return
  207. if (res.code == 200) {
  208. this.queryForm.pageNum = 1
  209. this.getInstList()
  210. showNotify({ type: 'success', message: '下机成功' })
  211. }
  212. },
  213. callbackOff() {
  214. this.queryForm.pageNum = 1
  215. this.getInstList()
  216. },
  217. toDetail(v) {
  218. this.$router.push(`/onlineInfo?appointId=${v.id}`)
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. * {
  225. box-sizing: border-box;
  226. }
  227. .panel-wrap {
  228. height: 100%;
  229. .data-list {
  230. height: 100%;
  231. padding: 20px;
  232. overflow: auto;
  233. .inst-item {
  234. border-radius: 10px;
  235. padding: 15px;
  236. box-shadow: -2px 0px 9px rgba(0, 0, 0, 0.12);
  237. margin-bottom: 20px;
  238. .equ-tit {
  239. width: 74px;
  240. }
  241. }
  242. }
  243. }
  244. </style>