<template>
  <a-modal
    :title="title"
    :width="modelStyle.width"
    :bodyStyle="bodyStyle"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    :footer="null">



    <a-card :bordered="false">
      <div class="table-operator">
        <a-button @click="handleAddInfo()" type="primary" icon="plus">新增</a-button>
      </div>
      <!-- table区域-begin -->
      <div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange">


        <span slot="action" slot-scope="text, record">
          <a @click="handleEditSub(record)" >编辑</a>

              <a-divider type="vertical" />
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>


        </span>

          <span slot="action3" slot-scope="text, record">
                <a @click="viewsubcontract(record)" > 查看</a>
            </span>


        </a-table>
      </div>

<hlw-cp-subcontractor-modal ref="modalForm" @ok="modalFormOk"></hlw-cp-subcontractor-modal>
<hlw-view-contract-modal ref="hlgViewContractForm"></hlw-view-contract-modal>
    </a-card>

  </a-modal>
</template>
<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction, deleteAction, putAction, postAction } from '@/api/manage'
  import HlwCpSubcontractorModal from './HlwCpSubcontractorModal'
  import HlwViewContractModal from './HlwViewContractModal'





  export default {
    name: 'HlwCpSubSubcontractList',
    mixins: [JeecgListMixin],
    components: {
      HlwViewContractModal,
      HlwCpSubcontractorModal


    },
    data() {
      return {
        description: '合同管理',
        headers: {},
        fileList: [],
        form: this.$form.createForm(this),
        title: '操作',
        bodyStyle: {
          padding: '0',
          height: (window.innerHeight * 0.66) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '80%',
          style: { top: '20px' },
          fullScreen: false
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        accept: '.pdf',
        confirmLoading: false,
        validatorRules: {},
        // 表头
        columns: [
          {
            title: '费率',
            align: 'center',
            dataIndex: 'serviceRate',
            customRender(text,record) {
              return text+"%"
            }

          },
          {
            title: '合同有效期',
            align: 'center',
            dataIndex: 'startDate',
            customRender(text,record) {
              return record.startDate+"~"+record.endDate
            }
          },
          {
            title: '合同文件',
            align: 'center',
            dataIndex: 'subcontract',
            scopedSlots: { customRender: 'action3' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          },


        ],
        url: {
          list: '/wisdom/hlwCpSubcontractor/subtractList',
          delete: '/wisdom/hlwCpSubcontractor/delete',
          imgerver: window._CONFIG['imgDomainOssURL']
        },
        dictOptions: {}
      }
    },


    computed: {},
    methods: {
      close() {
        this.visible = false
      },
      edit(record) {
        this.form.resetFields()
        this.model = Object.assign({}, record);
        this.visible = true
        this.loadData()
      },
      handleOk() {
        this.close()
        this.visible = false
      },
      handleCancel() {
        this.close()
      },



      loadData() {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }

        this.loading = true
        getAction(this.url.list, {subcontractorId:this.model.id}).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
        })
      },




      viewsubcontract(record){
        if(record.subcontract === null || record.subcontract === ''){
          this.$message.warning('该合同为线下合同,不支持预览')
          return
        }
        this.$refs.hlgViewContractForm.edit(record.subcontract,null);
        this.$refs.hlgViewContractForm.title = '查看合同'
        this.$refs.hlgViewContractForm.disableSubmit = false
        this.$refs.hlgViewContractForm.contractName = '外包合同';
      },


      handleAddInfo(){
        var record={}
        record.subcontractorId=this.model.id
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '新增'
        this.$refs.modalForm.disableSubmit = false
      },
      modalFormOk(){
        this.loadData()
      },
      handleEditSub(record){
        record.subcontractorId=this.model.id
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '编辑'
        this.$refs.modalForm.disableSubmit = false
      },


    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
<style lang="scss" scoped>

</style>