123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- <template>
- <div>
- <div>
- <h4>旧机型</h4>
- <el-divider />
- <zj-table :table-attributes="tableAttributes" :is-drop="true" :columns="oldColumns" :table-data="oldData" />
- <div style="margin: 20px 0; text-align: right">
- <el-button size="mini" @click="handleQuery">查询机型</el-button>
- </div>
- </div>
- <div>
- <h4>有效政策</h4>
- <el-divider />
- <zj-table
- :table-attributes="{
- ...tableAttributes, selectColumn: true
- }"
- :table-events="tableEvents"
- :is-drop="true"
- :columns="policyColumns"
- :table-data="policyList"
- />
- </div>
- <div>
- <h4>新机型</h4>
- <el-divider />
- <zj-table :table-attributes="tableAttributes" :is-drop="true" :columns="newColumns" :table-data="newData" />
- </div>
- <div style="margin: 20px 0;text-align: right;">
- <el-button type="primary" size="mini" @click="onClose">取消</el-button>
- <el-button type="primary" size="mini" @click="onSubmit">确定</el-button>
- </div>
- </div>
- </template>
- <script>
- import { updateMaterialPolicy, getK3List, getList } from '@/api/policy_list'
- export default {
- props: {
- recordSelected: {
- type: Array,
- default: () => []
- }
- },
- data() {
- return {
- loading: false,
- oldData: [
- {
- name: '',
- number: '',
- specification: '',
- price: '',
- createBy: ''
- }
- ],
- k3List: [],
- newK3List: [],
- policyList: [],
- selectedData: [],
- newData: [
- {
- name: '',
- number: '',
- specification: ''
- }
- ],
- tableAttributes: {},
- tableEvents: {
- 'selection-change': this.selectionChange
- }
- }
- },
- computed: {
- oldColumns() {
- return [
- {
- columnAttributes: {
- label: '物料代码',
- prop: 'number'
- },
- render: (h, { column, row, index }) => {
- return (
- <div style='margin:0 10px'>
- <el-select
- style='width:100%'
- value={row.number}
- onInput={e => (row.number = e)}
- onChange={e => this.setCheckeData(e, 'old')}
- filterable
- size='mini'
- remote
- reserve-keyword
- placeholder='请输入关键词'
- remote-method={e => this.remoteMethod(e, 'number', 'old')}
- loading={this.loading}
- >
- {this.k3List.map(k => {
- return <el-option key={k.id} label={k.number} value={k.id}></el-option>
- })}
- </el-select>
- </div>
- )
- }
- },
- {
- columnAttributes: {
- label: '产品名称',
- prop: 'name'
- }
- },
- {
- columnAttributes: {
- label: '规格型号',
- prop: 'specification'
- },
- render: (h, { column, row, index }) => {
- return (
- <div style='margin:0 10px'>
- <el-select
- style='width:100%'
- value={row.specification}
- onInput={e => (row.specification = e)}
- onChange={e => this.setCheckeData(e, 'old')}
- filterable
- size='mini'
- remote
- reserve-keyword
- placeholder='请输入规格型号'
- remote-method={e => this.remoteMethod(e, 'specification', 'old')}
- loading={this.loading}
- >
- {this.k3List.map(k => {
- return <el-option key={k.id} label={k.specification} value={k.id}></el-option>
- })}
- </el-select>
- </div>
- )
- }
- },
- {
- columnAttributes: {
- label: '制单人',
- prop: 'createBy'
- },
- render: (h, { column, row, index }) => {
- return (
- <div style='margin:0 10px'>
- <el-input value={row.createBy}
- onInput={e => (row.createBy = e)} placeholder='请输入制单人' size='mini' clearable ></el-input>
- </div>
- )
- }
- },
- {
- columnAttributes: {
- label: '操作',
- prop: ''
- },
- render: (h, { column, row, index }) => {
- return (
- <div>
- <el-button
- type='text'
- size='default'
- onClick={() => {
- this.oldData = [
- {
- name: '',
- number: '',
- specification: ''
- }
- ]
- }}
- >
- 清空
- </el-button>
- </div>
- )
- }
- }
- ]
- },
- policyColumns() {
- return [
- {
- columnAttributes: {
- label: '政策编码',
- prop: 'code'
- }
- },
- {
- columnAttributes: {
- label: '政策名称',
- prop: 'title'
- }
- },
- {
- columnAttributes: {
- label: '政策类型',
- prop: 'type'
- },
- render: (h, { column, row, index }) => {
- return (
- <div>
- {row.type === 'PROVISION' ? '配提' : '限量'}
- </div>
- )
- }
- },
- {
- columnAttributes: {
- label: '状态',
- prop: 'status'
- },
- render: (h, { column, row, index }) => {
- return (
- <div>
- {row.status ? '有效' : '无效'}
- </div>
- )
- }
- },
- {
- columnAttributes: {
- label: '生效日期',
- prop: 'startTime'
- }
- },
- {
- columnAttributes: {
- label: '失效日期',
- prop: 'endTime'
- }
- },
- {
- columnAttributes: {
- label: '制单人',
- prop: 'createBy'
- }
- },
- {
- columnAttributes: {
- label: '操作',
- prop: ''
- },
- render: (h, { column, row, index }) => {
- return (
- <div>
- <el-button type='text' size='default' onClick={() => {
- this.policyList.splice(index, 1)
- }}>
- 删除
- </el-button>
- </div>
- )
- }
- }
- ]
- },
- newColumns() {
- return [
- {
- columnAttributes: {
- label: '物料代码',
- prop: 'number'
- },
- render: (h, { column, row, index }) => {
- return (
- <div style='margin:0 10px'>
- <el-select
- style='width:100%'
- value={row.number}
- onInput={e => (row.number = e)}
- onChange={e => this.setCheckeData(e)}
- filterable
- size='mini'
- remote
- reserve-keyword
- placeholder='请输入关键词'
- remote-method={e => this.remoteMethod(e, 'number')}
- loading={this.loading}
- >
- {this.newK3List.map(k => {
- return <el-option key={k.id} label={k.number} value={k.id}></el-option>
- })}
- </el-select>
- </div>
- )
- }
- },
- {
- columnAttributes: {
- label: '产品名称',
- prop: 'name'
- }
- },
- {
- columnAttributes: {
- label: '规格型号',
- prop: 'specification'
- },
- render: (h, { column, row, index }) => {
- return (
- <div style='margin:0 10px'>
- <el-select
- style='width:100%'
- value={row.specification}
- onInput={e => (row.specification = e)}
- onChange={e => this.setCheckeData(e)}
- filterable
- size='mini'
- remote
- reserve-keyword
- placeholder='请输入规格型号'
- remote-method={e => this.remoteMethod(e, 'specification')}
- loading={this.loading}
- >
- {this.newK3List.map(k => {
- return <el-option key={k.id} label={k.specification} value={k.id}></el-option>
- })}
- </el-select>
- </div>
- )
- }
- },
- {
- columnAttributes: {
- label: '操作',
- prop: ''
- },
- render: (h, { column, row, index }) => {
- return (
- <div>
- <el-button
- type='text'
- size='default'
- onClick={() => {
- this.newData = [
- {
- name: '',
- number: '',
- specification: ''
- }
- ]
- }}
- >
- 清空
- </el-button>
- </div>
- )
- }
- }
- ]
- }
- },
- mounted() {
- this.tableData = this.recordSelected
- },
- methods: {
- remoteMethod(query, type, name) {
- if (query !== '') {
- this.loading = true
- getK3List({
- pageNum: 1,
- pageSize: 100,
- number: type === 'number' ? query : '',
- oldNumber: '',
- specification: type === 'specification' ? query : ''
- }).then(res => {
- if (name) {
- this.k3List = res.data.records
- } else {
- this.newK3List = res.data.records
- }
- this.loading = false
- })
- } else {
- this.options = []
- }
- },
- setCheckeData(e, type) {
- if (type) {
- this.oldData[0].specification = e
- this.oldData[0].number = e
- if (e) {
- const k3Obj = this.findData(e, type)
- this.oldData[0].name = k3Obj.name
- }
- } else {
- this.newData[0].specification = e
- this.newData[0].number = e
- if (e) {
- const k3Obj = this.findData(e)
- this.newData[0].name = k3Obj.name
- }
- }
- },
- handleQuery() {
- const number = this.oldData[0].number
- const createBy = this.oldData[0].createBy
- if (!number && !createBy) {
- this.$errorMsg('旧机型内容不能为空')
- return
- }
- this.selectedData = []
- const specification = number && this.findData(number, 'old').specification
- getList({
- pageNum: 1,
- pageSize: -1,
- specification: specification,
- createBy
- }).then(res => {
- this.policyList = res.data.records
- })
- },
- selectionChange(data) {
- this.selectedData = data
- },
- onSubmit() {
- if (!this.selectedData.length) {
- this.$errorMsg('请选择有效政策')
- return
- }
- const policyIds = this.selectedData.map(k => k.id).join(',')
- const newMaterialId = this.newData[0].number
- const oldMaterialId = this.oldData[0].number
- if (!newMaterialId) {
- this.$errorMsg('新机型内容不能为空')
- return
- }
- updateMaterialPolicy({
- policyIds,
- newMaterialId,
- oldMaterialId
- }).then(res => {
- this.$successMsg('批量修改成功')
- this.onClose()
- })
- },
- findData(e, type) {
- if (type) {
- return this.k3List.find(k => k.id === e)
- } else {
- return this.newK3List.find(k => k.id === e)
- }
- },
- onClose() {
- this.$emit('close')
- }
- }
- }
- </script>
- <style lang="scss" scoped></style>
|