model.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. min={1}
  226. onInput={e => (row.qty = e)}
  227. size="mini"
  228. clearable
  229. ></el-input>
  230. )
  231. }
  232. }
  233. ]
  234. },
  235. columns2() {
  236. return [
  237. {
  238. columnAttributes: {
  239. label: '物料名称',
  240. prop: 'name',
  241. width: 200
  242. }
  243. },
  244. {
  245. columnAttributes: {
  246. label: '物料编码',
  247. prop: 'number',
  248. width: 100
  249. }
  250. },
  251. {
  252. columnAttributes: {
  253. label: '旧物料编码',
  254. prop: 'oldNumber',
  255. width: 100
  256. }
  257. },
  258. {
  259. columnAttributes: {
  260. label: '规格型号',
  261. prop: 'specification'
  262. }
  263. }
  264. ]
  265. }
  266. },
  267. methods: {
  268. getMaterialListV2() {
  269. const params = []
  270. Object.keys(this.screenForm).forEach(k => {
  271. if (this.screenForm[k]) {
  272. params.push({
  273. param: `a.${k}`,
  274. compare: 'like',
  275. value: this.screenForm[k]
  276. })
  277. }
  278. })
  279. getMaterialListV2({
  280. pageNum: this.currentPage,
  281. pageSize: this.pageSize,
  282. params
  283. }).then(res => {
  284. this.k3List = res.data.records
  285. this.listTotal = res.data.total
  286. this.loading = false
  287. })
  288. },
  289. remoteMethod(query, type, name) {
  290. if (query !== '') {
  291. this.loading = true
  292. getMaterialListV2({
  293. pageNum: 1,
  294. pageSize: 100,
  295. params: [
  296. {
  297. param: `a.${type}`,
  298. compare: 'like',
  299. value: query
  300. }
  301. ]
  302. }).then(res => {
  303. this.k3List = res.data.records
  304. this.loading = false
  305. })
  306. } else {
  307. this.k3List = []
  308. }
  309. },
  310. setCheckeData(e, row) {
  311. if (e) {
  312. const item = this.k3List.find(k => k.id === e)
  313. row.specification = item.specification
  314. row.materialName = item.name
  315. row.materialId = item.id
  316. row.materialOldNumber = item.oldNumber
  317. } else {
  318. row.specification = ''
  319. row.materialName = ''
  320. row.materialId = ''
  321. row.materialOldNumber = ''
  322. }
  323. },
  324. handleAdd() {
  325. this.getMaterialListV2()
  326. this.isShowDialog = true
  327. // this.formData.items.push({
  328. // id: '',
  329. // itemRemark: '',
  330. // materialId: '',
  331. // materialName: '',
  332. // materialNumber: '',
  333. // materialOldNumber: '',
  334. // orderId: '',
  335. // projectNo: '',
  336. // qty: null,
  337. // specification: '',
  338. // unit: ''
  339. // })
  340. },
  341. selectable(row,index){
  342. for (let i = 0; i < this.formData.items.length; i++) {
  343. if (this.formData.items[i].materialId == row.id) {
  344. row.disabled = true
  345. }
  346. }
  347. if(row.disabled){
  348. return false
  349. }else{
  350. return true
  351. }
  352. },
  353. // 监听勾选变化
  354. selectionChange(data) {
  355. this.recordSelected = data
  356. },
  357. closeDialog() {
  358. this.isShowDialog = false
  359. },
  360. submitAddGoods() {
  361. this.formData.items =[ ...this.formData.items, ...this.recordSelected.map(k=>{
  362. return {
  363. qty: null,
  364. unit: '',
  365. orderId: '',
  366. projectNo: '',
  367. itemRemark: '',
  368. specification : k.specification,
  369. materialName : k.name,
  370. materialId : k.id,
  371. materialOldNumber : k.oldNumber,
  372. }
  373. })]
  374. this.k3List= []
  375. this.isShowDialog = false
  376. },
  377. // 更改列表当前页
  378. handleTableCurrentChange(val) {
  379. this.currentPage = val
  380. this.getMaterialListV2()
  381. },
  382. // 提交筛选表单
  383. submitScreenForm() {
  384. this.currentPage = 1
  385. this.getMaterialListV2()
  386. },
  387. // 重置筛选表单
  388. resetScreenForm() {
  389. this.$refs.screenForm.resetFields()
  390. this.currentPage = 1
  391. this.getMaterialListV2()
  392. }
  393. }
  394. }
  395. </script>
  396. <style lang="scss" scoped></style>