model.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <div>
  3. <h3>{{ title }}</h3>
  4. <el-divider />
  5. <div style="margin-bottom: 20px; width: 80px">
  6. <el-button v-if="!['detail', 'examine'].includes(module)" type="primary" size="small" @click="handleAdd"
  7. >添加机型</el-button
  8. >
  9. </div>
  10. <zj-table
  11. ref="tableEl"
  12. :is-drop="true"
  13. :columns="columns"
  14. :table-data="formData.items"
  15. :table-attributes="{
  16. border: true,
  17. maxHeight: 600
  18. }"
  19. />
  20. <el-dialog title="添加机型" append-to-body :visible.sync="isShowDialog" width="70%" :append-to-body="true">
  21. <el-form ref="screenForm" :model="screenForm" size="small" label-position="left">
  22. <el-row :gutter="20">
  23. <el-col :xs="12" :sm="6" :lg="6">
  24. <el-form-item prop="name">
  25. <el-input v-model="screenForm.name" placeholder="物料名称"></el-input>
  26. </el-form-item>
  27. </el-col>
  28. <el-col :xs="12" :sm="6" :lg="6">
  29. <el-form-item prop="number">
  30. <el-input v-model="screenForm.number" placeholder="物料编码"></el-input>
  31. </el-form-item>
  32. </el-col>
  33. <el-col :xs="12" :sm="6" :lg="6">
  34. <el-form-item prop="oldNumber">
  35. <el-input v-model="screenForm.oldNumber" placeholder="产品编码"></el-input>
  36. </el-form-item>
  37. </el-col>
  38. <el-col :xs="12" :sm="6" :lg="6">
  39. <el-form-item prop="specification">
  40. <el-input v-model="screenForm.specification" placeholder="规格型号"></el-input>
  41. </el-form-item>
  42. </el-col>
  43. <el-col :xs="24" :sm="24" :lg="24" class="tr">
  44. <el-form-item label="">
  45. <el-button size="small" @click="resetScreenForm">清空</el-button>
  46. <el-button size="small" type="primary" @click="submitScreenForm">搜索</el-button>
  47. </el-form-item>
  48. </el-col>
  49. </el-row>
  50. </el-form>
  51. <div class="table">
  52. <zj-table
  53. ref="tableEl"
  54. :is-drop="true"
  55. :columns="columns2"
  56. :table-data="k3List"
  57. :table-attributes="{
  58. border: true,
  59. selectColumn: true,
  60. selectable: this.selectable
  61. }"
  62. :tableEvents ="{
  63. 'selection-change': this.selectionChange
  64. }"
  65. />
  66. <div class="pagination clearfix" style="margin-top: 10px">
  67. <div class="fr">
  68. <el-pagination
  69. @current-change="handleTableCurrentChange"
  70. :current-page="currentPage"
  71. :page-size="10"
  72. background
  73. layout="prev, pager, next"
  74. :total="listTotal"
  75. >
  76. </el-pagination>
  77. </div>
  78. </div>
  79. </div>
  80. <span slot="footer" class="dialog-footer">
  81. <el-button @click="closeDialog">取 消</el-button>
  82. <el-button type="primary" @click="submitAddGoods">确 定</el-button>
  83. </span>
  84. </el-dialog>
  85. </div>
  86. </template>
  87. <script>
  88. import { getMaterialListV2 } from '@/api/basic_data/material'
  89. export default {
  90. props: {
  91. title: {
  92. type: String,
  93. default: '机型信息'
  94. },
  95. formData: {
  96. type: Object,
  97. default: () => ({})
  98. },
  99. // 页面类型
  100. pageType: {
  101. type: String,
  102. default: 'frock'
  103. },
  104. // 功能类型
  105. module: {
  106. type: String,
  107. default: 'add'
  108. },
  109. commonData: {
  110. type: Object,
  111. default: () => {}
  112. }
  113. },
  114. data() {
  115. return {
  116. loading: false,
  117. k3List: [],
  118. isShowDialog: false,
  119. currentPage: 1,
  120. pageSize: 10,
  121. listTotal: 0,
  122. screenForm: {
  123. name: '',
  124. oldNumber: '',
  125. number: '',
  126. specification: ''
  127. },
  128. recordSelected: []
  129. }
  130. },
  131. computed: {
  132. columns() {
  133. return [
  134. ...(() => {
  135. return !['detail', 'examine'].includes(this.module)
  136. ? [
  137. {
  138. hidden: '',
  139. columnAttributes: {
  140. fixed: 'left',
  141. label: '操作',
  142. prop: ''
  143. },
  144. render: (h, { row, column, index }) => {
  145. return (
  146. <div>
  147. <el-button
  148. size="mini"
  149. type="text"
  150. onClick={() => {
  151. this.formData.items.splice(index, 1)
  152. }}
  153. >
  154. 删除
  155. </el-button>
  156. </div>
  157. )
  158. }
  159. }
  160. ]
  161. : []
  162. })(),
  163. {
  164. columnAttributes: {
  165. label: '物料名称*',
  166. prop: 'materialName'
  167. },
  168. render: (h, { row, column, index }) => {
  169. return (
  170. <div style="display:flex;justify-content: space-between;align-items: center;">
  171. <div> {row.materialName}</div>
  172. <CopyButton copyText={row.materialName} />
  173. </div>
  174. )
  175. }
  176. },
  177. {
  178. columnAttributes: {
  179. label: '规格型号*',
  180. prop: 'specification'
  181. },
  182. render: (h, { row, column, index }) => {
  183. return (
  184. <div style="display:flex;justify-content: space-between;align-items: center;">
  185. <div> {row.specification}</div>
  186. <CopyButton copyText={row.specification} />
  187. </div>
  188. )
  189. }
  190. },
  191. {
  192. columnAttributes: {
  193. label: '备注',
  194. prop: 'itemRemark'
  195. },
  196. render: (h, { row, column, index }) => {
  197. return (
  198. <div>
  199. <el-input
  200. style="padding: 5px;width:90%"
  201. value={row.itemRemark}
  202. onInput={e => (row.itemRemark = e)}
  203. placeholder="请输入备注"
  204. size="mini"
  205. clearable
  206. >
  207. </el-input>
  208. <CopyButton copyText={row.itemRemark} />
  209. </div>
  210. )
  211. }
  212. },
  213. {
  214. columnAttributes: {
  215. label: '数量',
  216. prop: 'qty'
  217. },
  218. render: (h, { row, column, index }) => {
  219. return (
  220. <el-input
  221. style="padding: 5px;"
  222. type="number"
  223. value={row.qty}
  224. placeholder="请输入数量"
  225. onInput={e => (row.qty = e)}
  226. size="mini"
  227. clearable
  228. ></el-input>
  229. )
  230. }
  231. }
  232. ]
  233. },
  234. columns2() {
  235. return [
  236. {
  237. columnAttributes: {
  238. label: '物料名称',
  239. prop: 'name',
  240. width: 200
  241. }
  242. },
  243. {
  244. columnAttributes: {
  245. label: '物料编码',
  246. prop: 'number',
  247. width: 100
  248. }
  249. },
  250. {
  251. columnAttributes: {
  252. label: '旧物料编码',
  253. prop: 'oldNumber',
  254. width: 100
  255. }
  256. },
  257. {
  258. columnAttributes: {
  259. label: '规格型号',
  260. prop: 'specification'
  261. }
  262. }
  263. ]
  264. }
  265. },
  266. methods: {
  267. getMaterialListV2() {
  268. const params = []
  269. Object.keys(this.screenForm).forEach(k => {
  270. if (this.screenForm[k]) {
  271. params.push({
  272. param: `a.${k}`,
  273. compare: 'like',
  274. value: this.screenForm[k]
  275. })
  276. }
  277. })
  278. getMaterialListV2({
  279. pageNum: this.currentPage,
  280. pageSize: this.pageSize,
  281. params
  282. }).then(res => {
  283. this.k3List = res.data.records
  284. this.listTotal = res.data.total
  285. this.loading = false
  286. })
  287. },
  288. remoteMethod(query, type, name) {
  289. if (query !== '') {
  290. this.loading = true
  291. getMaterialListV2({
  292. pageNum: 1,
  293. pageSize: 100,
  294. params: [
  295. {
  296. param: `a.${type}`,
  297. compare: 'like',
  298. value: query
  299. }
  300. ]
  301. }).then(res => {
  302. this.k3List = res.data.records
  303. this.loading = false
  304. })
  305. } else {
  306. this.k3List = []
  307. }
  308. },
  309. setCheckeData(e, row) {
  310. if (e) {
  311. const item = this.k3List.find(k => k.id === e)
  312. row.specification = item.specification
  313. row.materialName = item.name
  314. row.materialId = item.id
  315. row.materialOldNumber = item.oldNumber
  316. } else {
  317. row.specification = ''
  318. row.materialName = ''
  319. row.materialId = ''
  320. row.materialOldNumber = ''
  321. }
  322. },
  323. handleAdd() {
  324. this.getMaterialListV2()
  325. this.isShowDialog = true
  326. // this.formData.items.push({
  327. // id: '',
  328. // itemRemark: '',
  329. // materialId: '',
  330. // materialName: '',
  331. // materialNumber: '',
  332. // materialOldNumber: '',
  333. // orderId: '',
  334. // projectNo: '',
  335. // qty: null,
  336. // specification: '',
  337. // unit: ''
  338. // })
  339. },
  340. selectable(row,index){
  341. for (let i = 0; i < this.formData.items.length; i++) {
  342. if (this.formData.items[i].materialId == row.id) {
  343. row.disabled = true
  344. }
  345. }
  346. if(row.disabled){
  347. return false
  348. }else{
  349. return true
  350. }
  351. },
  352. // 监听勾选变化
  353. selectionChange(data) {
  354. this.recordSelected = data
  355. },
  356. closeDialog() {
  357. this.isShowDialog = false
  358. },
  359. submitAddGoods() {
  360. this.formData.items =[ ...this.formData.items, ...this.recordSelected.map(k=>{
  361. return {
  362. qty: null,
  363. unit: '',
  364. orderId: '',
  365. projectNo: '',
  366. itemRemark: '',
  367. specification : k.specification,
  368. materialName : k.name,
  369. materialId : k.id,
  370. materialOldNumber : k.oldNumber,
  371. }
  372. })]
  373. this.k3List= []
  374. this.isShowDialog = false
  375. },
  376. // 更改列表当前页
  377. handleTableCurrentChange(val) {
  378. this.currentPage = val
  379. this.getMaterialListV2()
  380. },
  381. // 提交筛选表单
  382. submitScreenForm() {
  383. this.currentPage = 1
  384. this.getMaterialListV2()
  385. },
  386. // 重置筛选表单
  387. resetScreenForm() {
  388. this.$refs.screenForm.resetFields()
  389. this.currentPage = 1
  390. this.getMaterialListV2()
  391. }
  392. }
  393. }
  394. </script>
  395. <style lang="scss" scoped></style>