replaceRecordForm.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <div>
  3. <div>
  4. <h4>旧机型</h4>
  5. <el-divider />
  6. <zj-table :table-attributes="tableAttributes" :is-drop="true" :columns="oldColumns" :table-data="oldData" />
  7. <div style="margin: 20px 0; text-align: right">
  8. <el-button size="mini" @click="handleQuery">查询机型</el-button>
  9. </div>
  10. </div>
  11. <div>
  12. <h4>有效政策</h4>
  13. <el-divider />
  14. <zj-table
  15. :table-attributes="{
  16. ...tableAttributes, selectColumn: true
  17. }"
  18. :table-events="tableEvents"
  19. :is-drop="true"
  20. :columns="policyColumns"
  21. :table-data="policyList"
  22. />
  23. </div>
  24. <div>
  25. <h4>新机型</h4>
  26. <el-divider />
  27. <zj-table :table-attributes="tableAttributes" :is-drop="true" :columns="newColumns" :table-data="newData" />
  28. </div>
  29. <div style="margin: 20px 0;text-align: right;">
  30. <el-button type="primary" size="mini" @click="onClose">取消</el-button>
  31. <el-button type="primary" size="mini" @click="onSubmit">确定</el-button>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import { updateMaterialPolicy, getK3List, getList } from '@/api/policy_list'
  37. export default {
  38. props: {
  39. recordSelected: {
  40. type: Array,
  41. default: () => []
  42. }
  43. },
  44. data() {
  45. return {
  46. loading: false,
  47. oldData: [
  48. {
  49. name: '',
  50. number: '',
  51. specification: '',
  52. price: '',
  53. createBy: ''
  54. }
  55. ],
  56. k3List: [],
  57. newK3List: [],
  58. policyList: [],
  59. selectedData: [],
  60. newData: [
  61. {
  62. name: '',
  63. number: '',
  64. specification: ''
  65. }
  66. ],
  67. tableAttributes: {},
  68. tableEvents: {
  69. 'selection-change': this.selectionChange
  70. }
  71. }
  72. },
  73. computed: {
  74. oldColumns() {
  75. return [
  76. {
  77. columnAttributes: {
  78. label: '物料代码',
  79. prop: 'number'
  80. },
  81. render: (h, { column, row, index }) => {
  82. return (
  83. <div style='margin:0 10px'>
  84. <el-select
  85. style='width:100%'
  86. value={row.number}
  87. onInput={e => (row.number = e)}
  88. onChange={e => this.setCheckeData(e, 'old')}
  89. filterable
  90. size='mini'
  91. remote
  92. reserve-keyword
  93. placeholder='请输入关键词'
  94. remote-method={e => this.remoteMethod(e, 'number', 'old')}
  95. loading={this.loading}
  96. >
  97. {this.k3List.map(k => {
  98. return <el-option key={k.id} label={k.number} value={k.id}></el-option>
  99. })}
  100. </el-select>
  101. </div>
  102. )
  103. }
  104. },
  105. {
  106. columnAttributes: {
  107. label: '产品名称',
  108. prop: 'name'
  109. }
  110. },
  111. {
  112. columnAttributes: {
  113. label: '规格型号',
  114. prop: 'specification'
  115. },
  116. render: (h, { column, row, index }) => {
  117. return (
  118. <div style='margin:0 10px'>
  119. <el-select
  120. style='width:100%'
  121. value={row.specification}
  122. onInput={e => (row.specification = e)}
  123. onChange={e => this.setCheckeData(e, 'old')}
  124. filterable
  125. size='mini'
  126. remote
  127. reserve-keyword
  128. placeholder='请输入规格型号'
  129. remote-method={e => this.remoteMethod(e, 'specification', 'old')}
  130. loading={this.loading}
  131. >
  132. {this.k3List.map(k => {
  133. return <el-option key={k.id} label={k.specification} value={k.id}></el-option>
  134. })}
  135. </el-select>
  136. </div>
  137. )
  138. }
  139. },
  140. {
  141. columnAttributes: {
  142. label: '制单人',
  143. prop: 'createBy'
  144. },
  145. render: (h, { column, row, index }) => {
  146. return (
  147. <div style='margin:0 10px'>
  148. <el-input value={row.createBy}
  149. onInput={e => (row.createBy = e)} placeholder='请输入制单人' size='mini' clearable ></el-input>
  150. </div>
  151. )
  152. }
  153. },
  154. {
  155. columnAttributes: {
  156. label: '操作',
  157. prop: ''
  158. },
  159. render: (h, { column, row, index }) => {
  160. return (
  161. <div>
  162. <el-button
  163. type='text'
  164. size='default'
  165. onClick={() => {
  166. this.oldData = [
  167. {
  168. name: '',
  169. number: '',
  170. specification: ''
  171. }
  172. ]
  173. }}
  174. >
  175. 清空
  176. </el-button>
  177. </div>
  178. )
  179. }
  180. }
  181. ]
  182. },
  183. policyColumns() {
  184. return [
  185. {
  186. columnAttributes: {
  187. label: '政策编码',
  188. prop: 'code'
  189. }
  190. },
  191. {
  192. columnAttributes: {
  193. label: '政策名称',
  194. prop: 'title'
  195. }
  196. },
  197. {
  198. columnAttributes: {
  199. label: '政策类型',
  200. prop: 'type'
  201. },
  202. render: (h, { column, row, index }) => {
  203. return (
  204. <div>
  205. {row.type === 'PROVISION' ? '配提' : '限量'}
  206. </div>
  207. )
  208. }
  209. },
  210. {
  211. columnAttributes: {
  212. label: '状态',
  213. prop: 'status'
  214. },
  215. render: (h, { column, row, index }) => {
  216. return (
  217. <div>
  218. {row.status ? '有效' : '无效'}
  219. </div>
  220. )
  221. }
  222. },
  223. {
  224. columnAttributes: {
  225. label: '生效日期',
  226. prop: 'startTime'
  227. }
  228. },
  229. {
  230. columnAttributes: {
  231. label: '失效日期',
  232. prop: 'endTime'
  233. }
  234. },
  235. {
  236. columnAttributes: {
  237. label: '制单人',
  238. prop: 'createBy'
  239. }
  240. },
  241. {
  242. columnAttributes: {
  243. label: '操作',
  244. prop: ''
  245. },
  246. render: (h, { column, row, index }) => {
  247. return (
  248. <div>
  249. <el-button type='text' size='default' onClick={() => {
  250. this.policyList.splice(index, 1)
  251. }}>
  252. 删除
  253. </el-button>
  254. </div>
  255. )
  256. }
  257. }
  258. ]
  259. },
  260. newColumns() {
  261. return [
  262. {
  263. columnAttributes: {
  264. label: '物料代码',
  265. prop: 'number'
  266. },
  267. render: (h, { column, row, index }) => {
  268. return (
  269. <div style='margin:0 10px'>
  270. <el-select
  271. style='width:100%'
  272. value={row.number}
  273. onInput={e => (row.number = e)}
  274. onChange={e => this.setCheckeData(e)}
  275. filterable
  276. size='mini'
  277. remote
  278. reserve-keyword
  279. placeholder='请输入关键词'
  280. remote-method={e => this.remoteMethod(e, 'number')}
  281. loading={this.loading}
  282. >
  283. {this.newK3List.map(k => {
  284. return <el-option key={k.id} label={k.number} value={k.id}></el-option>
  285. })}
  286. </el-select>
  287. </div>
  288. )
  289. }
  290. },
  291. {
  292. columnAttributes: {
  293. label: '产品名称',
  294. prop: 'name'
  295. }
  296. },
  297. {
  298. columnAttributes: {
  299. label: '规格型号',
  300. prop: 'specification'
  301. },
  302. render: (h, { column, row, index }) => {
  303. return (
  304. <div style='margin:0 10px'>
  305. <el-select
  306. style='width:100%'
  307. value={row.specification}
  308. onInput={e => (row.specification = e)}
  309. onChange={e => this.setCheckeData(e)}
  310. filterable
  311. size='mini'
  312. remote
  313. reserve-keyword
  314. placeholder='请输入规格型号'
  315. remote-method={e => this.remoteMethod(e, 'specification')}
  316. loading={this.loading}
  317. >
  318. {this.newK3List.map(k => {
  319. return <el-option key={k.id} label={k.specification} value={k.id}></el-option>
  320. })}
  321. </el-select>
  322. </div>
  323. )
  324. }
  325. },
  326. {
  327. columnAttributes: {
  328. label: '操作',
  329. prop: ''
  330. },
  331. render: (h, { column, row, index }) => {
  332. return (
  333. <div>
  334. <el-button
  335. type='text'
  336. size='default'
  337. onClick={() => {
  338. this.newData = [
  339. {
  340. name: '',
  341. number: '',
  342. specification: ''
  343. }
  344. ]
  345. }}
  346. >
  347. 清空
  348. </el-button>
  349. </div>
  350. )
  351. }
  352. }
  353. ]
  354. }
  355. },
  356. mounted() {
  357. this.tableData = this.recordSelected
  358. },
  359. methods: {
  360. remoteMethod(query, type, name) {
  361. if (query !== '') {
  362. this.loading = true
  363. getK3List({
  364. pageNum: 1,
  365. pageSize: 100,
  366. number: type === 'number' ? query : '',
  367. oldNumber: '',
  368. specification: type === 'specification' ? query : ''
  369. }).then(res => {
  370. if (name) {
  371. this.k3List = res.data.records
  372. } else {
  373. this.newK3List = res.data.records
  374. }
  375. this.loading = false
  376. })
  377. } else {
  378. this.options = []
  379. }
  380. },
  381. setCheckeData(e, type) {
  382. if (type) {
  383. this.oldData[0].specification = e
  384. this.oldData[0].number = e
  385. if (e) {
  386. const k3Obj = this.findData(e, type)
  387. this.oldData[0].name = k3Obj.name
  388. }
  389. } else {
  390. this.newData[0].specification = e
  391. this.newData[0].number = e
  392. if (e) {
  393. const k3Obj = this.findData(e)
  394. this.newData[0].name = k3Obj.name
  395. }
  396. }
  397. },
  398. handleQuery() {
  399. const number = this.oldData[0].number
  400. const createBy = this.oldData[0].createBy
  401. if (!number && !createBy) {
  402. this.$errorMsg('旧机型内容不能为空')
  403. return
  404. }
  405. this.selectedData = []
  406. const specification = number && this.findData(number, 'old').specification
  407. getList({
  408. pageNum: 1,
  409. pageSize: -1,
  410. specification: specification,
  411. createBy
  412. }).then(res => {
  413. this.policyList = res.data.records
  414. })
  415. },
  416. selectionChange(data) {
  417. this.selectedData = data
  418. },
  419. onSubmit() {
  420. if (!this.selectedData.length) {
  421. this.$errorMsg('请选择有效政策')
  422. return
  423. }
  424. const policyIds = this.selectedData.map(k => k.id).join(',')
  425. const newMaterialId = this.newData[0].number
  426. const oldMaterialId = this.oldData[0].number
  427. if (!newMaterialId) {
  428. this.$errorMsg('新机型内容不能为空')
  429. return
  430. }
  431. updateMaterialPolicy({
  432. policyIds,
  433. newMaterialId,
  434. oldMaterialId
  435. }).then(res => {
  436. this.$successMsg('批量修改成功')
  437. this.onClose()
  438. })
  439. },
  440. findData(e, type) {
  441. if (type) {
  442. return this.k3List.find(k => k.id === e)
  443. } else {
  444. return this.newK3List.find(k => k.id === e)
  445. }
  446. },
  447. onClose() {
  448. this.$emit('close')
  449. }
  450. }
  451. }
  452. </script>
  453. <style lang="scss" scoped></style>