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. let _this = this
  110. uni.scanCode({
  111. success: function(res) {
  112. _this.Scancodedate(res.result)
  113. }
  114. })
  115. //_this.Scancodedate('res')
  116. },
  117. // 根据条码请求设备数据
  118. getData() {
  119. let par = {
  120. barType: this.barType,
  121. qrContent: this.qrContent
  122. }
  123. this.equipmentInfo = {}
  124. return postJ(this.apiUrl + '/scan/getAssetInfo', par)
  125. .then(res => {
  126. console.log(res.data)
  127. this.equipmentInfo = res.data
  128. })
  129. .catch(err => {
  130. console.log(err, 'err-----------------')
  131. uni.showToast({
  132. title: '系统错误!',
  133. icon: 'none',
  134. duration: 2000
  135. })
  136. })
  137. },
  138. // 扫码枪扫码
  139. cbScancodedate(data) {
  140. this.Scancodedate(data.code)
  141. },
  142. async Scancodedate(code) {
  143. this.qrContent = code.trim()
  144. // this.qrContent = 'w01000002100001@_@0' //code.trim()
  145. //this.qrContent = '005/w01000001120041/锤锤专用02-不拆包-批量/规格01//成型/成型工序@_@0'
  146. this.barType = this.setBarType(this.qrContent)
  147. await this.getData()
  148. if (this.equipmentInfo.assetCode) {
  149. if (this.equipmentInfo.assetType != 1) {
  150. uni.showToast({
  151. title: '请扫描生产设备码!',
  152. icon: 'none',
  153. duration: 2000
  154. })
  155. return
  156. }
  157. let par = {
  158. info: encodeURIComponent(JSON.stringify(this.equipmentInfo)),
  159. qrContent: this.qrContent
  160. }
  161. par = this.URLSearchParams(par)
  162. console.log('qrwewett')
  163. uni.navigateTo({
  164. url: '/pages/equipment_ledger/index?' + par
  165. })
  166. }
  167. },
  168. // 设置barType
  169. setBarType(val) {
  170. let index = val.indexOf('@_@')
  171. let result = 0
  172. if (index !== -1) {
  173. let item = val.substr(index + 3, 1)
  174. if (item) {
  175. result = Number(item)
  176. }
  177. }
  178. return result
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. page {
  185. background-color: $page-bg;
  186. }
  187. </style>