cancal.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <div>
  3. <div style="margin-bottom: 20px">
  4. <el-button
  5. size="mini"
  6. type="primary"
  7. @click="()=>{
  8. tableData.push({
  9. name: '',
  10. number: '',
  11. specification: ''
  12. })
  13. }"
  14. >添加</el-button>
  15. </div>
  16. <zj-table :table-attributes="tableAttributes" :is-drop="true" :columns="columns" :table-data="tableData" />
  17. <!-- <div style="margin: 20px 0; text-align: right">
  18. <el-button size="mini" @click="handleQuery">查询机型</el-button>
  19. </div> -->
  20. <!-- <div style="margin-top:20px ;">
  21. <zj-table
  22. :table-attributes="{
  23. // ...tableAttributes, selectColumn: true
  24. }"
  25. :table-events="tableEvents"
  26. :is-drop="true"
  27. :columns="policyColumns"
  28. :table-data="policyList"
  29. />
  30. </div> -->
  31. <div style="margin: 20px 0; text-align: right">
  32. <el-button type="primary" size="mini" @click="onClose">取消</el-button>
  33. <el-button type="primary" size="mini" @click="onSubmit">确定</el-button>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import { cancalMaterialPolicy, getList } from '@/api/policy_list'
  39. import { getMaterialListV2 } from '@/api/basic_data/material'
  40. export default {
  41. props: {
  42. recordSelected: {
  43. type: Array,
  44. default: () => []
  45. }
  46. },
  47. data() {
  48. return {
  49. loading: false,
  50. tableData: [
  51. {
  52. id: '',
  53. name: '',
  54. number: '',
  55. specification: ''
  56. }
  57. ],
  58. k3List: [],
  59. newK3List: [],
  60. policyList: [],
  61. selectedData: [],
  62. tableAttributes: {},
  63. tableEvents: {}
  64. }
  65. },
  66. computed: {
  67. columns() {
  68. return [
  69. {
  70. columnAttributes: {
  71. label: '物料代码',
  72. prop: 'number'
  73. },
  74. render: (h, { column, row, index }) => {
  75. return (
  76. <div style='margin:0 10px'>
  77. <el-select
  78. style='width:100%'
  79. value={row.number}
  80. onInput={e => (row.number = e)}
  81. onChange={e => this.setCheckeData(e, index)}
  82. filterable
  83. size='mini'
  84. remote
  85. reserve-keyword
  86. placeholder='请输入关键词'
  87. remote-method={e => this.remoteMethod(e, 'number')}
  88. loading={this.loading}
  89. >
  90. {this.k3List.map(k => {
  91. return <el-option key={k.id} label={k.number} value={k.id}></el-option>
  92. })}
  93. </el-select>
  94. </div>
  95. )
  96. }
  97. },
  98. {
  99. columnAttributes: {
  100. label: '产品名称',
  101. prop: 'name'
  102. },
  103. render: (h, { column, row, index }) => {
  104. return (
  105. <div style='margin:0 10px'>
  106. <el-select
  107. style='width:100%;margin:5px 0'
  108. value={row.name}
  109. onInput={e => (row.name = e)}
  110. onChange={e => this.setCheckeData(e, index)}
  111. filterable
  112. size='mini'
  113. remote
  114. reserve-keyword
  115. placeholder='请输入关键词'
  116. remote-method={e => this.remoteMethod(e, 'name')}
  117. loading={this.loading}
  118. >
  119. {this.k3List.map(k => {
  120. return <el-option key={k.id} label={k.name} value={k.id}></el-option>
  121. })}
  122. </el-select>
  123. </div>
  124. )
  125. }
  126. },
  127. {
  128. columnAttributes: {
  129. label: '规格型号',
  130. prop: 'specification'
  131. },
  132. render: (h, { column, row, index }) => {
  133. return (
  134. <div style='margin:0 10px'>
  135. <el-select
  136. style='width:100%'
  137. value={row.specification}
  138. onInput={e => (row.specification = e)}
  139. onChange={e => this.setCheckeData(e, index)}
  140. filterable
  141. size='mini'
  142. remote
  143. reserve-keyword
  144. placeholder='请输入规格型号'
  145. remote-method={e => this.remoteMethod(e, 'specification')}
  146. loading={this.loading}
  147. >
  148. {this.k3List.map(k => {
  149. return <el-option key={k.id} label={k.specification} value={k.id}></el-option>
  150. })}
  151. </el-select>
  152. </div>
  153. )
  154. }
  155. },
  156. {
  157. columnAttributes: {
  158. label: '操作',
  159. prop: ''
  160. },
  161. render: (h, { column, row, index }) => {
  162. return (
  163. <div>
  164. <el-button type='text' size='default' onClick={() => {
  165. this.tableData.splice(index, 1)
  166. }}>
  167. 删除
  168. </el-button>
  169. </div>
  170. )
  171. }
  172. }
  173. ]
  174. },
  175. policyColumns() {
  176. return [
  177. {
  178. columnAttributes: {
  179. label: '政策编码',
  180. prop: 'code'
  181. }
  182. },
  183. {
  184. columnAttributes: {
  185. label: '政策名称',
  186. prop: 'title'
  187. }
  188. },
  189. {
  190. columnAttributes: {
  191. label: '政策类型',
  192. prop: 'type'
  193. },
  194. render: (h, { column, row, index }) => {
  195. return (
  196. <div>
  197. {row.type === 'PROVISION' ? '配提' : '限量'}
  198. </div>
  199. )
  200. }
  201. },
  202. {
  203. columnAttributes: {
  204. label: '状态',
  205. prop: 'status'
  206. },
  207. render: (h, { column, row, index }) => {
  208. return (
  209. <div>
  210. {row.status ? '有效' : '无效'}
  211. </div>
  212. )
  213. }
  214. },
  215. {
  216. columnAttributes: {
  217. label: '生效日期',
  218. prop: 'startTime'
  219. }
  220. },
  221. {
  222. columnAttributes: {
  223. label: '失效日期',
  224. prop: 'endTime'
  225. }
  226. },
  227. {
  228. columnAttributes: {
  229. label: '制单人',
  230. prop: 'createBy'
  231. }
  232. },
  233. {
  234. columnAttributes: {
  235. label: '操作',
  236. prop: ''
  237. },
  238. render: (h, { column, row, index }) => {
  239. return (
  240. <div>
  241. <el-button type='text' size='default' onClick={() => {
  242. this.policyList.splice(index, 1)
  243. }}>
  244. 删除
  245. </el-button>
  246. </div>
  247. )
  248. }
  249. }
  250. ]
  251. }
  252. },
  253. mounted() {
  254. this.policyList = this.recordSelected
  255. },
  256. methods: {
  257. remoteMethod(query, type, name) {
  258. if (query !== '') {
  259. this.loading = true
  260. getMaterialListV2({
  261. pageNum: 1,
  262. pageSize: 100,
  263. params: [
  264. {
  265. 'param': `a.${type}`,
  266. 'compare': 'like',
  267. 'value': query
  268. }
  269. ]
  270. }).then(res => {
  271. this.k3List = res.data.records
  272. this.loading = false
  273. })
  274. } else {
  275. this.options = []
  276. }
  277. },
  278. setCheckeData(e, index) {
  279. if (e) {
  280. const k3Obj = this.findData(e)
  281. this.tableData[index].specification = k3Obj.specification
  282. this.tableData[index].number = k3Obj.number
  283. this.tableData[index].name = k3Obj.name
  284. this.tableData[index].id = k3Obj.id
  285. }
  286. },
  287. handleQuery(number) {
  288. if (!number) {
  289. this.$errorMsg('物料不能为空')
  290. return
  291. }
  292. const specification = number && this.findData(number).specification
  293. getList({
  294. pageNum: 1,
  295. pageSize: -1,
  296. specification: specification
  297. }).then(res => {
  298. const data = [...this.policyList, ...res.data.records]
  299. var result = []
  300. const obj = {}
  301. for (let i = 0; i < data.length; i++) {
  302. if (!obj[data[i].id]) {
  303. result.push(data[i])
  304. obj[data[i].id] = true
  305. }
  306. }
  307. this.policyList = result
  308. })
  309. },
  310. findData(e, type) {
  311. return this.k3List.find(k => k.id === e)
  312. },
  313. onSubmit() {
  314. if (!this.tableData.length) {
  315. this.$errorMsg('物料不能为空')
  316. return
  317. }
  318. const policyIds = this.policyList.map(k => k.id).join(',')
  319. const materialIds = this.tableData.map(k => k.id).join(',')
  320. cancalMaterialPolicy({
  321. policyIds,
  322. materialIds
  323. }).then(res => {
  324. this.$successMsg('批量修改成功')
  325. this.onClose()
  326. })
  327. },
  328. onClose() {
  329. this.$emit('close')
  330. }
  331. }
  332. }
  333. </script>
  334. <style lang="scss" scoped></style>