<template>
  <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="5" :sm="8">
            <a-form-item label="订单编号">
              <j-input placeholder="请输入订单编号" v-model="queryParam.propertyName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="状态">
              <a-select style="width: 100%" v-model="queryParam.chargeTypeId" placeholder="请选择状态">
                <a-select-option v-for="item in chargeList" :key="item.id"
                  :value="item.id">{{item.typeName}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="10">
            <a-form-item label="订单时间">
              <a-range-picker @change="onChangeData" />
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="5" :sm="24">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="toReconciliation(1,'')" type="primary">批量对账</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
        @change="handleTableChange"
        :rowSelection="{selectedRowKeys: selectedRowKeys,onSelect:onSelect,onChange: onSelectChange}">
        <span slot="action" slot-scope="text, record">
          <a type="primary" @click="toReconciliation(2,record)">申请对账</a>
        </span>
      </a-table>

    </div>
    <!-- table区域-end -->
    <a-modal centered title="申请对账" :visible="visibleReconciliation" :confirm-loading="confirmLoading" @ok="handleOk"
      @cancel="handleCancel" width="60%">
      <a-form>
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="对账总金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="propertyName"
              style="width: 100%;">
              <a-input v-model="model.propertyName" placeholder="对账总金额"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="对账日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="propertyName"
              style="width: 100%;">
              <a-input v-model="model.propertyName" placeholder="对账日期"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="对账明细" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="propertyName"
              style="width: 100%;">
              <a @click="checkDetails()">查看明细</a>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="propertyName"
              style="width: 100%;">
              <a-textarea v-model="model.propertyName" :auto-size="{ minRows: 4, maxRows: 6 }" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form>
    </a-modal>
    <a-modal centered title="对账明细" :visible="visibleReconciliationDetail" :confirm-loading="confirmLoading" :footer="null" width="60%" @cancel="handleCancelDetail">
      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns1"
        :dataSource="selectedList" :pagination="false" :loading="loading" class="j-table-force-nowrap">
      </a-table>
    </a-modal>
  </a-card>
</template>

<script>
//import { getChargeListApi } from '@/api/api'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

const columns = [
  {
    title: '订单编号',
    dataIndex: 'id',
    key: 'id',
    align: 'center',
  },
  {
    title: '提交时间',
    dataIndex: 'reconciliationBeginDate',
    key: 'reconciliationBeginDate',
    align: 'center',
  },
  {
    title: '用户账号',
    dataIndex: 'creditCode',
    key: 'creditCode',
    align: 'center',
  },
  {
    title: '分利金额',
    dataIndex: 'propertyName',
    key: 'propertyName',
    align: 'center',
  },

  {
    title: '支付方式',
    dataIndex: 'reconciliationEndDate',
    key: 'reconciliationEndDate',
    align: 'center',
  },
  {
    title: '订单来源',
    dataIndex: 'reconciliationAmount',
    key: 'reconciliationAmount',
    align: 'center',
  },
  {
    title: '订单状态',
    dataIndex: 'updateTime',
    key: 'updateTime',
    align: 'center',
  },
  {
    title: '备注',
    dataIndex: 'empowerCommunityNum',
    key: 'empowerCommunityNum',
    align: 'center',
  },
  {
    title: '所属平台',
    dataIndex: 'auditStatus',
    key: 'auditStatus',
    align: 'center',
  },
  {
    title: '所属小区',
    dataIndex: 'companyAuditStatus',
    key: 'companyAuditStatus',
    // customRender: function (text) {
    //   return filterDictTextByCache('companyAuditStatus', text)
    // },
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    fixed: 'right',
    width: 150,
  },
]
const columns1 = [
  {
    title: '订单编号',
    dataIndex: 'id',
    key: 'id',
    align: 'center',
  },
  {
    title: '提交时间',
    dataIndex: 'reconciliationBeginDate',
    key: 'reconciliationBeginDate',
    align: 'center',
  },
  {
    title: '用户账号',
    dataIndex: 'creditCode',
    key: 'creditCode',
    align: 'center',
  },
  {
    title: '分利金额',
    dataIndex: 'propertyName',
    key: 'propertyName',
    align: 'center',
  },

  {
    title: '支付方式',
    dataIndex: 'reconciliationEndDate',
    key: 'reconciliationEndDate',
    align: 'center',
  },
  {
    title: '订单来源',
    dataIndex: 'reconciliationAmount',
    key: 'reconciliationAmount',
    align: 'center',
  },
  {
    title: '订单状态',
    dataIndex: 'updateTime',
    key: 'updateTime',
    align: 'center',
  },
  {
    title: '备注',
    dataIndex: 'empowerCommunityNum',
    key: 'empowerCommunityNum',
    align: 'center',
  },
  {
    title: '所属平台',
    dataIndex: 'auditStatus',
    key: 'auditStatus',
    align: 'center',
  },
  {
    title: '所属小区',
    dataIndex: 'companyAuditStatus',
    key: 'companyAuditStatus',
    // customRender: function (text) {
    //   return filterDictTextByCache('companyAuditStatus', text)
    // },
  }
]

export default {
  components: { },
  name: 'ReconciliationList',
  mixins: [JeecgListMixin],
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      chargeList: [],
      columns: columns,
      columns1: columns1,
      loading: false,
      url: {
        list: '/property-central/property/communityReconciliation/list',
      },
      dataSource: [
        {
          id: 'JD2394231',
          creditCode: '18000000000',
          propertyName: 20000,
          reconciliationBeginDate: '2023-01-01',
          reconciliationEndDate: '微信',
          reconciliationAmount: '小程序',
          updateTime: '未对账',
          empowerCommunityNum: '备注',
          auditStatus: 'XXX物业集团',
          companyAuditStatus: '花园小区',
        },
        {
          id: 'JD2394232',
          creditCode: '18000000000',
          propertyName: 20000,
          reconciliationBeginDate: '2023-01-01',
          reconciliationEndDate: '微信',
          reconciliationAmount: '小程序',
          updateTime: '未对账',
          empowerCommunityNum: '备注',
          auditStatus: 'XXX物业集团',
          companyAuditStatus: '花园小区',
        },
        {
          id: 'JD2394233',
          creditCode: '18000000000',
          propertyName: 20000,
          reconciliationBeginDate: '2023-01-01',
          reconciliationEndDate: '微信',
          reconciliationAmount: '小程序',
          updateTime: '未对账',
          empowerCommunityNum: '备注',
          auditStatus: 'XXX物业集团',
          companyAuditStatus: '花园小区',
        },
        {
          id: 'JD2394234',
          creditCode: '18000000000',
          propertyName: 20000,
          reconciliationBeginDate: '2023-01-01',
          reconciliationEndDate: '微信',
          reconciliationAmount: '小程序',
          updateTime: '未对账',
          empowerCommunityNum: '备注',
          auditStatus: 'XXX物业集团',
          companyAuditStatus: '花园小区',
        },
      ],
      visibleReconciliation: false,
      confirmLoading: false,
      selectedList: [],
      selectedRowKeys: [],
      visibleReconciliationDetail:false
    }
  },
  created() {
    //this.getChargeList()
  },
  methods: {
    // async getChargeList() {
    //   let { result } = await getChargeListApi()
    //   this.chargeList = result
    // },
    onChangeData(date, dateString) {
      if (dateString.length > 0) {
        this.queryParam.createTime_begin = dateString[0]
        this.queryParam.createTime_end = dateString[1]
      } else {
        this.queryParam.createTime_begin = ''
        this.queryParam.createTime_end = ''
      }
    },
    //申请对账
    toReconciliation(type, record) {
      this.selectedList = [];
      if (type == 1) {
        if (this.selectionRows.length > 0) {
          this.visibleReconciliation = true
          this.selectedList = this.selectionRows
          console.log(this.selectedList)
          console.log(333)
        } else {
          this.$message.warning('请选择订单')
        }
      } else if (type == 2) {
        this.visibleReconciliation = true
        this.selectedList.push(record);
        this.selectedRowKeys = [];
      }
    },
    handleOk(e) {
      this.ModalText = 'The modal will be closed after two seconds'
      this.confirmLoading = true
      setTimeout(() => {
        this.visibleReconciliation = false
        this.confirmLoading = false
      }, 2000)
    },
    handleCancel(e) {
      this.visibleReconciliation = false
    },

    onSelect(record, selected) {
      if (selected === true) {
        this.selectedCurrently = record
      }
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectedRows
    },
    checkDetails(){
      this.visibleReconciliationDetail = true
    },
    handleCancelDetail(){
      this.visibleReconciliationDetail = false
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>