<template>
    <div class="app-container">
      <div class="flexBet searchTop">
        <!-- <div class="title flex m20">
          <div class="bar"></div>
          <div class="text">识别失败短信列表</div>
        </div> -->
     
      </div>

      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="76px"
          class="flex form" style="position: relative">
          <el-form-item label="码商" prop="carddealerName">
            <el-input size="medium" v-model="queryParams.carddealerName" placeholder="请输入码商"
              @keyup.enter.native="handleQuery" style="width: 180px; border-color: #e6f1ff" />
          </el-form-item>
          <el-form-item label="短信ID" prop="id">
            <el-input size="medium" v-model="queryParams.id" placeholder="请输入短信ID" @keyup.enter.native="handleQuery"
              style="width: 180px; border-color: #e6f1ff" />
          </el-form-item>
          <el-form-item label="设备key" prop="devKey">
            <el-input size="medium" v-model="queryParams.devKey" placeholder="请输入设备key" @keyup.enter.native="handleQuery"
              style="width: 180px; border-color: #e6f1ff" />
          </el-form-item>
  
          <el-form-item label="短信内容" prop="content">
            <el-input size="medium" v-model="queryParams.content" placeholder="请输入短信内容" @keyup.enter.native="handleQuery"
              style="width: 180px; border-color: #e6f1ff" />
          </el-form-item>
          <el-form-item label="识别备注" prop="verifyRemarks">
            <el-input size="medium" v-model="queryParams.verifyRemarks" placeholder="请输入识别备注"
              @keyup.enter.native="handleQuery" style="width: 180px; border-color: #e6f1ff" />
          </el-form-item>
  
          <!-- <el-form-item label="创建时间">
            <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
              range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :unlink-panels="true"></el-date-picker>
          </el-form-item> -->
          <el-form-item>
            <div class="searchTop flexBet" style="align-items: center">
              <el-row :gutter="10" class="mb8">
                <el-button type="primary" icon="" size="medium" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
              </el-row>
  
  
            </div>
          </el-form-item>
        </el-form>

        <!-- <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row> -->
  
      <div class="bg">
    
  
        <el-table stripe :data="infoList" v-loading="loading">
          <el-table-column label="短信id" align="center" prop="id" />
          <el-table-column label="码商" align="center" prop="carddealerName" />
          <el-table-column label="设备key" align="center" prop="devKey" />
          <el-table-column label="发送号码" align="center" prop="phone" />
          <el-table-column label="银行" align="center" prop="bankName" />
          <el-table-column :label="'金额'" align="center" prop="amountIntervalMax">
            <template slot-scope="scope">
              {{ parseFloat(NumberDiv(scope.row.amount, 100)).toFixed(2) }}
            </template>
          </el-table-column>
          <el-table-column label="卡号" align="center" prop="cardNumber" />
          <el-table-column label="短信中的时间" align="center" prop="smsTime" min-width="180" />
          <el-table-column label="设备接收时间" align="center" prop="recvTime" min-width="180" />
          <el-table-column label="创建时间" align="center" prop="createTime" min-width="180" />
          <el-table-column :label="'识别状态'" align="center" prop="verifyStatus">
          <template slot-scope="scope">
            {{ scope.row.verifyStatus == 2 ? '识别失败短信列表' :
              scope.row.verifyStatus == 1 && scope.row.orderNo? '匹配成功短信列表' : '匹配失败短信列表' }}
          </template>
        </el-table-column>
          <el-table-column label="失败原因" align="center" prop="verifyRemarks" min-width="180" />
          <el-table-column label="匹配单号" align="center" prop="orderNo" min-width="180" />
          <el-table-column label="短信内容" align="center" prop="content" min-width="180" />
          <el-table-column label="app版本" align="center" prop="ver" />
  
  
  
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" min-width="60">
            <template slot-scope="scope">
              <el-button size="small" type="text" @click="handleIdentify(scope.row)" style="color: #006eff">识别</el-button>
  
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList">
        </pagination>
      </div>
  
  
  
  
    </div>
  </template>
  
  <script>
  import { listCarddealerSms, getCarddealerSms, delCarddealerSms, addCarddealerSms, updateCarddealerSms, exportCarddealerSms } from "@/api/carddealer/carddealerSms";
  import Editor from '@/components/Editor';
  import { paySes } from "@/api/form";
import cardMerchantOrderRefreshMixin from "@/api/cardMerchantOrderRefresh.mixin";
  
  export default {
    name: "CarddealerSms",
    components: {
      Editor,
    },
  mixins: [cardMerchantOrderRefreshMixin],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 短信列表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          content: null,
          phone: null,
          devKey: null,
          bankName: null,
          amount: null,
          recvTime: null,
          cardNumber: null,
          cardHolder: null,
          verifyStatus: 2,
          smsTime: null,
          smsType: null,
          payType: null,
          orderNo: null,
          carddealerId: null,
          verifyRemarks: null,
          md5: null,
          ver: null,
          carddealerName: null,
          id: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          content: [
            { required: true, message: "内容不能为空", trigger: "blur" }
          ],
          phone: [
            { required: true, message: "发送号码不能为空", trigger: "blur" }
          ],
          devKey: [
            { required: true, message: "设备key不能为空", trigger: "blur" }
          ],
          createTime: [
            { required: true, message: "入库时间不能为空", trigger: "blur" }
          ],
        }
      };
    },
    $autoRefresh: {
    // 刷新间隔时间
    interval: 1000 * 10,
    // 立即执行一次
    immediate: false,
    // 被回调的函数, 不保证顺序执行
    handles: ["getList"],
    /**
     * 调用 handles 后的回调函数
     * 这个字段为数组类型, 数组中的每个元素都是一个函数, 在对应索引的 handle 执行后被调用
     */
    callbacks: [],
    // 是否启用调试模式
    debug: true,
  },
    created() {
      this.getList();
    },
    methods: {
      timerHandler(queryParams) {
        listCarddealerSms(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = Number(response.total);
        });
    },
      /** 查询短信列列表 */
      getList() {
        this.loading = true;
        listCarddealerSms(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = Number(response.total);
          this.loading = false;
        this.startTimer(this.queryParams)
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          content: null,
          phone: null,
          devKey: null,
          bankName: null,
          amount: null,
          recvTime: null,
          createTime: null,
          cardNumber: null,
          cardHolder: null,
          verifyStatus: 2,
          smsTime: null,
          smsType: null,
          payType: null,
          orderNo: null,
          carddealerId: null,
          verifyRemarks: null,
          md5: null,
          ver: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加短信列";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getCarddealerSms(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改短信列";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateCarddealerSms(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addCarddealerSms(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 识别按钮操作 */
      handleIdentify(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认识别短信编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return paySes.identify(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("识别成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有短信列数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return exportCarddealerSms(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };
  </script>
  