<template>
  <a-modal
    :title="title"
    :width="modelStyle.width"
    :visible="visible"
    :bodyStyle="bodyStyle"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    okText="确定关联"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-card :bordered="false">
        <!-- 查询区域 -->

        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">

        </div>

        <!-- table区域-begin -->
        <div>

          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:'radio'}"
            @change="handleTableChange">

          </a-table>
        </div>
      </a-card>
    </a-spin>
  </a-modal>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { httpAction, getAction,putAction } from '@/api/manage'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: 'HlgPaymentRequirementModal',
    mixins: [JeecgListMixin],
    components: {
      JDate

    },
    data() {
      return {
        title: '',
        bodyStyle: {
          padding: '0',
          height: (window.innerHeight * 0.62) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '60%',
          style: { top: '10px' },
          fullScreen: false
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        // 表头
        columns: [
          {
            title: '导入时间',
            align: 'left',
            dataIndex: 'createTime'
          },

          {
            title: '付款单号',
            align: 'left',
            dataIndex: 'paymentCode'
          },
          {
            title: '金额',
            align: 'left',
            dataIndex: 'totalPayment'
          }
        ],
        confirmLoading: false,
        dataSource: [],
        url: {
          list: '/hlgpayment/hlgPayment/relatePaymentList',
          edit: '/hlgcpmanager/hlgCpAccountDetail/relatePayment'
        }

      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.onClearSelected();
        this.model = Object.assign({}, record)
        this.visible = true
        this.loadData(1)
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams()//查询条件
        params.companyId = this.model.companyId;
        this.loading = true
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      close() {
        this.visible = false
      },
      handleOk() {
        if (this.selectionRows.length) {
          const that = this
          that.confirmLoading = true
          let formData = this.model;
          formData.paymentId = this.selectionRows[0].id;
          putAction(this.url.edit, formData).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })
        } else {
          this.$message.warning('请选择关联的付款')
        }
      },
      handleCancel() {
        this.close()
      },
      changeItem() {
        this.loadData()
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      },
      modalFormOk(){
        this.$emit('ok')
        this.close()
      }
    }
  }
</script>