choose.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <uni-popup class="materials-popup" ref="materialChoosePopRef" type="bottom" :is-mask-click="false"
  3. borderRadius="10px 10px 0 0">
  4. <z-paging class="z-page-popup" ref="paging" style="top: 200px;" :default-page-size="20" 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" @click="oncancel">
  11. {{$t('operation.cancel')}}
  12. </uni-col>
  13. <uni-col :span="12" class="head-title justify-center">
  14. {{$t('workOrder.selectMaterial')}}
  15. </uni-col>
  16. <uni-col :span="6" class="head-add align-center justify-end" @click="onAdd" v-if="!noAdd">
  17. <uni-icons type="plusempty" color="#004098"></uni-icons>
  18. {{$t('operation.add')}}
  19. </uni-col>
  20. </uni-row>
  21. <uni-row class="search-row flex-row justify-between">
  22. <uni-col :span="24">
  23. <uni-easyinput v-model="searchValue" :styles="inputStyles"
  24. :placeholderStyle="placeholderStyle"
  25. :placeholder="`${$t('operation.PleaseInput')}${$t('workOrder.materialName')}`"
  26. @confirm="searchList">
  27. </uni-easyinput>
  28. </uni-col>
  29. </uni-row>
  30. <uni-row :gutter="5" class="table-header flex-row align-center justify-between">
  31. <uni-col :span="5" class="flex-row justify-center">
  32. {{ $t('workOrder.materialCode')}}
  33. </uni-col>
  34. <uni-col :span="7" class="flex-row justify-center">
  35. {{ $t('workOrder.materialName')}}
  36. </uni-col>
  37. <uni-col :span="3" class="flex-row justify-center">
  38. {{ $t('workOrder.unit')}}
  39. </uni-col>
  40. <uni-col :span="3" class="flex-row justify-center">
  41. {{ $t('workOrder.unitPrice')}}
  42. </uni-col>
  43. <uni-col :span="3" class="flex-row justify-center">
  44. {{ $t('workOrder.inventory')}}
  45. </uni-col>
  46. <uni-col :span="4" class="flex-row justify-end">
  47. {{ $t('workOrder.source')}}
  48. </uni-col>
  49. </uni-row>
  50. </view>
  51. </template>
  52. <view class="page-table">
  53. <uni-row :gutter="2" class="item-row align-center"
  54. :class="{'choosed': chooseIds.includes(item.chooseKey)}" v-for="(item,index) in dataList"
  55. :key="index" @click="onChoose(item)">
  56. <uni-col :span="5" class="item-col flex-row justify-start">
  57. {{item.materialCode}}
  58. </uni-col>
  59. <uni-col :span="7" class="item-col flex-row justify-start">
  60. {{item.materialName}}
  61. </uni-col>
  62. <uni-col :span="3" class="item-col flex-row justify-center">
  63. {{item.unit}}
  64. </uni-col>
  65. <uni-col :span="3" class="item-col flex-row justify-center">
  66. {{item.unitPrice}}
  67. </uni-col>
  68. <uni-col :span="3" class="item-col flex-row justify-center">
  69. {{item.totalInventoryQuantity}}
  70. </uni-col>
  71. <uni-col :span="4" class="item-col flex-row justify-end">
  72. {{item.materialSource}}
  73. </uni-col>
  74. </uni-row>
  75. </view>
  76. </z-paging>
  77. </uni-popup>
  78. <materials-count ref="countRef" @count-set="onCountSet"></materials-count>
  79. <materials-add ref="addRef" @add-set="onEmit"></materials-add>
  80. </template>
  81. <script setup>
  82. import dayjs from 'dayjs'
  83. import {
  84. computed,
  85. ref,
  86. reactive,
  87. watch,
  88. onMounted,
  89. } from 'vue'
  90. import {
  91. useI18n
  92. } from 'vue-i18n'
  93. import {
  94. getDeptId,
  95. } from "@/utils/auth"
  96. import {
  97. getMaterialList
  98. } from '@/api/material'
  99. import {
  100. devicePage,
  101. } from '@/api/device';
  102. import materialsCount from './count'
  103. import materialsAdd from './add'
  104. // 接收父组件传递的参数
  105. const props = defineProps({
  106. deviceId: {
  107. type: Number,
  108. },
  109. deptId: {
  110. type: Number,
  111. default:getDeptId(),
  112. },
  113. bomNodeId: {
  114. type: String,
  115. default: null,
  116. },
  117. materialItem: {
  118. type: Object,
  119. default: () => {}
  120. },
  121. noAdd: {
  122. type: Boolean,
  123. default: false,
  124. },
  125. })
  126. const searchValue = ref('')
  127. const placeholderStyle = ref('color:#ADADAD;font-weight:400;font-size:12px')
  128. const inputStyles = reactive({
  129. backgroundColor: '#F5F5F5',
  130. color: '#797979',
  131. })
  132. const paging = ref(null)
  133. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  134. const dataList = ref([])
  135. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  136. const queryList = (pageNo, pageSize) => {
  137. // 此处请求仅为演示,请替换为自己项目中的请求
  138. getMaterialList({
  139. pageNo,
  140. pageSize,
  141. deviceId: props.deviceId,
  142. deptId: props.deptId,
  143. bomNodeId: props.bomNodeId,
  144. materialName: searchValue.value
  145. }).then(res => {
  146. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  147. res.data.list.forEach(item => {
  148. item.chooseKey =
  149. `${item.materialCode}_${item.costCenterId}_${item.factoryId}_${item.unitPrice}_${item.storageLocationId}`
  150. })
  151. paging.value.complete(res.data.list);
  152. }).catch(res => {
  153. // 如果请求失败写paging.value.complete(false);
  154. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  155. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  156. paging.value.complete(false);
  157. })
  158. }
  159. const searchList = () => {
  160. paging.value.reload()
  161. }
  162. const formatDate = (time) => {
  163. return dayjs(time).format('YYYY-MM-DD');
  164. }
  165. // ----------------------------------------------
  166. // ---------------------------------------------
  167. const chooseList = ref([])
  168. const chooseIds = computed(() => {
  169. // 返回chooseList的id组成新数组
  170. return chooseList.value.map(c => c.chooseKey)
  171. })
  172. const onChoose = (item) => {
  173. // 判断当前点击的设备是否存在于chooseList中,
  174. // 若存在,则从chooseList中删除,否则添加到chooseList中
  175. // 若不存在则添加
  176. const index = chooseList.value.findIndex((v) => v.chooseKey === item.chooseKey)
  177. if (index > -1) {
  178. // chooseList.value.splice(index, 1)
  179. } else {
  180. chooseList.value = [item]
  181. onCountShow(item)
  182. }
  183. }
  184. const onChooseDel = (item) => {
  185. // 判断当前点击的设备是否存在于chooseList中,
  186. // 若存在,则从chooseList中删除,否则添加到chooseList中
  187. const index = chooseList.value.findIndex((v) => v.chooseKey === item.chooseKey)
  188. if (index > -1) {
  189. chooseList.value.splice(index, 1)
  190. }
  191. }
  192. const oncancel = () => {
  193. chooseList.value = []
  194. close()
  195. }
  196. const addRef = ref(null)
  197. const onAdd = () => {
  198. // oncancel()
  199. addRef.value.open()
  200. }
  201. const onEmit = (item) => {
  202. // chooseList.value = [item]
  203. console.log('onEmit-item', item, bomItem.value)
  204. const subItem = Object.assign({}, item)
  205. // subItem.bomId = bomItem.value.id
  206. subItem.bomNodeId = bomItem.value.bomNodeId
  207. // subItem.workOrderId = bomItem.value.workOrderId
  208. subItem.workOrderBomOnlyKey = bomItem.value.workOrderBomOnlyKey
  209. console.log('onEmit-subItem', subItem)
  210. emit('material-submit', subItem)
  211. oncancel()
  212. }
  213. const countRef = ref(null)
  214. const onCountShow = (item) => {
  215. countRef.value.showCountPop(item)
  216. }
  217. const onCountSet = (item) => {
  218. console.log('onCountSet- item', item)
  219. onEmit(item)
  220. countRef.value.hideCountPop()
  221. }
  222. const {
  223. t,
  224. locale
  225. } = useI18n({
  226. useScope: 'global'
  227. })
  228. const bomItem = ref({})
  229. const materialChoosePopRef = ref(null)
  230. // 打开弹窗
  231. const open = (bom) => {
  232. console.log('open-bom', bom)
  233. bomItem.value = bom
  234. materialChoosePopRef.value.open()
  235. }
  236. // 关闭弹窗
  237. const close = () => {
  238. materialChoosePopRef.value.close()
  239. }
  240. const emit = defineEmits(['material-submit'])
  241. // 提供外部方法
  242. const expose = {
  243. open,
  244. }
  245. defineExpose(expose)
  246. </script>
  247. <style lang="scss" scoped>
  248. @import "@/style/choose-device.scss";
  249. .z-page-popup {
  250. padding: 20px 15px;
  251. box-sizing: border-box;
  252. background: #FFF;
  253. border-radius: 10px 10px 0 0;
  254. }
  255. .page-top {
  256. background: #fff;
  257. padding: 0;
  258. }
  259. .head-row {
  260. margin-bottom: 20px;
  261. font-size: 16px;
  262. line-height: 21px;
  263. color: #A3A3A3;
  264. }
  265. .head-title {
  266. color: #333333;
  267. font-weight: bold;
  268. }
  269. .head-add {
  270. color: #004098;
  271. }
  272. .table-header {
  273. background: #FFF;
  274. border-bottom: 1px solid #CACCCF;
  275. }
  276. .page-table {
  277. padding: 0;
  278. }
  279. .item-col {
  280. font-size: 11px;
  281. }
  282. </style>