<template>
  <div class="white_bg burt-container">
    <!-- form -->
    <a-form-model ref="form" layout="vertical" :model="form">
      <a-row :gutter="30">
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="保险公司">
            <a-select v-model="form.payorCode" placeholder="请选择保险公司" allowClear>
              <a-select-option v-for="item in companyOptions" :key="item.id" :value="item.payorCode">
                {{ item.longName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="EOB编号">
            <a-input v-model="form.eobNo"  placeholder="EOB编号"/>
          </a-form-model-item>
        </a-col>
        <a-col :md="12" class="none-label">
          <a-form-model-item label="button">
            <a-button class="mar-left10" type="primary" @click="handlerSearch">
              <Icon name="ssisearch_active" :size="14" />查询
            </a-button>
            <a-button class="mar-left10" type="primary" @click.stop="handlerReset">
              <Icon name="ssireset" :size="14" />重置
            </a-button>
            <a-button class="mar-left10" type="primary" @click="addNewEvt">
              <Icon name="ssiadd" :size="14" />新建回款
            </a-button>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
    <!-- table -->
    <a-table :columns="columns" :data-source="dataList" :scroll="{ x: true }" :pagination="false" >
      <template slot="eobSts" slot-scope="text">
        {{text==1?'待回款':'已回款'}}
      </template>
      <template slot="operation" slot-scope="text, record, index">
        <a-button type="link" @click.stop="editEvt(record)">修改</a-button>
        <a-button type="link" class="success" @click.stop="editEvt(record)">查看</a-button>
        <a-button v-if="record.backMoneyNo" type="link" class="danger" @click.stop="delRecord(index)">删除</a-button>
      </template>
    </a-table>
    <BurtPagination :pagination="pagination" @pageChange="getData" />
  </div>
</template>

<script>
import BurtPagination from "@/components/CUSTOMER/pagation";
import moment from "moment";
const columns = [
  { title: "回款编号", dataIndex: "backMoneyNo", ellipsis: true, width: 150 },
  { title: "保险公司", dataIndex: "payorName", ellipsis: true, width: 110 },
  { title: "回款金额(人民币)", dataIndex: "backAmountCny", ellipsis: true, width: 190,},
  { title: "回款金额(美元)", dataIndex: "backAmountUsd", ellipsis: true, width: 190,},
  { title: "汇率差", dataIndex: "backExchangeRate", ellipsis: true, width: 110 },
  { title: "操作", dataIndex: "operation", scopedSlots: { customRender: "operation" },fixed: "right", width: "200px", align: "center"},
];
export default {
  data() {
    return {
      columns,
      form: {
        payorCode: '',
        eobNo: '',
      },
      dataList: [],
      companyOptions: [], //保险公司
      pagination: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  components: {
    BurtPagination,
  },
  created(){
    this.getData();
    this._getCompanyOptions();
  },
  methods: {
    moment,
    pageChange(pager) {
      const { current } = pager;
      this.pagination.pageNum = current;
      this.getData();
    },
    // 重置
    handlerReset() {
      this.form = {
        payorCode: '',
        eobNo: '',
      }
    },
    // 获取保险公司下拉选项
    _getCompanyOptions() {
      this.$apis.GETCOMPANYOPTIONS().then((res) => {
        this.companyOptions = res.content || [];
      });
    },
    handlerSearch() {
      this.pagination.pageNum = 1;
      this.getData();
    },
    getData() {
      this.$apis.QUERYBACKMONEYLIST({
        ...this.form,
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
       })
      .then((res) => {
        if (res.returnCode == "0000") {
          let content = res.content || {};
          this.pagination.total = content.total || 0;
          this.dataList = content.list || [];
        } else {
          this.$message.error(res.returnMsg);
        }
      });
    },
    //新建回款
    addNewEvt(){
      this.$router.push({
        path: '/verification/collectionDetail'
      })
    },
    //编辑回款
    editEvt(record){
      const { backMoneyNo } = record;
      localStorage.setItem('backMoneyDataDetail', JSON.stringify(record));
      this.$router.push({
        path: '/verification/collectionDetail',
        query: {
          backMoneyNo
        }
      })
    },
    //删除记录
    delRecord(index) {
      this.$modal.confirm({
        title: "删除",
        content: "确定删除该条记录？",
        okText: "确认",
        cancelText: "取消",
        onOk: () => {
          this.$apis.DELETEBACKMONEY({
            backMoneyNo: this.dataList[index].backMoneyNo,
          })
          .then((res) => {
            if (res.returnCode == "0000") {
              this.$message.success("删除成功");
              this.dataList.splice(index, 1);
            } else {
              this.$message.error(res.returnMsg);
            }
          });
        },
        onCancel: () => {},
      });
    }
  },
};
</script>

<style lang="less" scoped>
.none-label {
  text-align: right;
  .ant-form-item-label {
    opacity: 0;
  }
}
.ant-btn .icon-class {
  .mg-r(10);
}
.success.ant-btn-link {
  color: #4cd964;
}
.danger.ant-btn-link {
  color: #ff3b30;
}
</style>
