<!--
@name: 波次发票重推
@author: 瞿涛
@time: 2024-06-12 10:36:44
-->
<template>
  <p-spin :spinning="spinning">
    <p-card title="主要信息">
      <div slot="extra">
        <p-button type="primary" @click="batchResetPush">批量重推</p-button>
      </div>
      <p-form-model ref='formTarget' :label-col='{ span: 8 }' :model='form' :wrapper-col='{ span: 16 }' class='plg-grid-from'>
        <a-row>
          <a-col :span='8'>
            <p-form-model-item label="波次号">
              <p-input v-model='form.id' placeholder="请输入波次号" />
            </p-form-model-item>
          </a-col>
          <a-col :span='8'>
            <p-form-model-item :wrapper-col="{ span: 24 }" style="text-align: center">
              <p-button type="primary" @click="onSearch">查询</p-button>
              <p-button class="ml-10" @click="onReset">重置</p-button>
            </p-form-model-item>
          </a-col>
        </a-row>
      </p-form-model>
      <p-table 
          ref="masterTable"
          dragle
          bordered
          row-key="id"
          hasRowSelectCheck
          :data-source.sync="dataSource"
          :remote-url="listRemoteUrl"
          :remoteData="listParams"
          :selectedRowKeys.sync="selectedRowKeys"
          >
            <p-table-column data-index='gmtCreate' title='波次时间' />
            <p-table-column data-index='code' title='波次号' />
            <p-table-column data-index='status' title='状态' />
            <p-table-column :width='80' data-index='operation' fixed='right' title='操作'>
              <template slot-scope='text, record'>
                <a @click="onResetPush(record)">重推</a>
              </template>
            </p-table-column>
      </p-table>
    </p-card>
  </p-spin>
</template>

<script>
import { waveRepush, listRemoteUrl } from './api'
export default {
  data() {
    return {
      spinning: false,
      form: {
        id:''
      },
      // 表格数据
      dataSource: [],
      selectedRowKeys: [],
      listParams: {},
      listRemoteUrl,
      
    }
  },
  methods: {
    // 重推
    onResetPush(record) {
      let self = this
      this.$confirm({
        title: '确定要重推该数据吗?',
        onOk() {
          self.spinning = true
          waveRepush([record.id]).then(res => {
            self.spinning = false
            if (res.success) {
              self.$message.success(res.message)
              self.onSearch()
            } else {
              self.$message.error(res.message)
            }
          })
        }
      })
    },
    // 批量重推
    batchResetPush() {
      if (this.selectedRowKeys.length === 0) return this.$message.warn('没有选中的数据!')
      let self = this
      this.$confirm({
        title: '确定要重推选中的数据吗?',
        onOk() {
          self.spinning = true
          waveRepush(self.selectedRowKeys).then(res => {
            self.spinning = false
            if (res.success) {
              self.$message.success(res.message)
              self.onSearch()
            } else {
              self.$message.error(res.message)
            }
          })
        }
      })
    },
    onSearch() {
      this.listParams = { ...this.listParams, ...this.form }
    },
    onReset() {
      this.form.id = ''
    },

  }
}
</script>

<style>

</style>