<template>
  <a-modal
    :title="title"
    :width="modelStyle.width"
    :visible="visible"
    :bodyStyle="bodyStyle"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :maskClosable="false"
    @cancel="handleCancel"
    cancelText="关闭"
    :footer="null">
    <a-spin :spinning="confirmLoading">
      <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <a-form-item label="创客">
                  <a-input placeholder="请输入创客" v-model="queryParam.userNmae"></a-input>
                </a-form-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button type="primary" icon="download" @click="handleExportXls('出账信息')" v-has="'require:exportOut'">导出</a-button>
        </div>

        <!-- table区域-begin -->
        <div>
          <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
            <!--<i class="anticon anticon-info-circle ant-alert-icon"></i> 选中金额:<a style="font-weight: 600">{{selectedPrice}}</a>-->
            <!--<a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
          <!--</div>-->

          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :loading="loading"
            :pagination="ipagination"
            @change="handleTableChange">
            <span slot="action" slot-scope="text, record">
            <a @click="viewServiceContract(record)" v-has="'require:viewServiceContract'">承揽合同-{{record.userNmae}}</a>

            </span>

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

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { httpAction, getAction,putAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import { filterObj } from '@/utils/util'
  import qs from 'qs';
  import { ACCESS_TOKEN } from '@/store/mutation-types'
  const hanpayment = (params) => putAction('/hwpayment/hwPaymentDetail/handPayment', params)
  const hanbackpay = (params) => putAction('/hwpayment/hwPaymentDetail/handBackpay', params)

  export default {
    name: 'HwPaymentOutModal',
    mixins: [JeecgListMixin],
    components: {
      JDate
    },
    data() {
      return {
        description: 'hw_payment_detail管理页面',
        bodyStyle: {
          padding: '0',
          height: (window.innerHeight * 0.66) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '76%',
          style: { top: '20px' },
          fullScreen: false
        },
        // 查询条件
        queryParam: {
          createTimeRange: [],
          paymentId: 0
        },
        // 表头
        columns: [
          {
            title: '业务单号',
            align: 'center',
            dataIndex: 'paymentCode'
          },
          {
            title: '创客',
            align: 'center',
            dataIndex: 'userNmae'
          },
          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'idcardNumber'
          },
          {
            title: '到账金额',
            align: 'center',
            dataIndex: 'netPayment'
          },
          {
            title: '税费',
            align: 'center',
            dataIndex: 'taxFee'
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'status_dictText'
          },
          {
            title: '时间',
            align: 'center',
            dataIndex: 'paymentTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        title: '操作',
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        paymentId:0,
        confirmLoading: false,
        url: {
          list: '/hwpayment/hwPaymentDetail/list',
          delete: '/hwpayment/hwPaymentDetail/delete',
          deleteBatch: '/hwpayment/hwPaymentDetail/deleteBatch',
          exportXlsUrl: '/hwpayment/hwPaymentDetail/exportXls',
          importExcelUrl: 'hwpayment/hwPaymentDetail/importExcel',
        },
        dictOptions: {},
        selectedPrice:0,
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      getQueryParams() {
        console.log(this.queryParam.createTimeRange)
        var param = Object.assign({}, this.queryParam, this.isorter)
        param.field = this.getQueryField()
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        param.paymentId = this.paymentId;
        delete param.createTimeRange // 时间参数不传递后台
        return filterObj(param)
      },
      loadData() {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        var params = this.getQueryParams()//查询条件
        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
        })
      },
      initDictConfig() {
      },
      add() {
        this.edit({})
      },
      edit(record) {
        this.model = Object.assign({}, record)
        this.queryParam.paymentId = record.paymentId
        this.paymentId = record.paymentId
        this.visible = true
        this.loadData()
      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      handleOk() {
        this.$emit('ok')
        this.visible = false
      },
      handleCancel() {
        this.close()
      },
      popupCallback(row) {
        this.form.setFieldsValue(pick(row, 'paymentCode', 'payment', 'serviceFee', 'totalPayment', 'createTime', 'createBy', 'updateTime', 'updateBy', 'sysOrgCode', 'status', 'delFlag'))
      },
      onDateChange: function(value, dateString) {
        console.log(dateString[0], dateString[1])
        this.queryParam.createTime_begin = dateString[0] + ' 00:00:00'
        this.queryParam.createTime_end = dateString[1] + ' 23:59:59'
      },
      onDateOk(value) {
        console.log(value)
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectionRows = selectionRows
        console.log('selectionRows', selectionRows)
        var selectedPrice = 0;
        for(var i=0;i<selectionRows.length;i++){
          selectedPrice = this.numAdd(selectedPrice,selectionRows[i].payment)
        }
        this.selectedPrice = selectedPrice;
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedPrice=0;
      },
      //监听checkbox属性
      getCheckboxProps(record) {
        return {
          props: {
            disabled: record.status !=0,
          }
        }
      },
      viewServiceContract(record){
        if(record.workContract==null){
          this.$message.warning('该合同为线下合同,不支持预览')
          return
        }
        if(record.contractType==2){
          window.open(record.workContract, '_blank', 'toolbar=yes')
        }else{
          window.open(window._CONFIG['imgDomainOssURL']+record.workContract, '_blank', 'toolbar=yes')
        }
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>