repair-view.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <z-paging class="page material" ref="paging" v-model="dataList" @query="queryList">
  3. <!-- z-paging默认铺满全屏,此时页面所有view都应放在z-paging标签内,否则会被盖住 -->
  4. <!-- 需要固定在页面顶部的view请通过slot="top"插入,包括自定义的导航栏 -->
  5. <view class="paging-list">
  6. <view class="material-item" v-for="(item,index) in dataList">
  7. <view class="item-content flex-row align-center justify-between">
  8. <view class="item-title">
  9. <span class="item-title-width">{{$t('workOrder.materialName')}}:</span>
  10. </view>
  11. <view class="item-title">
  12. <span>{{item.materialName || item.name}}</span>
  13. </view>
  14. </view>
  15. <view class="item-content flex-row align-center justify-between">
  16. <view class="item-title">
  17. <span class="item-title-width">{{$t('workOrder.materialCode')}}:</span>
  18. </view>
  19. <view class="item-title">
  20. <span>{{item.materialCode}}</span>
  21. </view>
  22. </view>
  23. <view class="item-content flex-row align-center justify-between">
  24. <view class="item-title">
  25. <span class="item-title-width">{{$t('workOrder.unit')}}:</span>
  26. </view>
  27. <view class="item-title">
  28. <span>{{item.unit}}</span>
  29. </view>
  30. </view>
  31. <view class="item-content flex-row align-center justify-between">
  32. <view class="item-title">
  33. <span class="item-title-width">{{$t('workOrder.consumptionQuantity')}}:</span>
  34. </view>
  35. <view class="item-title">
  36. <span>{{item.quantity}}</span>
  37. </view>
  38. </view>
  39. <view class="item-content flex-row align-center justify-between">
  40. <view class="item-title">
  41. <span class="item-title-width">{{$t('workOrder.inventoryType')}}:</span>
  42. </view>
  43. <view class="item-title">
  44. <span>{{item.materialSource}}</span>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </z-paging>
  50. </template>
  51. <script setup>
  52. import {
  53. ref,
  54. reactive,
  55. onMounted,
  56. onBeforeUnmount
  57. } from 'vue'
  58. import {
  59. onLoad
  60. } from '@dcloudio/uni-app'
  61. import {
  62. getRepairMaterialDetail,
  63. getMaterialDetail
  64. } from '@/api/material'
  65. import dayjs from 'dayjs'
  66. // --- 列表 ---start---
  67. const name = ref('')
  68. const paging = ref(null)
  69. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  70. const dataList = ref([])
  71. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  72. const queryList = (pageNo, pageSize) => {
  73. console.log('quewryList', optionParams.value.bomId)
  74. if (optionParams.value.bomId) {
  75. getRepairMaterialDetail({
  76. pageNo,
  77. pageSize,
  78. // workOrderId: optionParams.value.workOrderId,
  79. bomId: optionParams.value.bomId
  80. }).then(res => {
  81. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  82. paging.value.complete(res.data.list);
  83. }).catch(res => {
  84. // 如果请求失败写paging.value.complete(false);
  85. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  86. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  87. paging.value.complete(false);
  88. })
  89. }else{
  90. paging.value.complete(materialList.value);
  91. }
  92. }
  93. const onSearch = () => {
  94. paging.value.reload()
  95. }
  96. const formatDate = (time) => {
  97. return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
  98. }
  99. // -- end --
  100. const optionParams = ref({})
  101. onLoad((option) => {
  102. optionParams.value = option
  103. console.log('onLoad' + optionParams.value)
  104. })
  105. const materialList = ref([])
  106. onMounted(() => {
  107. // 监听子页面提交的事件
  108. console.log('onMounted')
  109. uni.$on('material-view', (data) => {
  110. console.log('接收到子页面数据:', data);
  111. materialList.value = data
  112. paging.value.reload()
  113. });
  114. })
  115. onBeforeUnmount(() => {
  116. // 移除监听
  117. console.log('onBeforeUnmount')
  118. uni.$off('material-view');
  119. })
  120. const navigatorBack = () => {
  121. uni.navigateBack();
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. @import "@/style/work-order-detail.scss";
  126. .material-item {
  127. box-sizing: border-box;
  128. padding: 20px;
  129. background-color: #fff;
  130. margin-bottom: 5px;
  131. }
  132. </style>