<template>
  <!-- 收费查询-账单查询 -->
  <div class="white_bg burt-container custom-info">
    <!-- form -->
    <a-form-model
      ref="form"
      :model="form"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-row :gutter="30">
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="就诊日期">
            <a-range-picker
              format="YYYY-MM-DD"
              v-model="form.dateRange"
              :placeholder="['开始日期', '结束日期']"
            />
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="账单日期">
            <a-range-picker
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              v-model="form.billDate"
              :placeholder="['选择账单开始日期', '选择账单结束日期']"
            />
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="保险公司">
            <a-select
              v-model="form.payorCode"
              placeholder="请选择保险公司"
              showSearch
              allowClear
              optionFilterProp="label"
            >
              <a-select-option
                v-for="item in companyOptions"
                :key="item.longName"
                :value="item.payorCode"
                :label="item.longName"
              >
                {{ item.longName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="寄送状态">
            <a-select
              v-model="form.sendSts"
              placeholder="请选择寄送状态"
              allowClear
            >
              <a-select-option value="1">已寄送</a-select-option>
              <a-select-option value="2">未寄送</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="快递公司">
            <a-select
              v-model="form.sendCompany"
              placeholder="请选择快递公司"
              showSearch
              allowClear
            >
              <a-select-option
                v-for="item in expressList"
                :key="item.id"
                :value="item.descCh"
                >{{ item.descCh }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="快递单号">
            <a-input
              v-model="form.trackingNo"
              placeholder="请输入快递单号"
              allow-clear
            />
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="寄送批号">
            <a-input
              v-model="form.sendBatchNo"
              placeholder="请输入寄送批号"
              allow-clear
            />
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="账单编号">
            <a-input
              v-model="form.receiptNo"
              placeholder="请输入账单编号"
              allow-clear
            />
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="病案号">
            <a-input
              v-model="form.mrnNo"
              placeholder="请输入病案号"
              allow-clear
            />
          </a-form-model-item>
        </a-col>
        <a-col :xxl="6" :xl="8" :sm="12">
          <a-form-model-item label="客户名称">
            <a-input
              v-model="form.patientName"
              placeholder="请输入客户名称"
              allow-clear
            />
          </a-form-model-item>
        </a-col>
        <a-col :xxl="12" :xl="16" :sm="24" class="none-label">
          <div class="btn-div flex">
            <span></span>
            <a-form-model-item
              label=""
              :labelCol="{ span: 0 }"
              :wrapperCol="{ span: 24 }"
            >
              <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="handlerReset">
                <Icon name="ssireset" :size="14" />重置
              </a-button>
              <a-button class="mar-left10" type="primary" @click="addNewCharge">
                <Icon name="ssiadd" :size="14" />新建寄送</a-button
              >
            </a-form-model-item>
          </div>
        </a-col>
      </a-row>
    </a-form-model>

    <!-- table -->
    <div class="scroll-table">
      <a-table
        :columns="columns"
        :data-source="dataList"
        :scroll="{ x: true }"
        :pagination="false"
      >
        <template slot="sendDate" slot-scope="text">
          {{ text ? moment(text).format('YYYY-MM-DD') : '' }}
        </template>
        <template slot="sendSts" slot-scope="text">
          {{ text == 1 ? '已寄送' : '未寄送' }}
        </template>
        <template slot="operation" slot-scope="text, record, index">
          <a-button type="link" @click.stop="editEvt(record, true)"
            >编辑</a-button
          >
          <a-button type="link" class="success" @click.stop="editEvt(record)"
            >查看</a-button
          >
          <a-button type="link" class="danger" @click.stop="delRecord(index)"
            >删除</a-button
          >
        </template>
      </a-table>
      <!--分页-->
      <BurtPagination :pagination="pagination" @pageChange="getData" />
    </div>
  </div>
</template>

<script>
import BurtPagination from '@/components/Customers/pagation'
import moment from 'moment'
export default {
  data() {
    const columns = [
      {
        title: '寄送批号',
        dataIndex: 'sendBatchNo',
        key: 'sendBatchNo',
        align: 'center',
        width: 136
      },
      { title: '保险公司', dataIndex: 'payorName', width: 110 },
      {
        title: '寄送状态',
        dataIndex: 'sendSts',
        width: 90,
        scopedSlots: { customRender: 'sendSts' }
      },
      {
        title: '寄送日期',
        dataIndex: 'sendDate',
        width: 130,
        scopedSlots: { customRender: 'sendDate' }
      },
      { title: '快递单号', dataIndex: 'trackingNo', width: 180 },
      { title: '寄送备注', dataIndex: 'sendRemark', width: 100 },
      {
        title: '操作',
        key: 'operation',
        width: '200px',
        fixed: 'right',
        scopedSlots: { customRender: 'operation' },
        align: 'center'
      }
    ]
    return {
      labelCol: { span: 5 },
      wrapperCol: { span: 19 },
      loading: false,
      columns,
      form: {
        dateRange: [],
        billDate: [],
        payorCode: undefined,
        sendBatchNo: '',
        sendCompany: undefined,
        trackingNo: '',
        sendSts: undefined
      },
      companyOptions: [], //保险公司
      expressList: [], //快递列表
      dataList: [],
      pagination: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      iscreated: false
    }
  },
  components: {
    BurtPagination
  },
  created() {
    this.iscreated = true
    this.getData()
    this._getCompanyOptions()
    this.getRefcdByRefgrp()
  },
  activated() {
    if (!this.iscreated) {
      this.getData()
      this._getCompanyOptions()
      this.getRefcdByRefgrp()
    } else {
      this.iscreated = false
    }
  },
  methods: {
    moment,
    // 获取列表数据
    getData() {
      let filter = {
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
        ...this.form,
        visitTimeStart: this.form.dateRange[0]
          ? moment(this.form.dateRange[0]).format('YYYY-MM-DD 00:00:00')
          : '',
        visitTimeEnd: this.form.dateRange[1]
          ? moment(this.form.dateRange[1]).format('YYYY-MM-DD 00:00:00')
          : '',
        receiptEndDate: this.form.billDate[1]
          ? moment(this.form.billDate[1]).format('YYYY-MM-DD 00:00:00')
          : '',
        receiptStartDate: this.form.billDate[0]
          ? moment(this.form.billDate[0]).format('YYYY-MM-DD 00:00:00')
          : ''
      }
      delete filter.dateRange
      this.$apis.querySendInfoList(filter).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)
        }
      })
    },
    // 获取保险公司下拉选项
    _getCompanyOptions() {
      this.$apis.getCompanyOptions().then((res) => {
        this.companyOptions = res.content || []
      })
    },
    // 获取快递列表
    getRefcdByRefgrp() {
      this.$apis
        .getRefcdByRefgrp({
          modid: 'CI',
          refgrp: 'SEND_COMPANY'
        })
        .then((res) => {
          this.expressList = res.content || []
        })
    },
    // 重置
    handlerReset() {
      this.form = {
        dateRange: [],
        billDate: [],
        payorCode: '',
        sendBatchNo: '',
        sendCompany: '',
        trackingNo: '',
        sendSts: ''
      }
    },
    //编辑
    editEvt(record, isEdit) {
      const { sendBatchNo } = record
      localStorage.setItem('jisongDataDetail', JSON.stringify(record))
      this.$router.push({
        path: '/charge-query/lpjManageDetail',
        query: { sendBatchNo, isEdit }
      })
    },
    handlerSearch() {
      this.pagination.pageNum = 1
      this.getData()
    },
    //删除
    delRecord(index) {
      this.$modal.confirm({
        title: '删除',
        content: '确定删除该条记录?',
        okText: '确定',
        cancelText: '取消',
        onOk: () => {
          this.$apis
            .DeleteReceiptSendInfo({
              sendBatchNo: this.dataList[index].sendBatchNo
            })
            .then((res) => {
              if (res.returnCode == '0000') {
                this.$message.success('删除成功')
                this.dataList.splice(index, 1)
              } else {
                this.$message.error(res.returnMsg)
              }
            })
        }
      })
    },
    //新建寄送
    addNewCharge() {
      this.$router.push({
        path: '/charge-query/lpjManageDetail',
        query: { isEdit: true }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.none-label {
  text-align: right;
}
.ant-btn .icon-class {
  .mg-r(10);
}
.btn-div {
  justify-content: space-between;
}
.scroll-table {
  height: calc(100vh - 330px);
  overflow: scroll;
}
@media screen and (min-width: 1920px) {
  .scroll-table {
    height: calc(100vh - 320px);
  }
}
</style>