<template>
  <a-modal
    :title="title"
    :width="modelStyle.width"
    :visible="visible"
    :bodyStyle="bodyStyle"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    :footer="null"
    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"
            @change="handleTableChange">

            <span slot="action" slot-scope="text, record">
              <a @click="handledelete(record)" v-has="'platform:subcontractor:delete'">删除</a>
            </span>

            <span slot="action1" slot-scope="text, record">
               <a @click="uploadContract(record)"  v-has="'userSubcontractor:subcontractorManager'">{{record.workContract ? '已上传':'未上传'}}</a>

            </span>


            <span slot="action2" slot-scope="text, record">
              <template v-if="record.isAutoRenew === 0 && text">
                <template v-if="record.contractStatus == 1">
                  <span style="color: #FF7312">{{text.length > 10 ? text.substring(0,10) : text}}(即将到期)</span>
                </template>
                <template v-else-if="record.contractStatus == 2">
                  <span style="color: #F01B1B">{{text.length > 10 ? text.substring(0,10) : text}}(已到期)</span>
                </template>
                <template v-else>
                  {{text.length > 10 ? text.substring(0,10) : text}}
                </template>
              </template>
              <template v-else>
                 --
              </template>
            </span>


          </a-table>
        </div>
     <HlgUserSubcontractorContract ref="contractModal" @ok="modalFormOk"></HlgUserSubcontractorContract>
      </a-card>
    </a-spin>
    <div class="drawer-bootom-button">
     <a-button class="ant-btn ant-btn-primary"  @click="handleCancel">关闭</a-button>
    </div>
  </a-modal>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { httpAction ,getAction,putAction,deleteAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import { filterObj } from '@/utils/util'
  import HlgUserSubcontractorContract from './HlgUserSubcontractorContract'


  export default {
    name: "HlgUserSubcontractor",
    mixins: [JeecgListMixin],
    components: {
      HlgUserSubcontractorContract
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        bodyStyle: {
          padding: '0',
          height: (window.innerHeight * 0.66) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '76%',
          style: { top: '20px' },
          fullScreen: false
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        options: [{
          value: '',
          label: '',
          isLeaf: false
        }],
        // 查询条件
        queryParam: {
          subcontractorName: '',
        },
        // 表头
        columns: [
          {
            title: '服务商',
            align: 'left',
            dataIndex: 'name'
          },
          {
            title: '合同开始时间',
            align: 'left',
            dataIndex: 'startDate',
            customRender:function (text) {
                return !text?"--":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title: '合同结束时间',
            align: 'left',
            dataIndex: 'endDate',
            scopedSlots: { customRender: 'action2' }
          },
          {
            title: '走款情况',
            align: 'left',
            dataIndex: 'isPayment',
            customRender:function (text,record) {
              if(record.isPayment){
                return "已走款:"+record.minPaymentTime+'~'+record.maxPaymentTime
              }else{
                return "未走款"
              }
            }
          },
          {
            title: '用户合同',
            align: 'left',
            dataIndex: 'workContract',
            scopedSlots: { customRender: 'action1' }
          },
          // {
          //   title: '操作',
          //   align: 'left',
          //   scopedSlots: { customRender: 'action' }
          // },
        ],
        platformId: 0,
        userId: 0,
        confirmLoading: false,
        url: {
          list: "/hlgcompany/hlgCompany/userSubcontractorList",
        }
     
      }
    },
    created () {

    },
    methods: {
      getQueryParams() {
        var param = Object.assign({}, this.queryParam, this.isorter)
        param.field = this.getQueryField()
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        param.platformId = this.platformId;
        return filterObj(param)
      },
      edit (record) {
        this.model = Object.assign({}, record)
        this.platformId = record.platformId;
        this.userId = record.id;
        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.id= this.userId
        this.loading = true
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total;
            console.log(  res.result.records[0].workContract)
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.close()
      },
      handleCancel () {
        this.close()
      },
      modalFormOk(){
        this.loadData(1)
      },
      //上传合同
      uploadContract(record){
        let recordNew = {};
        recordNew.userId = this.userId;
        recordNew.subcontractorId = record.id;
        recordNew.isPayment=record.isPayment
        recordNew.minPaymentTime=record.minPaymentTime
        recordNew.maxPaymentTime=record.maxPaymentTime
        this.$refs.contractModal.edit(recordNew)
        this.$refs.contractModal.title = '用户合同--'+record.name
        this.$refs.contractModal.disableSubmit = false
      },


    }
  }
</script>
<style>
  .drawer-bootom-button {
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }
  .avatar-uploader > .ant-upload {
    width: 104px;
    height: 104px;
  }

  .ant-upload-select-picture-card i {
    font-size: 49px;
    color: #999;
  }

  .ant-upload-select-picture-card .ant-upload-text {
    margin-top: 8px;
    color: #666;
  }

</style>