<template>
  <div>
    <br />
    <div class="top">
      <el-form :inline="true" :model="searchInfo" class="demo-form-inline">

        <el-form-item label="银行名称：">
          <el-input placeholder="请输入银行名称" v-model="searchInfo.openBankName"></el-input>
        </el-form-item>

        <el-form-item label="签约状态：">
           <el-select v-model="searchInfo.payChannelType" clearable placeholder="全部">
                        <el-option v-for="item in this.$enumUtils.toValue('BankCardStatus')" :key="item.value"
                                :label="item.label" :value="item.value"></el-option>
                    </el-select>
        </el-form-item>
        <div class="btn">
          <el-button @click="reset" type="primary">重置</el-button>
          <el-button @click="querySearchRemind" type="primary">查询</el-button>
        </div>
      </el-form>
    </div>
    <div>
      <el-table
        :data="tablePlanRemindData"
        style="width: 100%"
        :default-sort="{prop: 'date', order: 'descending'}"
      >
        <el-table-column
          type="index"
          width="50" label="排行">
        </el-table-column>
        <el-table-column prop="channelName" label="渠道名称" ></el-table-column>
        <el-table-column prop="payChannelApi" label="支付渠道" ></el-table-column>
        <el-table-column prop="payChannelType" label="支付渠道类型" ></el-table-column>
        <el-table-column prop="channelGrade" label="渠道优先级" ></el-table-column>
        <el-table-column prop="openBankName" label="银行名称" ></el-table-column>
        <el-table-column prop="openBankCode" label="银行Code" ></el-table-column>
        <el-table-column prop="memo" label="备注"></el-table-column>

        <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="updateBankCode(scope.row)">修改</el-button>
            </template>
        </el-table-column>
      
      </el-table>
    </div>
 

  </div>
</template>

<script>
import * as moment from "moment";

export default {
  name: "CarkBankList",
  data() {
    return {
      flag: false,
      page: {
        current: 1,
        size: 20,
        total: 0
      },
      searchInfo: {
        date: [new Date(), new Date()],
        openBankName: "",
        payChannelType:''
      },
      tablePlanRemindData: [],
    };
  },

  mounted: function() {
    this.tablePlanRemindData = this.remindData();
  },

  methods: {
    formatter(row, column) {
      return row.address;
    },

    /** 加载数据 */
    remindData(params) {
      var listsData = [];
      this.$$post("/channel/getBankCodeList", this.buildParam())
        .then(res => {
          if (res.data.code != 200) {
            this.$message.error(res.data.message);
            return;
          }
          listsData = res.data.result;
          this.tablePlanRemindData = listsData;
        })
        .catch(error => {
          this.$Message.error(error || "系统异常");
        });
    },
    // 修改优先渠道
    updateBankCode(record) {
      
      this.$prompt('请输入优先级别：', '修改渠道优先级', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /\.*?/,
          inputErrorMessage: '内容不能为空'
        }).then(({ value }) => {
           // 获取输入的意见  value

           var bank_id = record.id
           console.log(bank_id,value);

            this.$$post("/channel/editBankCode", this.buildBankParam(bank_id,Number(value)))
            .then(res => {
              if (res.data.code != 200) {
                this.$message.error(res.data.message);
                return;
              }
              this.$message({message: '修改渠道优先级成功', type: 'success'});

              this.remindData();
            })
            .catch(error => {
              this.$Message.error(error || "系统异常");
            });

         
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消修改优先级'
          });       
        });


     
    },

    //搜索查询
    querySearchRemind() {
      this.remindData();
    },

    //参数
    buildParam() {
      var return_hash = {
      };

      if (this.searchInfo.payChannelType != "") {
        return_hash["payChannelType"] = this.searchInfo.payChannelType;
      }

      if (this.searchInfo.openBankName != "") {
        return_hash["openBankName"] = this.searchInfo.openBankName;
      }
      return return_hash;
    },
    // 渠道优先级参数 
     buildBankParam(bank_id,value) {
      
      var return_hash = {

      };

      if (bank_id != "") {
        return_hash["id"] = bank_id;
      }
      if (value != "") {
        return_hash["channelGrade"] = value;
      }
      return return_hash;
    },


    //显示日期
    dateFormat: function(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD");
    },

    //重置
    reset() {
      this.searchInfo.batchNo = "";
      this.searchInfo.batchStatus = "";
    },

    /** 处理分页操作*/
    handleCurrentChange() {
      this.tablePlanRemindData = this.remindData();
    },

    mergeDate(param1, param2) {
      if (param1 == "") {
        return "";
      }
      var array = new Array();
      array[0] = new Date(param1);
      array[1] = new Date(param2);
      return array;
    },
    getDate(param, num) {
      if (param && param[num] !== "") {
        return moment(param[num]).format("YYYY-MM-DD");
      }
      return "";
    }
  }
};
</script>

<style scoped>
</style>