ContractParameterModal.vue 4.33 KB
<template>
  <a-modal :title="title" :width="1000" :centered='true' :visible="visible" :confirmLoading="confirmLoading" @ok="handleSubmit" @cancel="handleCancel" :maskClosable="false" cancelText="关闭" style="top:20px;">
    <a-table rowKey="id" v-if="lookShow==1" :columns="columns" :dataSource="dataSource" :pagination="false" :disabled="true" />
    <a-table rowKey="id" v-else-if="lookShow==2" :rowSelection="rowSelection" :columns="columns" :dataSource="dataSource" :pagination="false" :disabled="true" />
  </a-modal>
</template>

<script>
import { postAction,getAction } from '@/api/configApi'
export default {
  name: "PasswordModal",
  data () {
    return {
      lookShow: 3, // 解决缓存
      visible: false,
      title: '',
      confirmLoading: false,
      columns: [
        {
          title: '参数编号',
          dataIndex: 'contractParamNo',
        },
        {
          title: '参数描述',
          dataIndex: 'deacription',
        },
        {
          title: '参数替代符标识',
          dataIndex: 'dynamicVariable',
        },
      ],
      model: {},
      dataSource: [],
      selectData: [],
      selectedRows: [],
      selectedRowKeys: [],
      concatData: [],
    }
  },
  created () {
    console.log("created");
  },
  computed: {
    rowSelection () {
      const { selectedRowKeys } = [];
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRowKeys = selectedRowKeys;
          this.selectedRows = selectedRows;
        },
        onSelect: (record) => {
          this.selectData.map(v => {
            if (record.select && v.id == record.id) {
              v.deleteFlag = !v.deleteFlag
            }
          })
          this.concatData = this.setArrObj(this.selectedRows.concat(this.selectData))
          console.log(this.concatData)
        },
        onSelectAll: (selected) => {
          this.selectData.map(v => {
            v.deleteFlag = !selected
          })
          this.concatData = this.setArrObj(this.selectedRows.concat(this.selectData))
          console.log(this.concatData)
        },
        onSelectInvert: (selected) => {
          this.selectData.map(v => {
            v.deleteFlag = !selected
          })
          this.concatData = this.setArrObj(this.selectedRows.concat(this.selectData))
          console.log(this.concatData)
        },
        getCheckboxProps: record => (
          console.log(record.select), {
            props: {
              defaultChecked: record.select === true,
            },
          }),
      };
    },
  },
  watch: {
    lookShow (val) {
      this.lookShow = val
    }
  },
  methods: {
    edit (record, type, recordNo) { // recordType => 类型   type 1.查看 2.增加 3.修改  recordNo =>编号
      console.log(record)
      this.lookShow = 2
      this.dataSource = record
      this.selectData = this.dataSource.filter((item) => {  // 修改已选中带过来的数据
        return item.select
      })
      this.concatData = this.selectData
      if (type == 1) {
        this.lookShow = 1
        let _p = '/config/admin/queryContractParam?contractTemplateNo=' + recordNo;
        getAction(_p).then(res => {
          console.log(res)
          if (res.status.statusCode == 0) {
            this.dataSource = res.result
            console.log(this.selectData)
          } else {
            this.$message.warning(res.status.statusReason);
          }
        })
      }
      type == 1 ? this.lookShow = true : false;
      this.visible = true;
    },
    close () {
      this.$emit('close');
      this.visible = false;
      this.disableSubmit = false;
      this.selectedRole = [];
    },
    handleSubmit () {
      let contractParamList = [];
      this.concatData.map(v => {
        if (v.deleteFlag) {
          contractParamList.push({ 'contractParamNo': v.contractParamNo, 'deleteFlag': 1 })
        } else {
          contractParamList.push({ 'contractParamNo': v.contractParamNo })
        }
      })
      console.log(contractParamList)
      this.lookShow = 3;
      this.$emit('transmitData', contractParamList);
      this.visible = false;
    },
    handleCancel () {
      this.lookShow = 3;
      this.close()
    },
    setArrObj (data) {
      let obj = {};
      return data.reduce((cur, next) => {
        obj[next.id] ? "" : obj[next.id] = true && cur.push(next);
        return cur;
      }, [])
    },
  }
}
</script>