<template>
  <div class="app-container">
    <div class="search_con m-b-28">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商家名称" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入商家名称"
          clearable
          size="medium"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家账号" prop="storeAccount">
        <el-input
          v-model="queryParams.storeAccount"
          placeholder="请输入商家账号"
          clearable
          size="medium"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="质押币种" prop="coin">
        <el-input
          v-model="queryParams.coin"
          placeholder="请输入质押币种"
          clearable
          size="medium"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="medium">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" size="medium" @click="handleQuery">搜索</el-button>
        <el-button size="medium" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </div>

  <div class="bg bg-white">
    <el-row :gutter="10" class="m-b-16">
    <!--  <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['otc:otcStorePledge:add']"
        >新增</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="medium"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['otc:otcStorePledge:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="medium"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['otc:otcStorePledge:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="medium"
          @click="handleExport"
          v-hasPermi="['otc:otcStorePledge:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="otcStorePledgeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="流水编号" align="center" prop="id" />
      <el-table-column label="商家昵称" align="center" prop="storeName" />
      <el-table-column label="商家账号" align="center" prop="storeAccount" />
      <el-table-column label="质押币种" align="center" prop="coin" />
      <el-table-column label="质押数量" align="center" prop="balance" />
      <el-table-column label="冻结数" align="center" prop="frozenBalance" />
      <el-table-column label="可用数量" align="center" prop="availableBalance" />
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['otc:otcStorePledge:edit']"
          >修改</el-button>
        <!--  <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['otc:otcStorePledge:remove']"
          >删除</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"
    />
  </div>


    <!-- 添加或修改商户质押资产对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商家编号" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入商家编号" />
        </el-form-item>
        <el-form-item label="质押币种" prop="coin">
          <el-input v-model="form.coin" placeholder="请输入质押币种" />
        </el-form-item>
        <el-form-item label="质押数量" prop="balance">
          <el-input v-model="form.balance" placeholder="请输入质押数量" />
        </el-form-item>
        <el-form-item label="冻结数" prop="frozenBalance">
          <el-input v-model="form.frozenBalance" placeholder="请输入冻结数" />
        </el-form-item>
        <el-form-item label="可用数量" prop="availableBalance">
          <el-input v-model="form.availableBalance" placeholder="请输入可用数量" />
        </el-form-item>
        <el-form-item label="状态">
          <!-- <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group> -->
          <el-select v-model="form.status" placeholder="请选择状态" clearable size="medium">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>

        </el-form-item>
        <el-form-item label="添加时间" prop="createTime">
          <el-date-picker clearable size="small"
            v-model="form.createTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择添加时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOtcStorePledge, getOtcStorePledge, delOtcStorePledge, addOtcStorePledge, updateOtcStorePledge, exportOtcStorePledge } from "@/api/otc/otcStorePledge";

export default {
  name: "OtcStorePledge",
  components: {
  },
  data() {
    return {
      statusOptions: [],

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户质押资产表格数据
      otcStorePledgeList: [],
      statusOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeId: null,
        coin: null,
        balance: null,
        frozenBalance: null,
        availableBalance: null,
        status: null,
        storeAccount:null,
        storeName:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        storeId: [
          { required: true, message: "商家编号不能为空", trigger: "blur" }
        ],
        coin: [
          { required: true, message: "质押币种不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_yes_no").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询商户质押资产列表 */
    getList() {
      this.loading = true;
      listOtcStorePledge(this.queryParams).then(response => {
        this.otcStorePledgeList = response.rows;
        this.total = Number(response.total);
        this.loading = false;
      });
    },

    statusFormat(row, column) {
       return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        storeId: null,
        coin: null,
        balance: null,
        frozenBalance: null,
        availableBalance: null,
        status: "0",
        createTime: 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
      getOtcStorePledge(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) {
            updateOtcStorePledge(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOtcStorePledge(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除商户质押资产编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOtcStorePledge(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有商户质押资产数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportOtcStorePledge(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
