<template>
  <div class="body-wrapper">
    <el-tabs v-model="activeName">
      <el-tab-pane label="电话追缴" name="电话追缴">
        <el-form class="form-wrapper" :model="formInline1" :inline="true" style="margin-bottom: 20px;">
          <el-row>
            <el-col :span="6">
              <el-form-item label="车牌号: ">
                <el-input v-model="formInline1.plateNo" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="电话号码: ">
                <el-input v-model="formInline1.phoneNo" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>
                <el-button type="primary" class="query-btn" @click="onSubmit" icon="el-icon-search">查询</el-button>
                <el-button type="success" @click="handleAdd">新增</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table border :row-class-name="rowClassName" :data="tableData1" v-loading="loading1">
          <el-table-column v-for="(item, index) in columns1" :key="index" :label="item.label" :prop="item.key">
          </el-table-column>
          <el-table-column
            label="操作"
            width="200">
            <template slot-scope="scope" style="display: inline-block">
              <el-button v-if='scope.row.auditStatus ==="未审核"' type="primary" @click="handleEdit(scope.row)" slot="reference">修改</el-button>
              <el-popconfirm  v-if='scope.row.auditStatus ==="未审核"' title="确定删除吗？" @confirm="deleteRow(scope.row)">
                <el-button type="danger" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <div class="table-pagination">
          <el-pagination layout="total, prev, pager, next, jumper" :total="total1" @current-change="handlePageChange1"
                         :current-page.sync="pageNum1" :page-size.sync="pageSize1">
          </el-pagination>
        </div>
        <el-dialog
          :title="title"
          :visible.sync="dialogVisible"
          width="50%"
          custom-class="audit-dialog">
          <div class="form-div">
            <el-form label-position="left" :rules="rules" label-width="85px" ref="formLabelAlign" :model="formLabelAlign">
              <el-form-item label="停车场">
                <el-select filterable clearable v-model="formLabelAlign.parkLotId" placeholder="请选择">
                  <el-option
                    v-for="(item,index) in carParkingNameOptions"
                    :key="index"
                    :label="item.parkName"
                    :value="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item label="车牌号" prop="plateNo">
                <el-input v-model="formLabelAlign.plateNo"></el-input>
              </el-form-item>
              <el-form-item label="电话号码">
                <el-input v-model="formLabelAlign.phoneNo"></el-input>
              </el-form-item>
              <el-form-item label="欠缴金额">
                <el-input v-model="formLabelAlign.arrearsAmount"></el-input>
              </el-form-item>
<!--              <el-form-item label="追缴详情">-->
<!--                <el-input-->
<!--                  type="textarea"-->
<!--                  :rows="2"-->
<!--                  placeholder="请输入内容"-->
<!--                  v-model="formLabelAlign.recoveryDetail">-->
<!--                </el-input>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="追缴日期">-->
<!--                <el-date-picker-->
<!--                  v-model="formLabelAlign.recoveryTime"-->
<!--                  type="datetime"-->
<!--                  value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                  placeholder="选择日期时间">-->
<!--                </el-date-picker>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="追缴结果">-->
<!--                <el-input v-model="formLabelAlign.recoveryResult"></el-input>-->
<!--              </el-form-item>-->
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleConfirm">确 定</el-button>
          </span>
        </el-dialog>
      </el-tab-pane>
      <el-tab-pane label="短信追缴" name="短信追缴">
        <el-form class="form-wrapper" :model="formInline2" :inline="true" style="margin-bottom: 20px;">
          <el-row>
            <el-col :span="6">
              <el-form-item label="车牌号: " prop="plateNo">
                <el-input v-model="formInline2.plateNo" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="电话号码: ">
                <el-input v-model="formInline2.phoneNo" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>
                <el-button type="primary" class="query-btn" @click="onSubmit2" icon="el-icon-search">查询</el-button>
                <el-button type="success" @click="handleAdd2">新增</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table border :row-class-name="rowClassName" :data="tableData2" v-loading="loading2">
          <el-table-column v-for="(item, index) in columns2" :key="index" :label="item.label" :prop="item.key">
          </el-table-column>
          <el-table-column
            label="操作"
            width="200">
            <template slot-scope="scope" style="display: inline-block">
              <el-button v-if='scope.row.auditStatus ==="未审核"' type="primary" @click="handleEdit2(scope.row)" slot="reference">修改</el-button>
              <el-popconfirm v-if='scope.row.auditStatus ==="未审核"' title="确定删除吗？" @confirm="deleteRow2(scope.row)">
                <el-button type="danger" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <div class="table-pagination">
          <el-pagination layout="total, prev, pager, next, jumper" :total="total2" @current-change="handlePageChange2"
                         :current-page.sync="pageNum2" :page-size.sync="pageSize2">
          </el-pagination>
        </div>
        <el-dialog
          :title="title2"
          :visible.sync="dialogVisible2"
          width="50%"
          custom-class="audit-dialog">
          <div class="form-div">
            <el-form label-position="left" label-width="85px" :model="formLabelAlign2">
              <el-form-item label="停车场: ">
                <el-select filterable clearable v-model="formLabelAlign2.parkLotId" placeholder="请选择">
                  <el-option
                    v-for="(item,index) in carParkingNameOptions"
                    :key="index"
                    :label="item.parkName"
                    :value="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item label="车牌号">
                <el-input v-model="formLabelAlign2.plateNo"></el-input>
              </el-form-item>
              <el-form-item label="电话号码">
                <el-input v-model="formLabelAlign2.phoneNo"></el-input>
              </el-form-item>
              <el-form-item label="欠缴金额">
                <el-input v-model="formLabelAlign2.arrearsAmount"></el-input>
              </el-form-item>
<!--              <el-form-item label="追缴详情">-->
<!--                <el-input-->
<!--                  type="textarea"-->
<!--                  :rows="2"-->
<!--                  placeholder="请输入内容"-->
<!--                  v-model="formLabelAlign2.recoveryDetail">-->
<!--                </el-input>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="追缴日期">-->
<!--                <el-date-picker-->
<!--                  v-model="formLabelAlign2.recoveryTime"-->
<!--                  type="datetime"-->
<!--                  value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                  placeholder="选择日期时间">-->
<!--                </el-date-picker>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="追缴结果">-->
<!--                <el-input v-model="formLabelAlign2.recoveryResult"></el-input>-->
<!--              </el-form-item>-->
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible2 = false">取 消</el-button>
            <el-button type="primary" @click="handleConfirm2">确 定</el-button>
        </span>
        </el-dialog>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import api_z from "@/api/article_z.js";
import {vehicleNumber} from '@/util/common'

export default {
  components: {},
  data() {
    return {
      loading1: false,
      loading2: false,
      carParkingNameOptions: [],
      activeName: '电话追缴',
      columns1: [
        {
          label: '车牌号',
          key: 'plateNo'
        },
        {
          label: '停车场',
          key: 'parkName'
        },
        {
          label: '电话号码',
          key: 'phoneNo'
        },
        {
          label: '欠缴金额',
          key: 'arrearsAmount'
        },
        {
          label: '审核状态',
          key: 'auditStatus'
        },
        {
          label: '创建日期',
          key: 'createTime'
        },
        // {
        //   label: '追缴日期',
        //   key: 'recoveryTime'
        // },
        // {
        //   label: '追缴状态',
        //   key: 'recoveryStatus'
        // },
        // {
        //   label: '追缴结果',
        //   key: 'recoveryResult'
        // },
      ],
      tableData1: [],
      total1: 0,
      pageSize1: 10,
      pageNum1: 1,
      title: '',
      dialogVisible: false,
      rules: {
        plateNo: [
          { required: true, message: "车牌号不能为空", trigger: "blur" },
          {
            validator: vehicleNumber,
            trigger: "blur",
          },
        ],
      },
      formLabelAlign: {
        parkLotId: '',
        plateNo: '',
        phone: '',
        arrearsAmount: '',
        recoveryDetail: '',
        recoveryTime: '',
        recoveryResult: '',
      },
      columns2: [
        {
          label: '车牌号',
          key: 'plateNo'
        },
        {
          label: '停车场',
          key: 'parkName'
        },
        {
          label: '电话号码',
          key: 'phoneNo'
        },
        {
          label: '欠缴金额',
          key: 'arrearsAmount'
        },
        {
          label: '审核状态',
          key: 'auditStatus'
        },
        {
          label: '创建日期',
          key: 'createTime'
        },
        // {
        //   label: '追缴状态',
        //   key: 'recoveryStatus'
        // },
        // {
        //   label: '追缴结果',
        //   key: 'recoveryResult'
        // },
      ],
      tableData2: [],
      total2: 0,
      radio: '2',
      pageSize2: 10,
      pageNum2: 1,
      formInline1: {
        plateNo: '',
        phoneNo: '',
      },
      formInline2: {
        plateNo: '',
        phoneNo: '',
      },
      title2: '',
      dialogVisible2: false,
      formLabelAlign2: {
        parkLotId: '',
        plateNo: '',
        phone: '',
        arrearsAmount: '',
        recoveryDetail: '',
        recoveryTime: '',
        recoveryResult: '',
      },
    }
  },
  mounted() {
    this.getCarParkingName()
    this.getTableData1()
    this.getTableData2()
  },
  watch: {},
  methods: {
    rowClassName({ rowIndex }) {
      // 偶数行和奇数行分别返回不同的类名，也可以根据实际需求基于rowData进行条件判断
      return rowIndex % 2 === 0 ? 'even-row' : 'odd-row';
    },
    //车场
    getCarParkingName() {
      api_z.querySelectParkListByPage().then(res => {
        this.carParkingNameOptions=res.data
      })
    },
    onSubmit() {
      this.pageNum1 = 1
      this.getTableData1()
    },
    handleAdd() {
      this.title = '添加'
      this.formLabelAlign = {}
      this.dialogVisible = true
    },
    handleEdit(row) {
      this.title = '修改'
      this.formLabelAlign = {...row}
      this.dialogVisible = true
    },
    deleteRow(record) {
      api_z.deleteTaskRecovery([{id: record.id}]).then(res => {
        if (res.code === 200) {
          this.$message({type: 'success', message: '删除成功!'})
          this.getTableData1()
        }
      })
    },
    handleConfirm() {
      if (this.title === '修改') {
        api_z.editTaskRecovery({...this.formLabelAlign}).then(res => {
          if (res.code === 200) {
            this.dialogVisible = false
            this.$message({
              message: '修改成功!',
              type: 'success'
            })
            this.getTableData1()
          }
        })
      } else {
        api_z.addTaskRecovery({...this.formLabelAlign, recoveryType: '电话'}).then(res => {
          if (res.code === 200) {
            this.dialogVisible = false
            this.$message({
              message: '添加成功!',
              type: 'success'
            })
            this.getTableData1()
          }
        })
      }
    },
    handleAdd2() {
      this.title2 = '添加'
      this.formLabelAlign2 = {}
      this.dialogVisible2 = true
    },
    handleEdit2(row) {
      this.title2 = '修改'
      this.formLabelAlign2 = {...row}
      this.dialogVisible2 = true
    },
    deleteRow2(record) {
      api_z.deleteTaskRecovery([{id: record.id}]).then(res => {
        if (res.code === 200) {
          this.$message({type: 'success', message: '删除成功!'})
          this.getTableData2()
        }
      })
    },
    onSubmit2() {
      this.pageNum2 = 1
      this.getTableData2()
    },

    handleConfirm2() {
      if (this.title2 === '修改') {
        api_z.editTaskRecovery({...this.formLabelAlign2}).then(res => {
          if (res.code === 200) {
            this.dialogVisible2 = false
            this.$message({
              message: '修改成功!',
              type: 'success'
            })
            this.getTableData2()
          }
        })
      } else {
        api_z.addTaskRecovery({...this.formLabelAlign2, recoveryType: '短信'}).then(res => {
          if (res.code === 200) {
            this.dialogVisible2 = false
            this.$message({
              message: '添加成功!',
              type: 'success'
            })
            this.getTableData2()
          }
        })
      }
    },
    handlePageChange1() {
      this.getTableData1()
    },
    getTableData1() {
      this.loading1 = true
      const {pageNum1, pageSize1} = this
      api_z.queryTaskRecoveryPhoneByPage({current: pageNum1, size: pageSize1, ...this.formInline1}).then(res => {
        this.tableData1 = res.data.records || []
        this.total1 = res.data.total
        this.loading1 = false
      })
    },
    handlePageChange2() {
      this.getTableData2()
    },
    getTableData2() {
      this.loading2 = true
      const {pageNum2, pageSize2} = this
      api_z.queryTaskRecoverySmsByPage({current: pageNum2, size: pageSize2, ...this.formInline2}).then(res => {
        this.tableData2 = res.data.records || []
        this.total2 = res.data.total
        this.loading2 = false
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.body-wrapper {
  .form-wrapper {
    .el-form-item {
      margin-bottom: 0px;
    }
  }

  .button-block {
    text-align: right;
    margin-bottom: 20px;
  }

  .table-pagination {
    text-align: right;
  }

  .search-card {
    margin-bottom: 20px;
    text-align: center;

    .input-wrapper {
      width: 36%;
    }
  }

  .audit-dialog {
    .mg-bt {
      margin-bottom: 24px;
    }

    .label {
      text-align: right;
    }

    .form-div {
      /deep/ .el-input__inner {
        height: 35px;
        width: 99%;
        border: 1px solid #a6a5a5;
      }
    }
  }
}
</style>
