index.vue 8.6 KB

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