view.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. getMaterialDetail,
  63. } from '@/api/material'
  64. import dayjs from 'dayjs'
  65. // --- 列表 ---start---
  66. const name = ref('')
  67. const paging = ref(null)
  68. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  69. const dataList = ref([])
  70. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  71. const queryList = (pageNo, pageSize) => {
  72. console.log('quewryList', optionParams.value.bomId)
  73. if (optionParams.value.bomId) {
  74. getMaterialDetail({
  75. pageNo,
  76. pageSize,
  77. workOrderId: optionParams.value.workOrderId,
  78. bomId: optionParams.value.bomId
  79. }).then(res => {
  80. if(optionParams.value.bomNodeId){
  81. res.data.list = res.data.list.filter(item => item.bomNodeId == optionParams.value.bomNodeId)
  82. }
  83. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  84. paging.value.complete(res.data.list);
  85. }).catch(res => {
  86. // 如果请求失败写paging.value.complete(false);
  87. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  88. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  89. paging.value.complete(false);
  90. })
  91. }else{
  92. paging.value.complete(materialList.value);
  93. }
  94. }
  95. const onSearch = () => {
  96. paging.value.reload()
  97. }
  98. const formatDate = (time) => {
  99. return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
  100. }
  101. // -- end --
  102. const optionParams = ref({})
  103. onLoad((option) => {
  104. optionParams.value = option
  105. console.log('onLoad' + optionParams.value)
  106. })
  107. const materialList = ref([])
  108. onMounted(() => {
  109. // 监听子页面提交的事件
  110. console.log('onMounted')
  111. uni.$on('material-view', (data) => {
  112. console.log('接收到子页面数据:', data);
  113. materialList.value = data
  114. paging.value.reload()
  115. });
  116. })
  117. onBeforeUnmount(() => {
  118. // 移除监听
  119. console.log('onBeforeUnmount')
  120. uni.$off('material-view');
  121. })
  122. const navigatorBack = () => {
  123. uni.navigateBack();
  124. };
  125. </script>
  126. <style lang="scss" scoped>
  127. @import "@/style/work-order-detail.scss";
  128. .material-item {
  129. box-sizing: border-box;
  130. padding: 20px;
  131. background-color: #fff;
  132. margin-bottom: 5px;
  133. }
  134. </style>