index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <!--
  2. * @Author: liuzhenlin 461480418@qq.ocm
  3. * @Date: 2023-01-12 11:57:48
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-09-26 18:13:20
  6. * @Description: file content
  7. * @FilePath: \labsop小程序\pages\appointList\soonGeton\index.vue
  8. -->
  9. <template>
  10. <div class="panel-wrap">
  11. <!-- <van-pull-refresh v-model="refreshing" @refresh="onRefresh"> -->
  12. <van-empty v-if="appointList.length == 0" mode="list" description="暂无即将上机"></van-empty>
  13. <van-list v-else v-model:loading="listloading" class="data-list" :finished="finished" finished-text="没有更多了"
  14. @load="onLoad">
  15. <div class="inst-item mb40" v-for="(v, index) in appointList" :key="index">
  16. <div class="flex flex-between mb20">
  17. <div>
  18. <div class="mr10">
  19. <span class="primary-color bold fontSize14">{{ v.instName }}</span>
  20. </div>
  21. </div>
  22. <div class="flex">
  23. <van-button style="width: 80px; height: 30px; margin: 0; font-size: 14px" class="scan-txt" type="primary"
  24. size="small" :disabled="loading" v-if="['10', '20', '30', '50', '60', '70'].includes(v.controlMode)"
  25. @click="handleGetOn(v)">
  26. {{ v.controlMode == '10' ? '上机' : '扫码上机' }}
  27. </van-button>
  28. <van-button style="width: 60px; height: 30px; margin: 0 0 0 10px; font-size: 14px" class="scan-txt"
  29. type="warning" size="small" :disabled="loading" @click="handleCancelAppoint(v)">
  30. 取消
  31. </van-button>
  32. </div>
  33. </div>
  34. <div class="flex mb20">
  35. <div class="equ-tit">
  36. <span class="fontSize14 bold">设备型号:</span>
  37. </div>
  38. <div>
  39. <span class="fontSize14">{{ v.instNameEn }}</span>
  40. </div>
  41. </div>
  42. <div class="flex mb20" v-if="v.projectName">
  43. <div class="equ-tit">
  44. <span class="fontSize14 bold">课题组:</span>
  45. </div>
  46. <div>
  47. <span class="fontSize14">{{ v.projectName }}</span>
  48. </div>
  49. </div>
  50. <div class="flex mb20" v-if="v.serviceName">
  51. <div class="equ-tit">
  52. <span class="fontSize14 bold">服务:</span>
  53. </div>
  54. <div>
  55. <span class="fontSize14">{{ v.serviceName }}</span>
  56. </div>
  57. </div>
  58. <div class="flex mb20">
  59. <div class="equ-tit">
  60. <span class="fontSize14 bold">所在位置:</span>
  61. </div>
  62. <div>
  63. <span class="fontSize14">{{ v.placeAddress + '(' + (v.laboratoryName || '') + ')' }}</span>
  64. </div>
  65. </div>
  66. <div class="flex">
  67. <div class="equ-tit">
  68. <span class="fontSize14 bold">开始时间:</span>
  69. </div>
  70. <div>
  71. <span class="fontSize14">
  72. {{ v.startTime }}
  73. <!-- {{ v.startTime ? formatDates(new Date(v.startTime), 'YYYY-mm-dd HH:MM') : '' }} -->
  74. </span>
  75. </div>
  76. </div>
  77. </div>
  78. </van-list>
  79. <!-- </van-pull-refresh> -->
  80. <!-- <blue-tooth ref="bluetoothRef"></blue-tooth> -->
  81. </div>
  82. </template>
  83. <script>
  84. // import BlueTooth from '../../../components/BlueTooth'
  85. // import { formatDate } from '/@/utils/formatTime'
  86. import { useUserInfo } from '/@/stores/userInfo'
  87. import { useMyAppointApi } from '/@/api/appoint'
  88. const myAppointApi = useMyAppointApi()
  89. import { useInstrApi } from '/@/api/instr'
  90. const instApi = useInstrApi()
  91. import instAppointApi from '/@/api/instr/instAppoint'
  92. import to from 'await-to-js'
  93. import { showConfirmDialog, showNotify } from 'vant'
  94. import { scanCodeWxUrl } from '/@/constants/pageConstants'
  95. export default {
  96. // components: { BlueTooth },
  97. data() {
  98. return {
  99. loading: false,
  100. curAppointInfo: {},
  101. appointList: [],
  102. queryForm: {
  103. pageNum: 1,
  104. pageSize: 10
  105. },
  106. total: 0,
  107. listloading: false,
  108. finished: false
  109. }
  110. },
  111. mounted() {
  112. this.queryForm.pageNum = 1
  113. this.getInstList()
  114. window.addEventListener('pageshow', this.onPageShow)
  115. },
  116. beforeUnmount() {
  117. window.removeEventListener('pageshow', this.onPageShow)
  118. },
  119. methods: {
  120. onPageShow(e) {
  121. this.loading = false
  122. },
  123. // 重新加载
  124. onLoad() {
  125. this.queryForm.pageNum++
  126. this.getInstList()
  127. },
  128. // 查询列表
  129. async getInstList(isRefresh = false) {
  130. if (!isRefresh) {
  131. this.listloading = true
  132. }
  133. const [err, res] = await to(myAppointApi.toGetonList(this.queryForm))
  134. this.listloading = false
  135. if (err) return
  136. if (res?.code === 200) {
  137. this.appointList = this.queryForm.pageNum == 1 ? [...(res?.data?.list || [])] : [...this.appointList, ...(res?.data?.list || [])]
  138. this.total = res?.data?.total
  139. if (this.queryForm.pageNum * this.queryForm.pageSize >= res.data.total) {
  140. this.finished = true
  141. }
  142. }
  143. },
  144. /**
  145. * 触发上机之前的订阅
  146. *
  147. * */
  148. handleGetOn(row) {
  149. this.handleScanCode(row)
  150. },
  151. /**
  152. * 调起二维码扫码
  153. * controlMode (10 不控制 20 电源控制(wifi) 30 电源控制(蓝牙) 50 电脑控制 60 蓝牙V2)
  154. */
  155. async handleScanCode(row) {
  156. this.curAppointInfo = row
  157. // 直接上机
  158. if (row.controlMode == '10') {
  159. showConfirmDialog({
  160. title: '提示',
  161. message: '确认上机?'
  162. })
  163. .then(() => {
  164. if (this.loading) return
  165. this.loading = true
  166. this.handleGetOnByAppointId(this.curAppointInfo.id)
  167. })
  168. .catch(() => { })
  169. } else if (row.controlMode == '20' || row.controlMode == '50' || row.controlMode == '70') {
  170. // wifi控制 和 电脑控制
  171. const that = this
  172. // 调起条码扫描
  173. const res = await useUserInfo().scanCode()
  174. that.handleDeCode(res, row, that.handleCodeInfo)
  175. } else if (row.controlMode == '30' || row.controlMode == '60') {
  176. // 蓝牙
  177. // this.$refs.bluetoothRef.initBlue('open', row)
  178. // await useUserInfo().scanCode(0)
  179. const that = this
  180. const res = await useUserInfo().scanCode()
  181. that.handleDeCode(res, row, that.handleBluetoothDeCode)
  182. }
  183. },
  184. /**
  185. * 解码
  186. * code 二维码内容
  187. * row 当前预约信息
  188. * func 解码后的操作函数
  189. * */
  190. async handleDeCode(code, row, func) {
  191. if (this.loading) return
  192. this.loading = true
  193. const params = { content: code }
  194. const [err, res] = await to(instApi.decode({ ...params }))
  195. if (err) {
  196. this.loading = false
  197. showNotify({ type: 'danger', message: '解码失败,请重试' })
  198. return
  199. }
  200. if (res?.code == 200 && res?.data?.content) {
  201. func(res.data.content, row)
  202. } else {
  203. this.loading = false
  204. showNotify({ type: 'danger', message: res?.message || '解码失败' })
  205. }
  206. },
  207. /**
  208. * 解码后的信息判断扫码仪器是否是当前预约仪器
  209. * content 解码后的内容 两种 带id(仪器id)和不带id
  210. * appointRow 当前预约信息
  211. */
  212. async handleCodeInfo(content, appointRow) {
  213. // if (content.includes('id')) {
  214. // if (JSON.parse(content).id == appointRow.instId) {
  215. // this.handleGetOnByAppointId(appointRow.id)
  216. // } else {
  217. // this.loading = false
  218. // showNotify({ type: 'warning', message: '扫码机器不是预约机器' })
  219. // }
  220. // } else {
  221. // // 拿到解码信息(仪器编码)获取仪器id
  222. // const [instErr, instRes] = await to(instApi.getIdByTerminal({ terminal: content }))
  223. // if (instErr) {
  224. // this.loading = false
  225. // return
  226. // }
  227. // if (instRes.data.id == appointRow.instId) {
  228. // this.handleGetOnByAppointId(appointRow.id)
  229. // } else {
  230. // this.loading = false
  231. // showNotify({ type: 'warning', message: '扫码机器不是预约机器' })
  232. // }
  233. // }
  234. console.log(content)
  235. // 不管有没有 id 都不要再校验“扫码机器不是预约机器”,直接上机
  236. this.handleGetOnByAppointId(appointRow.id)
  237. },
  238. //蓝牙 重新解码函数,获取解码内容之后 执行跳转操作
  239. async handleBluetoothDeCode(content) {
  240. let terminal = ''
  241. if (content.includes('id')) {
  242. terminal = JSON.parse(content)?.terminal
  243. } else {
  244. terminal = content
  245. }
  246. this.loading = true
  247. const [codeErr, codeRes] = await to(instApi.getBlueToothCode({ terminal }))
  248. if (codeErr) {
  249. this.loading = false
  250. showNotify({ type: 'danger', message: '获取蓝牙码失败,请重试' })
  251. return
  252. }
  253. if (codeRes?.code == 200 && codeRes.data?.code) {
  254. this.loading = false
  255. const url = scanCodeWxUrl(terminal, 'StartRun')
  256. window.location.href = url
  257. } else {
  258. this.loading = false
  259. showNotify({ type: 'warning', message: '未获取到该设备的蓝牙配置,请联系管理员' })
  260. }
  261. },
  262. // 上机
  263. async handleGetOnByAppointId(id) {
  264. const params = { appointId: id }
  265. const [err, res] = await to(instAppointApi.getOn({ ...params }))
  266. this.loading = false
  267. if (err) return
  268. if (res.code == 200) {
  269. showNotify({ type: 'success', message: '上机成功' })
  270. setTimeout(() => {
  271. this.$router.push(`/onlineInfo?appointId=${id}`)
  272. })
  273. }
  274. },
  275. handleCancelAppoint(row) {
  276. showConfirmDialog({
  277. title: '提示',
  278. message: '确认取消预约?'
  279. })
  280. .then((e) => {
  281. this.cancelAppoint(row.id)
  282. })
  283. },
  284. // 取消预约
  285. async cancelAppoint(id) {
  286. const params = { id }
  287. const [err, res] = await to(instAppointApi.userCancelAppoint(params))
  288. if (err) return
  289. if (res?.code === 200) {
  290. this.queryForm.pageNum = 1
  291. this.appointList = []
  292. this.getInstList()
  293. showNotify({ type: 'success', message: '取消成功' })
  294. }
  295. }
  296. }
  297. }
  298. </script>
  299. <style lang="scss" scoped>
  300. * {
  301. box-sizing: border-box;
  302. }
  303. .panel-wrap {
  304. height: 100%;
  305. .data-list {
  306. .inst-item {
  307. border-radius: 10px;
  308. padding: 15px;
  309. box-shadow: -2px 0px 9px rgba(0, 0, 0, 0.12);
  310. margin-bottom: 20px;
  311. background-color: #fff;
  312. .equ-tit {
  313. width: 74px;
  314. }
  315. }
  316. }
  317. }
  318. </style>