master-data.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <uni-popup class="materials-popup" ref="masterDataPopRef" type="bottom" :is-mask-click="false"
  3. borderRadius="10px 10px 0 0">
  4. <z-paging class="z-page-popup" ref="paging" style="top: 230px;" v-model="dataList" @query="queryList">
  5. <!-- z-paging默认铺满全屏,此时页面所有view都应放在z-paging标签内,否则会被盖住 -->
  6. <!-- 需要固定在页面顶部的view请通过slot="top"插入,包括自定义的导航栏 -->
  7. <template #top>
  8. <view class="page-top">
  9. <uni-row class="head-row">
  10. <uni-col :span="6" class="head-cancel align-center justify-start">
  11. {{$t('operation.cancel')}}
  12. </uni-col>
  13. <uni-col :span="12" class="head-title justify-center">
  14. {{$t('workOrder.masterData')}}
  15. </uni-col>
  16. <uni-col :span="6" class="head-add align-center justify-end" @click="oncancel">
  17. <uni-icons type="closeempty" color="#333"></uni-icons>
  18. </uni-col>
  19. </uni-row>
  20. <uni-row class="search-row flex-row justify-between">
  21. <uni-col :span="24">
  22. <uni-easyinput v-model="searchValue" :styles="inputStyles"
  23. :placeholderStyle="placeholderStyle"
  24. :placeholder="`${$t('operation.PleaseInput')}${$t('workOrder.materialName')}`"
  25. @confirm="searchList">
  26. </uni-easyinput>
  27. </uni-col>
  28. </uni-row>
  29. <uni-row :gutter="5" class="table-header flex-row align-center justify-between">
  30. <uni-col :span="5" class="flex-row justify-center">
  31. {{ $t('workOrder.materialCode')}}
  32. </uni-col>
  33. <uni-col :span="9" class="flex-row justify-center">
  34. {{ $t('workOrder.materialName')}}
  35. </uni-col>
  36. <uni-col :span="3" class="flex-row justify-center">
  37. {{ $t('workOrder.unit')}}
  38. </uni-col>
  39. <uni-col :span="4" class="flex-row justify-center">
  40. {{ $t('workOrder.specification')}}
  41. </uni-col>
  42. <uni-col :span="3" class="flex-row justify-center">
  43. {{ $t('workOrder.status')}}
  44. </uni-col>
  45. </uni-row>
  46. </view>
  47. </template>
  48. <view class="page-table">
  49. <uni-row :gutter="5" class="item-row align-center"
  50. :class="{'choosed': chooseIds.includes(item.id)}" v-for="(item,index) in dataList"
  51. :key="index" @click="onChoose(item)">
  52. <uni-col :span="5" class="item-col flex-row justify-start">
  53. {{item.code}}
  54. </uni-col>
  55. <uni-col :span="9" class="item-col flex-row justify-center">
  56. {{item.name}}
  57. </uni-col>
  58. <uni-col :span="3" class="item-col flex-row justify-center">
  59. {{item.unit}}
  60. </uni-col>
  61. <uni-col :span="4" class="item-col flex-row justify-center">
  62. {{item.unitPrice}}
  63. </uni-col>
  64. <uni-col :span="3" class="item-col flex-row justify-center">
  65. {{item.status==0 ? $t('status.enable') : $t('status.disable')}}
  66. </uni-col>
  67. </uni-row>
  68. </view>
  69. </z-paging>
  70. </uni-popup>
  71. </template>
  72. <script setup>
  73. import dayjs from 'dayjs'
  74. import {
  75. computed,
  76. ref,
  77. reactive,
  78. watch,
  79. onMounted,
  80. } from 'vue'
  81. import {
  82. useI18n
  83. } from 'vue-i18n'
  84. import {
  85. getDeptId,
  86. } from "@/utils/auth"
  87. import {
  88. getMaterialListData
  89. } from '@/api/material'
  90. // 接收父组件传递的参数
  91. const props = defineProps({
  92. deviceId: {
  93. type: Number,
  94. },
  95. materialItem: {
  96. type: Object,
  97. default: () => {}
  98. },
  99. })
  100. const searchValue = ref('')
  101. const placeholderStyle = ref('color:#ADADAD;font-weight:400;font-size:12px')
  102. const inputStyles = reactive({
  103. backgroundColor: '#F5F5F5',
  104. color: '#797979',
  105. })
  106. const paging = ref(null)
  107. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  108. const dataList = ref([])
  109. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  110. const queryList = (pageNo, pageSize) => {
  111. // 此处请求仅为演示,请替换为自己项目中的请求
  112. getMaterialListData({
  113. pageNo,
  114. pageSize,
  115. name: searchValue.value
  116. }).then(res => {
  117. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  118. // res.data.list.forEach(item => {
  119. // item.chooseKey =
  120. // `${item.code}_${item.id}`
  121. // })
  122. paging.value.complete(res.data.list);
  123. }).catch(res => {
  124. // 如果请求失败写paging.value.complete(false);
  125. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  126. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  127. paging.value.complete(false);
  128. })
  129. }
  130. const searchList = () => {
  131. paging.value.reload()
  132. }
  133. const formatDate = (time) => {
  134. return dayjs(time).format('YYYY-MM-DD');
  135. }
  136. // ----------------------------------------------
  137. // ---------------------------------------------
  138. const chooseList = ref([])
  139. const chooseIds = computed(() => {
  140. // 返回chooseList的id组成新数组
  141. return chooseList.value.map(c => c.id)
  142. })
  143. const onChoose = (item) => {
  144. // 判断当前点击的设备是否存在于chooseList中,
  145. // 若存在,则从chooseList中删除,否则添加到chooseList中
  146. // 若不存在则添加
  147. const index = chooseList.value.findIndex((v) => v.id === item.id)
  148. if (index > -1) {
  149. // chooseList.value.splice(index, 1)
  150. } else {
  151. chooseList.value = [item]
  152. onSubmit(item)
  153. }
  154. }
  155. const onChooseDel = (item) => {
  156. // 判断当前点击的设备是否存在于chooseList中,
  157. // 若存在,则从chooseList中删除,否则添加到chooseList中
  158. const index = chooseList.value.findIndex((v) => v.id === item.id)
  159. if (index > -1) {
  160. chooseList.value.splice(index, 1)
  161. }
  162. }
  163. const oncancel = () => {
  164. chooseList.value = []
  165. close()
  166. }
  167. const onSubmit = (item) => {
  168. console.log('item', item)
  169. emit('master-data-submit', {
  170. ...item,
  171. materialCode: item.code, // 转换物料编码字段
  172. materialName: item.name, // 转换物料名称字段
  173. })
  174. oncancel()
  175. }
  176. const {
  177. t,
  178. locale
  179. } = useI18n({
  180. useScope: 'global'
  181. })
  182. onMounted(() => {})
  183. const masterDataPopRef = ref(null)
  184. // 打开弹窗
  185. const open = () => {
  186. masterDataPopRef.value.open()
  187. }
  188. // 关闭弹窗
  189. const close = () => {
  190. masterDataPopRef.value.close()
  191. }
  192. const emit = defineEmits(['master-data-submit'])
  193. // 提供外部方法
  194. const expose = {
  195. open,
  196. }
  197. defineExpose(expose)
  198. </script>
  199. <style lang="scss" scoped>
  200. @import "@/style/choose-device.scss";
  201. .z-page-popup {
  202. padding: 20px 15px;
  203. box-sizing: border-box;
  204. background: #FFF;
  205. border-radius: 10px 10px 0 0;
  206. }
  207. .page-top {
  208. background: #fff;
  209. padding: 0;
  210. }
  211. .head-row {
  212. margin-bottom: 20px;
  213. font-size: 16px;
  214. line-height: 21px;
  215. color: #A3A3A3;
  216. }
  217. .head-title {
  218. color: #333333;
  219. font-weight: bold;
  220. }
  221. .head-add {
  222. color: #004098;
  223. }
  224. .table-header {
  225. background: #FFF;
  226. border-bottom: 1px solid #CACCCF;
  227. }
  228. .page-table {
  229. padding: 0;
  230. }
  231. .item-col {
  232. font-size: 11px;
  233. }
  234. </style>