home.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view>
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. right-icon="scan"
  7. title="工作台"
  8. @clickLeft="back"
  9. @clickRight="HandlScanCode"
  10. ></uni-nav-bar>
  11. <!-- <uni-nav-bar fixed="true" statusBar="true" title="工作台"></uni-nav-bar> -->
  12. <navigation ref="navigationRef"></navigation>
  13. <!-- 设备主管 -->
  14. <equipment v-if="roleId == 102" ref="equipmentRef"></equipment>
  15. <!-- 运维 -->
  16. <Mocha v-if="roleId == 157" ref="mochaRef"></Mocha>
  17. <!-- 模具舟皿 -->
  18. <mould v-if="roleId == 155" ref="mouldRef"></mould>
  19. <!-- 备品备件 -->
  20. <sparePart v-if="roleId == 150" ref="sparePartRef"></sparePart>
  21. <!-- <ScanCode ref="ScanCode" :model="'uni'"></ScanCode> -->
  22. </view>
  23. </template>
  24. <script>
  25. import navigation from './components/navigation.vue'
  26. import equipment from './pages/equipment/equipment.vue'
  27. import Mocha from './pages/Mocha/Mocha.vue'
  28. import mould from './pages/mould/mould.vue'
  29. import sparePart from './pages/sparePart/sparePart.vue'
  30. import ScanCode from '@/components/ScanCode.vue'
  31. import { postJ, post, get } from '@/utils/api'
  32. export default {
  33. components: {
  34. navigation,
  35. equipment,
  36. Mocha,
  37. mould,
  38. sparePart,
  39. ScanCode
  40. },
  41. onShow () {
  42. this.init()
  43. let _this = this
  44. uni.$off('scancodedate') // 每次进来先 移除全局自定义事件监听器
  45. uni.$on('scancodedate', function (data) {
  46. console.log(data, '-----scancodedate')
  47. _this.cbScancodedate(data)
  48. })
  49. // this.Scancodedate()
  50. },
  51. onUnload () {
  52. uni.$off('scancodedate')
  53. },
  54. onHide () {
  55. uni.$off('scancodedate')
  56. },
  57. data () {
  58. return {
  59. roleId: null,
  60. timer: null,
  61. qrContent: null,
  62. barType: null,
  63. // 扫码后的设备信息
  64. equipmentInfo: '',
  65. qrContent: '',
  66. barType: ''
  67. }
  68. },
  69. created () {
  70. uni.getStorage({
  71. key: 'userInfo',
  72. success: res => {
  73. this.roleId = res.data.role.id
  74. }
  75. })
  76. },
  77. methods: {
  78. init () {
  79. this.$refs.navigationRef && this.$refs.navigationRef.getCount()
  80. this.$refs.equipmentRef && this.$refs.equipmentRef.getData()
  81. this.$refs.mochaRef && this.$refs.mochaRef.getData()
  82. this.$refs.mouldRef &&
  83. (this.$refs.mouldRef.getBoatInventoryCountList(),
  84. this.$refs.mouldRef.getModeInventoryCountList())
  85. this.$refs.sparePartRef && this.$refs.sparePartRef.getData()
  86. this.timer = setTimeout(() => {
  87. this.init()
  88. }, 6000)
  89. },
  90. // 相机扫码
  91. HandlScanCode () {
  92. let _this = this
  93. uni.scanCode({
  94. success: function (res) {
  95. _this.Scancodedate(res.result)
  96. }
  97. })
  98. //_this.Scancodedate('res')
  99. },
  100. // 根据条码请求设备数据
  101. getData () {
  102. let par = {
  103. barType: this.barType,
  104. qrContent: this.qrContent
  105. }
  106. this.equipmentInfo = {}
  107. return postJ(this.apiUrl + '/scan/getAssetInfo', par)
  108. .then(res => {
  109. console.log(res.data)
  110. this.equipmentInfo = res.data
  111. })
  112. .catch(err => {
  113. console.log(err, 'err-----------------')
  114. uni.showToast({
  115. title: '系统错误!',
  116. icon: 'none',
  117. duration: 2000
  118. })
  119. })
  120. },
  121. // 扫码枪扫码
  122. cbScancodedate (data) {
  123. this.Scancodedate(data.code)
  124. },
  125. async Scancodedate (code) {
  126. this.qrContent = code.trim()
  127. // this.qrContent = 'w01000002100001@_@0' //code.trim()
  128. //this.qrContent = '005/w01000001120041/锤锤专用02-不拆包-批量/规格01//成型/成型工序@_@0'
  129. this.barType = this.setBarType(this.qrContent)
  130. await this.getData()
  131. if (this.equipmentInfo.assetCode) {
  132. if (this.equipmentInfo.assetType != 1) {
  133. uni.showToast({
  134. title: '请扫描生产设备码!',
  135. icon: 'none',
  136. duration: 2000
  137. })
  138. return
  139. }
  140. let par = {
  141. info: encodeURIComponent(JSON.stringify(this.equipmentInfo)),
  142. qrContent: this.qrContent
  143. }
  144. par = this.URLSearchParams(par)
  145. console.log('qrwewett')
  146. uni.navigateTo({
  147. url: '/pages/equipment_ledger/index?' + par
  148. })
  149. }
  150. },
  151. // 设置barType
  152. setBarType (val) {
  153. let index = val.indexOf('@_@')
  154. let result = 0
  155. if (index !== -1) {
  156. let item = val.substr(index + 3, 1)
  157. if (item) {
  158. result = Number(item)
  159. }
  160. }
  161. return result
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. page {
  168. background-color: $page-bg;
  169. }
  170. </style>