index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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="没有更多了" @load="onLoad">
  14. <div class="inst-item mb40" v-for="(v, index) in appointList" :key="index">
  15. <div class="flex flex-between mb20">
  16. <div>
  17. <div class="mr10">
  18. <span class="primary-color bold fontSize14">{{ v.instName }}</span>
  19. </div>
  20. </div>
  21. <div class="flex">
  22. <van-button
  23. style="width: 80px; height: 30px; margin: 0; font-size: 14px"
  24. class="scan-txt"
  25. type="primary"
  26. size="small"
  27. :disabled="loading"
  28. v-if="['10', '20', '30', '50'].includes(v.controlMode)"
  29. @click="handleGetOn(v)"
  30. >
  31. {{ v.controlMode == '10' ? '上机' : '扫码上机' }}
  32. </van-button>
  33. <van-button
  34. style="width: 60px; height: 30px; margin: 0 0 0 10px; font-size: 14px"
  35. class="scan-txt"
  36. type="warning"
  37. size="small"
  38. :disabled="loading"
  39. @click="handleCancelAppoint(v)"
  40. >
  41. 取消
  42. </van-button>
  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.instNameEn }}</span>
  51. </div>
  52. </div>
  53. <div class="flex mb20" v-if="v.projectName">
  54. <div class="equ-tit">
  55. <span class="fontSize14 bold">课题组:</span>
  56. </div>
  57. <div>
  58. <span class="fontSize14">{{ v.projectName }}</span>
  59. </div>
  60. </div>
  61. <div class="flex mb20" v-if="v.serviceName">
  62. <div class="equ-tit">
  63. <span class="fontSize14 bold">服务:</span>
  64. </div>
  65. <div>
  66. <span class="fontSize14">{{ v.serviceName }}</span>
  67. </div>
  68. </div>
  69. <div class="flex mb20">
  70. <div class="equ-tit">
  71. <span class="fontSize14 bold">所在位置:</span>
  72. </div>
  73. <div>
  74. <span class="fontSize14">{{ v.placeAddress + '(' + (v.laboratoryName || '') + ')' }}</span>
  75. </div>
  76. </div>
  77. <div class="flex">
  78. <div class="equ-tit">
  79. <span class="fontSize14 bold">开始时间:</span>
  80. </div>
  81. <div>
  82. <span class="fontSize14">
  83. {{ v.startTime }}
  84. <!-- {{ v.startTime ? formatDates(new Date(v.startTime), 'YYYY-mm-dd HH:MM') : '' }} -->
  85. </span>
  86. </div>
  87. </div>
  88. </div>
  89. </van-list>
  90. <!-- </van-pull-refresh> -->
  91. <!-- <blue-tooth ref="bluetoothRef"></blue-tooth> -->
  92. </div>
  93. </template>
  94. <script>
  95. // import BlueTooth from '../../../components/BlueTooth'
  96. // import { formatDate } from '/@/utils/formatTime'
  97. import { useUserInfo } from '/@/stores/userInfo'
  98. import { useMyAppointApi } from '/@/api/appoint'
  99. const myAppointApi = useMyAppointApi()
  100. import { useInstrApi } from '/@/api/instr'
  101. const instApi = useInstrApi()
  102. import instAppointApi from '/@/api/instr/instAppoint'
  103. import to from 'await-to-js'
  104. import { showConfirmDialog, showNotify } from 'vant'
  105. export default {
  106. // components: { BlueTooth },
  107. data() {
  108. return {
  109. loading: false,
  110. curAppointInfo: {},
  111. appointList: [],
  112. queryForm: {
  113. pageNum: 1,
  114. pageSize: 10
  115. },
  116. total: 0,
  117. listloading: false,
  118. finished: false
  119. }
  120. },
  121. mounted() {
  122. this.queryForm.pageNum = 1
  123. this.getInstList()
  124. },
  125. methods: {
  126. // 重新加载
  127. onLoad() {
  128. this.queryForm.pageNum++
  129. this.getInstList()
  130. },
  131. // 查询列表
  132. async getInstList() {
  133. this.listloading = true
  134. const [err, res] = await to(myAppointApi.toGetonList(this.queryForm))
  135. this.listloading = false
  136. if (err) return
  137. if (res?.code === 200) {
  138. this.appointList = this.queryForm.pageNum == 1 ? [...(res?.data?.list || [])] : [...this.appointList, ...(res?.data?.list || [])]
  139. this.total = res?.data?.total
  140. if (this.queryForm.pageNum * this.queryForm.pageSize >= res.data.total) {
  141. this.finished = true
  142. }
  143. }
  144. },
  145. /**
  146. * 触发上机之前的订阅
  147. *
  148. * */
  149. handleGetOn(row) {
  150. this.handleScanCode(row)
  151. },
  152. /**
  153. * 调起二维码扫码
  154. * controlMode (10 不控制 20 电源控制(wifi) 30 电源控制(蓝牙) 50 电脑控制)
  155. */
  156. async handleScanCode(row) {
  157. this.curAppointInfo = row
  158. // 直接上机
  159. if (row.controlMode == '10') {
  160. showConfirmDialog({
  161. title: '提示',
  162. message: '确认上机?'
  163. })
  164. .then(() => {
  165. if (this.loading) return
  166. this.loading = true
  167. this.handleGetOnByAppointId(this.curAppointInfo.id)
  168. })
  169. .catch(() => {})
  170. } else if (row.controlMode == '20' || row.controlMode == '50') {
  171. // wifi控制 和 电脑控制
  172. const that = this
  173. // 调起条码扫描
  174. const res = await useUserInfo().scanCode()
  175. that.handleDeCode(res, row)
  176. } else if (row.controlMode == '30') {
  177. // 蓝牙
  178. // this.$refs.bluetoothRef.initBlue('open', row)
  179. await useUserInfo().scanCode(0)
  180. }
  181. },
  182. /**
  183. * 解码
  184. * code 二维码内容
  185. * row 当前预约信息
  186. * */
  187. async handleDeCode(code, row) {
  188. if (this.loading) return
  189. this.loading = true
  190. const params = { content: code }
  191. const [err, res] = await to(instApi.decode({ ...params }))
  192. if (err) return (this.loading = false)
  193. if (res.code == 200) {
  194. this.handleCodeInfo(res.data.content, row)
  195. } else {
  196. this.loading = false
  197. }
  198. },
  199. /**
  200. * 解码后的信息判断扫码仪器是否是当前预约仪器
  201. * content 解码后的内容 两种 带id(仪器id)和不带id
  202. * appointRow 当前预约信息
  203. */
  204. async handleCodeInfo(content, appointRow) {
  205. if (content.includes('id')) {
  206. if (JSON.parse(content).id == appointRow.instId) {
  207. this.handleGetOnByAppointId(appointRow.id)
  208. } else {
  209. this.loading = false
  210. showNotify({ type: 'warning', message: '扫码机器不是预约机器' })
  211. }
  212. } else {
  213. // 拿到解码信息(仪器编码)获取仪器id
  214. const [instErr, instRes] = await to(instApi.getIdByTerminal({ terminal: content }))
  215. if (instErr) return
  216. if (instRes.data.id == appointRow.instId) {
  217. this.handleGetOnByAppointId(appointRow.id)
  218. } else {
  219. this.loading = false
  220. showNotify({ type: 'warning', message: '扫码机器不是预约机器' })
  221. }
  222. }
  223. },
  224. // 上机
  225. async handleGetOnByAppointId(id) {
  226. const params = { appointId: id }
  227. const [err, res] = await to(instAppointApi.getOn({ ...params }))
  228. this.loading = false
  229. if (err) return
  230. if (res.code == 200) {
  231. showNotify({ type: 'success', message: '上机成功' })
  232. setTimeout(() => {
  233. this.$router.push(`/onlineInfo?appointId=${id}`)
  234. })
  235. }
  236. },
  237. handleCancelAppoint(row) {
  238. showConfirmDialog({
  239. title: '提示',
  240. message: '确认取消预约?'
  241. })
  242. .then((e) => {
  243. console.log(e)
  244. this.cancelAppoint(row.id)
  245. })
  246. .catch(() => {
  247. console.log('ssss')
  248. })
  249. },
  250. // 取消预约
  251. async cancelAppoint(id) {
  252. const params = { id }
  253. const [err, res] = await to(instAppointApi.userCancelAppoint(params))
  254. this.modalVisible = false
  255. if (err) return
  256. if (res?.code === 200) {
  257. this.queryForm.pageNum = 1
  258. this.appointList = []
  259. this.getInstList()
  260. showNotify({ type: 'success', message: '取消成功' })
  261. }
  262. }
  263. }
  264. }
  265. </script>
  266. <style lang="scss" scoped>
  267. * {
  268. box-sizing: border-box;
  269. }
  270. .panel-wrap {
  271. height: 100%;
  272. .data-list {
  273. .inst-item {
  274. border-radius: 10px;
  275. padding: 15px;
  276. box-shadow: -2px 0px 9px rgba(0, 0, 0, 0.12);
  277. margin-bottom: 20px;
  278. background-color: #fff;
  279. .equ-tit {
  280. width: 74px;
  281. }
  282. }
  283. }
  284. }
  285. </style>