home.vue 4.6 KB

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