
<template>
  <BasicLayout>
    <template #wrapper>
      <el-card class="box-card">
        <el-table ref="table" v-loading="loading" :data="linePreOrderList">
          <el-table-column
            label="限价止损溢价"
            align="center"
            prop="stopLossPremium"
          />
          <el-table-column
            label="限价加仓溢价"
            align="center"
            prop="addPositionPremium"
          />
          <el-table-column
            label="限价减仓溢价"
            align="center"
            prop="reducePremium"
          />
          <!-- <el-table-column
            label="主账号加仓溢价百分比"
            align="center"
            prop="scaleOrderTypeARate"
            width="210"
            :show-overflow-tooltip="true"
          /> -->
          <!-- <el-table-column
            label="副账号加仓溢价百分比"
            align="center"
            prop="scaleOrderTypeBRate"
            width="210"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="主单亏损多少百分比开始加仓"
            align="center"
            prop="scaleUnrealizedProfitRate"
            width="210"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="加仓类型"
            align="center"
            prop="scaleType"
            :show-overflow-tooltip="true"
          >
            <template #default="{row}">
              <el-tag size="mini" :type="row.scaleType===1?'success':'default'">{{ ['','百分比','数值'][row.scaleType] }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="加仓数值"
            align="center"
            prop="scaleNum"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="自动加仓次数"
            align="center"
            prop="autoScaleTimes"
            width="100"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="加仓账户类型"
            align="center"
            width="100"
            prop="scaleSubordinate"
            :show-overflow-tooltip="true"
          >
            <template #default="{row}">
              {{ ['主账号','副账号','都加'][row.scaleSubordinate-1] }}
            </template>
          </el-table-column>
          <el-table-column
            label="对冲平仓涨跌幅"
            align="center"
            prop="hedgePerformance"
            width="200"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="对冲市价百分比"
            align="center"
            prop="protectHedgeRate"
            width="80"
          /> -->
          <el-table-column
            label="创建时间"
            align="center"
            prop="createdAt"
            width="150"
            :show-overflow-tooltip="true"
          >
            <template #default="{row}">{{ parseTime(row.createdAt) }}</template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120" fixed="right">
            <template slot-scope="scope">
              <el-popconfirm
                class="delete-popconfirm"
                title="确认要修改吗?"
                confirm-button-text="修改"
                @confirm="handleUpdate(scope.row)"
              >
                <el-button
                  slot="reference"
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                >修改
                </el-button>
              </el-popconfirm>
              <!-- <el-popconfirm
                  class="delete-popconfirm"
                  title="确认要删除吗?"
                  confirm-button-text="删除"
                  @confirm="handleDelete(scope.row)"
                >
                  <el-button
                    slot="reference"
                    v-permisaction="['admin:linePreOrder:remove']"
                    size="mini"
                    type="text"
                    icon="el-icon-delete"
                  >删除
                  </el-button>
                </el-popconfirm> -->
            </template>
          </el-table-column>
        </el-table>

        <!-- 添加或修改对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="700px">
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-form-item label="限价止损溢价" prop="stopLossPremium">
              <el-input v-model="form.stopLossPremium" placeholder="限价止损溢价" />
            </el-form-item>
            <el-form-item label="限价加仓溢价" prop="addPositionPremium">
              <el-input v-model="form.addPositionPremium" placeholder="限价加仓溢价" />
            </el-form-item>
            <el-form-item label="限价减仓溢价" prop="reducePremium">
              <el-input v-model="form.reducePremium" placeholder="限价减仓溢价" />
            </el-form-item>
            <!-- <el-form-item label="主账号加仓溢价百分比" prop="scaleOrderTypeARate">
              <el-input v-model="form.scaleOrderTypeARate" placeholder="主账号限价加仓买入百分比" />
            </el-form-item>
            <el-form-item label="副账号加仓溢价百分比" prop="scaleOrderTypeBRate">
              <el-input v-model="form.scaleOrderTypeBRate" placeholder="副账号限价加仓买入百分比" />
            </el-form-item>
            <el-form-item label="主单亏损多少百分比开始加仓" prop="scaleUnrealizedProfitRate">
              <el-input v-model="form.scaleUnrealizedProfitRate" placeholder="主单亏损多少百分比开始加仓" />
            </el-form-item>
            <el-form-item label="加仓类型" prop="scaleType">
              <el-radio-group v-model="form.scaleType">
                <el-radio :label="1">百分比</el-radio>
                <el-radio :label="2">数值</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="加仓数值" prop="scaleNum">
              <el-input v-model="form.scaleNum" placeholder="加仓数值" />
            </el-form-item>
            <el-form-item label="自动加仓次数" prop="autoScaleTimes">
              <el-input v-model.number="form.autoScaleTimes" placeholder="自动加仓次数" type="number" />
            </el-form-item>
            <el-form-item label="对冲平仓涨跌幅" prop="hedgePerformance">
              <el-input v-model="form.hedgePerformance" placeholder="对冲平仓涨跌幅" />
            </el-form-item>
            <el-form-item label="对冲市价亏损百分比" prop="protectHedgeRate">
              <el-input v-model="form.protectHedgeRate" placeholder="对冲市价亏损百分比" />
            </el-form-item>
            <el-form-item label="只开启保险对冲" prop="protectHedgeEnable">
              <el-radio-group v-model="form.protectHedgeEnable" lab>
                <el-radio :label="0">关闭</el-radio>
                <el-radio :label="1">开启</el-radio>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="加仓账户类型" prop="scaleSubordinate">
              <el-radio-group v-model="form.scaleSubordinate">
                <el-radio :label="1">主账号</el-radio>
                <el-radio :label="2">副账号</el-radio>
                <el-radio :label="3">都加</el-radio>
              </el-radio-group>
            </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>
      </el-card>
    </template>
  </BasicLayout>
</template>

<script>
import { systemSetting, systemSettingPut } from '@/api/admin/line-api-setting'
export default {
  data() {
    return {
      // 遮罩层
      loading: true,

      // 总条数
      total: 0,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      isEdit: false,
      // 类型数据字典
      typeOptions: [],
      linePreOrderList: [],

      // 表单参数
      form: {
      },
      // 表单校验
      rules: {
        stopLossPremium: [{ required: true, message: '限价止损溢价不能为空', trigger: 'blur' }],
        addPositionPremium: [{ required: true, message: '限价加仓溢价不能为空', trigger: 'blur' }],
        reducePremium: [{ required: true, message: '限价减仓溢价不能为空', trigger: 'blur' }]
      }

    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询参数列表 */
    getList() {
      this.loading = true
      systemSetting().then(response => {
        this.linePreOrderList = response.data.list
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.resetForm('form')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.title = '修改挂单配置'
      this.form = row
      this.open = true
      this.isEdit = true
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id !== undefined) {
            systemSettingPut(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess(response.msg)
                this.open = false
                this.getList()
              } else {
                this.msgError(response.msg)
              }
            })
          }
        }
      })
    }
  }
}
</script>
  <style lang="scss" scoped>
  .hour{
    ::v-deep.el-input__inner{
      line-height: 1;
    }
  }
  .page{
    .pagination-container{
      padding: 0 !important;
      margin-top: 0;
      margin-bottom: 0;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    ::v-deep.el-pagination{
      width: 100%;
    }
  }
  </style>
