index2.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template>
  2. <!-- 商品点检 -->
  3. <view class="container">
  4. <uni-nav-bar dark :fixed="true" shadow title="数智化产线AI视觉识别系统" backgroundColor="#007aff" color="#fff" height="60px">
  5. <view class="nav-bar-view" style="">数智化产线AI视觉识别系统</view>
  6. </uni-nav-bar>
  7. <view class="uni-ma-10 " style="text-align: center;font-size: 50rpx;">
  8. 设备({{eqSn}})
  9. <uni-tag class="uni-ml-10" style="font-size: 40rpx;" size="normal" text="链接中" v-if="webSocketStatus==0" type="warning"></uni-tag>
  10. <uni-tag class="uni-ml-10" style="font-size: 40rpx;" size="normal" text="已连接" v-else-if="webSocketStatus==1" type="primary"></uni-tag>
  11. <uni-tag class="uni-ml-10" style="font-size: 40rpx;" size="normal" text="重连中" v-else-if="webSocketStatus==2" type="success"></uni-tag>
  12. <uni-tag class="uni-ml-10" style="font-size: 40rpx;" size="normal" text="已断开" v-else-if="webSocketStatus==-1" type="error"></uni-tag>
  13. <uni-tag class="uni-ml-10" style="font-size: 40rpx;" size="normal" text="未知" v-else type="default"></uni-tag>
  14. </view>
  15. <uni-row class="demo-uni-row uni-ma-10">
  16. <uni-col :span="16" class="">
  17. <view class="img-card uni-mx-5">
  18. <image style="width: 100%;" mode="widthFix" v-if="imgUrl"
  19. :src="imgUrl">
  20. </image>
  21. <view class="empty" v-else>
  22. <uni-icons type="image" size="80"></uni-icons>
  23. </view>
  24. </view>
  25. </uni-col>
  26. <uni-col :span="8">
  27. <view class="uni-mr-5">
  28. <uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
  29. <uni-tr>
  30. <uni-th width="150" align="center">商品二维码</uni-th>
  31. <!-- <uni-th width="100" align="center">图片</uni-th> -->
  32. <uni-th width="50">状态</uni-th>
  33. <uni-th align="center">识别结果</uni-th>
  34. <uni-th align="center">拍照时间</uni-th>
  35. </uni-tr>
  36. <uni-tr v-for="(item, index) in tableData" :key="index" @click-row="clickRow(item)">
  37. <template >
  38. <uni-td align="center">{{ item.goodsCode }}</uni-td>
  39. <!-- <uni-td align="center">
  40. <view style="max-height: 60rpx;"><image style="width: 100rpx;height: 60rpx;":src="item.goodsImage"></image></view>
  41. </uni-td> -->
  42. <uni-td align="center">
  43. <view :class="item.status==1?'uni-success':item.status==2?'uni-error':'uni-warning'">{{ item.status==1?'成功':item.status==2?'失败':'修正成功' }}</view>
  44. </uni-td>
  45. <uni-td align="center">{{ item.ocrResult }}</uni-td>
  46. <uni-td align="center">{{ item.createTime }}</uni-td>
  47. </template>
  48. </uni-tr>
  49. </uni-table>
  50. <view class="uni-pagination-box"><uni-pagination show-icon :page-size="size" :current="current"
  51. :total="total" @change="change" /></view>
  52. </view>
  53. </uni-col>
  54. </uni-row>
  55. <!-- 提示信息弹窗 -->
  56. <uni-popup ref="message" type="message">
  57. <uni-popup-message :type="msgType" fontSizt="30px" :message="messageText" :duration="3000"></uni-popup-message>
  58. </uni-popup>
  59. <!-- 普通弹窗 -->
  60. <uni-popup ref="popup" background-color="#fff" :mask-click="false">
  61. <view class="popup-header">物料详情</view>
  62. <view class="popup-content" >
  63. <uni-forms ref="detailsForm" :modelValue="details">
  64. <uni-forms-item v-for="(item,index) in details" :key="item.id" :label="item.materialName" required :rules="[{'required': true,errorMessage: item.materialName+'必填'}]" :name="index+'.materialCode'">
  65. <view class="form-item">
  66. <uni-easyinput v-model="details[index].materialCode" :disabled="true" :placeholder="'请输入或扫描'+item.materialName+'的条码' "@blur="(e)=>detailsForm.id=e.detail.value" />
  67. </view>
  68. </uni-forms-item>
  69. </uni-forms>
  70. <input class="uni-easyinput__content-input" ref="materialCode" v-model="materialCode" :focus="true" :placeholder="'请输入或扫描物料条码' " @input="materialCodeInput"/>
  71. <view class="button-group">
  72. <button type="default" size="mini" @click="$refs.popup.close()">返回</button>
  73. <button type="primary" size="mini" @click="submit('detailsForm')">提交</button>
  74. </view>
  75. </view>
  76. </uni-popup>
  77. </view>
  78. </template>
  79. <script>
  80. const websocketModule = uni.requireNativePlugin("kyzone-websocket");
  81. export default {
  82. data() {
  83. return {
  84. isConnect:false,
  85. tableData: [],
  86. // 每页数据量
  87. size: 10,
  88. // 当前页
  89. current: 1,
  90. // 数据总量
  91. total: 0,
  92. loading: false,
  93. eqSn: this.api.getSn(),
  94. imgUrl:'',//https://ai.my-123.cn/pic/product-line/upload/20231218/d0dde7a200584e6cdb2e2f02622b9948.jpg
  95. msgType:'',
  96. messageText:'',
  97. webSocketStatus:0,
  98. detailsForm:{},
  99. details:[],
  100. materialCode:'',
  101. }
  102. },
  103. onLoad() {
  104. if(!this.eqSn){
  105. let macAddress = that.api.getMacAddress()
  106. that.api.setSn(macAddress)
  107. }
  108. // this.webSocketConfig()
  109. this.getData(1)
  110. this.initWebSocket()
  111. },
  112. onUnload() {
  113. // 页面销毁时执行的操作
  114. console.log('页面销毁,onUnload被触发');
  115. websocketModule.close()
  116. },
  117. methods: {
  118. initWebSocket(){
  119. websocketModule.close()
  120. var that = this
  121. let url = that.api.wsHost() + that.eqSn +"_"+ new Date().getTime()
  122. websocketModule.connect({
  123. url: url,
  124. reconnect: true, // 是否重连
  125. headers:[],
  126. })
  127. plus.globalEvent.addEventListener('onConnectState', function(e) {
  128. debugger
  129. const data = e.data;
  130. that.webSocketStatus = data
  131. })
  132. plus.globalEvent.addEventListener('onErrorMsg', function(e) {
  133. debugger
  134. console.log("错误信息:" + e.data);
  135. })
  136. plus.globalEvent.addEventListener('onMessage', function(e) {
  137. debugger
  138. e.data = e.data.replace(/\"id\": (\d+)/g,'"id":"$1"');
  139. const data = JSON.parse(e.data);
  140. console.log("监听接收的信息:" );
  141. console.log(data);
  142. if(data.eqSn==that.eqSn){
  143. that.imgUrl = data.goodsImage
  144. that.msgType = data.status==1?'success':'error'
  145. that.messageText = data.ocrResult
  146. that.$refs.message.open()
  147. that.getData(1)
  148. if(data.status!=1){
  149. that.clickRow(data)
  150. }
  151. let innerAudioContext = uni.createInnerAudioContext();
  152. innerAudioContext.src = data.status==1?'../../static/cg.mp3':'../../static/sb.mp3';
  153. innerAudioContext.play();
  154. innerAudioContext.onPause(function() {
  155. uni.$console.info('end');
  156. innerAudioContext.destroy();//音频播放停止后,就销毁实例
  157. });
  158. }
  159. })
  160. },
  161. // 分页触发
  162. change(e) {
  163. this.getData(e.current)
  164. },
  165. // 获取数据
  166. getData(pageCurrent, value = '') {
  167. this.loading = true
  168. let that = this,
  169. url = "app/api/inspectionRecordsList",
  170. params = {
  171. current: pageCurrent,
  172. size: that.size,
  173. eqSn_equal: that.eqSn
  174. }
  175. that.api.request(url, params, "get").then((res) => {
  176. that.tableData = res.records
  177. that.total = res.total
  178. that.loading = false
  179. }).catch((res) => {
  180. that.loading = false
  181. })
  182. // this.request({
  183. // pageSize: this.pageSize,
  184. // pageCurrent: pageCurrent,
  185. // value: value,
  186. // success: res => {
  187. // // console.log('data', res);
  188. // this.tableData = res.data
  189. // this.total = res.total
  190. // this.loading = false
  191. // }
  192. // })
  193. },
  194. clickRow(item){
  195. let that = this
  196. this.imgUrl = item.goodsImage
  197. console.log(item)
  198. if(item.status==2 && item.goodsId>0){
  199. this.$refs.popup.open("center")
  200. this.details=[];
  201. that.api.request("app/api/getInspectionDetails", {inspectionRecordsId_equal:item.id}, "get").then((res) => {
  202. that.details = res
  203. console.log(res)
  204. }).catch((res) => {
  205. that.loading = false
  206. })
  207. }
  208. },
  209. submit(ref) {
  210. let that = this;
  211. this.$refs[ref].validate().then(res => {
  212. console.log("123123")
  213. that.api.request("app/api/editInspectionDetails",that.details, "post").then((res) => {
  214. that.$refs.popup.close()
  215. uni.showToast({
  216. title: `修改成功`
  217. })
  218. that.getData(1)
  219. }).catch((res) => {
  220. that.loading = false
  221. })
  222. }).catch(err => {
  223. console.log('err', err);
  224. })
  225. },
  226. materialCodeInput(e){
  227. let that = this;
  228. let value = e.target.value;
  229. this.$nextTick(()=>{
  230. that.materialCode='';
  231. })
  232. let count = 0;
  233. that.details.forEach(function(item, index) {
  234. if(item.correctMaterialCode == value){
  235. console.log(index)
  236. if(!item.materialCode){
  237. that.$nextTick(()=>{
  238. that.details[index].materialCode = value
  239. })
  240. count++
  241. }
  242. }
  243. if(item.materialCode){
  244. count++
  245. }
  246. })
  247. if(count >= that.details.length){
  248. console.log(count)
  249. that.$nextTick(()=>{
  250. setTimeout(() => {
  251. console.log("detailsForm")
  252. that.submit('detailsForm')
  253. }, 500)
  254. })
  255. }
  256. return
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang="scss" scoped>
  262. .container {
  263. font-size: 14px;
  264. line-height: 24px;
  265. }
  266. .uni-group {
  267. display: flex;
  268. align-items: center;
  269. }
  270. .img-card{
  271. box-shadow: 0 0 5px 1px rgba(0,0,0,.08);
  272. min-height: 1300rpx;
  273. text-align: center;
  274. .empty{
  275. padding-top: 600rpx;
  276. }
  277. }
  278. .nav-bar-view{
  279. display: flex;
  280. flex: 1;
  281. flex-direction: row;
  282. align-items: center;
  283. justify-content: center;
  284. font-size: 12px;
  285. overflow: hidden;
  286. font-size: 50rpx;
  287. font-weight: bold;
  288. }
  289. .popup-header{
  290. padding: 20rpx 20rpx;
  291. font-size: 30rpx;
  292. border-bottom: 2rpx #bcbcbc solid;
  293. }
  294. .popup-content{
  295. margin: 100rpx;
  296. .button-group{
  297. margin-top: 15px;
  298. display: flex;
  299. justify-content: space-around;
  300. button{
  301. width: 200rpx;
  302. padding: 10rpx 0;
  303. }
  304. }
  305. }
  306. .uni-easyinput__content-input {
  307. color: #333;
  308. line-height: 35px;
  309. font-size: 14px;
  310. height: 35px;
  311. border: 1px solid $uni-border-1;
  312. border-radius: 4px;
  313. padding: 0 15px;
  314. }
  315. </style>