新版交易所前段管理后台
1
jhzh
9 days ago 3c9801025acf79edd3c8dc78451752e0c5d8435f
src/views/modules/mining/mining-order-add-or-update.vue
@@ -1,24 +1,81 @@
<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    title="新增"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="角色名称" prop="roleName">
        <el-input v-model="dataForm.roleName" placeholder="角色名称"></el-input>
    width="800px"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="100px"
    >
          <el-form-item label="矿机" prop="algorithm">
            <el-select
              class="speaInputTwo"
              v-model="dataForm.algorithm"
              placeholder="请选择"
              @change="changeVal(dataForm.algorithm)"
            >
              <el-option
                v-for="item in algorithms"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
          <!---->
          <el-row>
            <el-col :span="11">
              <el-form-item label="投资金额区间" prop="investment_min">
                <el-input disabled v-model="investment_min" placeholder="">
                  <template v-slot:append>
                    <span>USDT</span>
                  </template>
                </el-input>
      </el-form-item>
      <el-form-item size="mini" label="授权">
        <el-tree
          :data="menuList"
          :props="menuListTreeProps"
          node-key="menuId"
          ref="menuListTree"
          show-checkbox>
        </el-tree>
            </el-col>
            <el-col :span="2">
              <el-form-item label="— —" prop="">
              </el-form-item></el-col>
            <el-col :span="11">
              <el-form-item label="" prop="investment_max">
                <el-input disabled v-model="investment_max"  placeholder="">
                  <template v-slot:append>
                    <span>USDT</span>
                  </template>
                </el-input>
      </el-form-item>
            </el-col>
          </el-row>
          <!---->
          <el-form-item label="用户uid" prop="para_uid">
            <el-input
              v-model="dataForm.para_uid"
              placeholder="用户uid"
            ></el-input>
          </el-form-item>
          <el-form-item label="投资金额" prop="para_amount">
            <el-input
              v-model="dataForm.para_amount"
              placeholder="投资金额"
            ><template v-slot:append>
                <span>USDT</span>
              </template></el-input>
          </el-form-item>
      <!-- <el-form-item  label="登录人资金密码"  prop="login_safeword">
        <el-input v-model="dataForm.login_safeword" type="password" placeholder="请输入登录人资金密码"></el-input>
      </el-form-item> -->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
@@ -26,96 +83,170 @@
    </span>
  </el-dialog>
</template>
<script>
  import { treeDataTranslate } from '@/utils'
  import { Debounce } from '@/utils/debounce'
import { encrypt } from "@/utils/crypto";
import { Debounce } from "@/utils/debounce";
  export default {
    data () {
      return {
      investment_min:"",
      investment_max:"",
        visible: false,
        menuList: [],
        menuListTreeProps: {
          label: 'name',
          children: 'children'
        },
        dataForm: {
          id: 0,
          roleName: '',
          remark: ''
        roleName: "",
        remark: "",
        name: "",
        state: "",
        computing_power_unit:'',
        },
        dataRule: {
          roleName: [
            { required: true, message: '角色名称不能为空', trigger: 'blur' },
            { pattern: /\s\S+|S+\s|\S/, message: '请输入正确的角色名称', trigger: 'blur' }
      all:{},
      algorithms: [
        {
          label: "EtHash",
          value: "EtHash",
        },
        {
          label: "EquiHash",
          value: "EquiHash",
        },
        {
          label: "Kadena",
          value: "Kadena",
        },
        {
          label: "EthHash",
          value: "EthHash",
        },
          ],
          remark: [
            { required: false, pattern: /\s\S+|S+\s|\S/, message: '输入格式有误', trigger: 'blur' }
          ]
      dataRule: {
        algorithm: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        para_uid: [
            { required: true, message: '不能为空', trigger: 'blur' },
        ],
        para_amount: [
            { required: true, message: '不能为空', trigger: 'blur' },
        ],
        },
        tempKey: -666666 // 临时key, 用于解决tree半选中状态项不能传给后台接口问题. # 待优化
      }
      tempKey: -666666, // 临时key, 用于解决tree半选中状态项不能传给后台接口问题. # 待优化
    };
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
    init(row) {
      this.dataForm = {};
      // if(row){
      //   this.dataForm = row;
      // }
      this.listMiningOrder();
    },
    changeVal(val) {
      console.log(val);
      let data = this.all[val];
      this.investment_min = data.investment_min;
      this.investment_max = data.investment_max;
    },
    listMiningOrder(){
      //
      this.algorithms = []
      this.all = {}
        this.$http({
          url: this.$http.adornUrl('/sys/menu/table'),
          method: 'get',
          params: this.$http.adornParams()
            url: this.$http.adornUrl(`/normal/adminMinerOrderAction!toAddOrder.action`),
            method: "get",
            params: this.$http.adornParams({
            }),
        }).then(({data}) => {
          this.menuList = treeDataTranslate(data, 'menuId', 'parentId')
        }).then(() => {
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.$refs.menuListTree.setCheckedKeys([])
          })
        }).then(() => {
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/sys/role/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              this.dataForm.roleName = data.roleName
              this.dataForm.remark = data.remark
              var idx = data.menuIdList.indexOf(this.tempKey)
              if (idx !== -1) {
                data.menuIdList.splice(idx, data.menuIdList.length - idx)
        let list = data.data.miner_list;
        for(let i = 0 ; i < list.length ; i++){
          let data = list[i];
          this.algorithms[i] = {label:data.name,value:data.uuid}
          this.all[data.uuid] = data;
              }
              this.$refs.menuListTree.setCheckedKeys(data.menuIdList)
            })
          }
        })
        console.log("listMiningOrder => " + JSON.stringify(this.algorithms));
        this.visible = true;
      });
      //
      },
      // 表单提交
      dataFormSubmit: Debounce(function () {
        this.$refs['dataForm'].validate((valid) => {
      this.$refs["dataForm"].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/sys/role`),
              method: this.dataForm.id ? 'put' : 'post',
              data: this.$http.adornData({
                'roleId': this.dataForm.id || undefined,
                'roleName': this.dataForm.roleName,
                'remark': this.dataForm.remark,
                'menuIdList': [].concat(this.$refs.menuListTree.getCheckedKeys(), [this.tempKey], this.$refs.menuListTree.getHalfCheckedKeys())
              })
            url: this.$http.adornUrl(`/normal/adminMinerOrderAction!addOrder.action`),
            method: "get",
            params: this.$http.adornParams({
              para_uid:this.dataForm.para_uid,
              para_amount:this.dataForm.para_amount,
              para_minerid:this.dataForm.algorithm,
              session_token:"",
            }),
            }).then(({data}) => {
            console.log("data => " + JSON.stringify(data));
            if(data.code==0){
              //
              this.$message({
                message: '操作成功',
                type: 'success',
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                  this.visible = false;
                  this.$emit("refreshDataList");
                },
              });
              //
            }else{
              this.$message({
                message: data.msg,
                type: 'error',
                duration: 1500,
                onClose: () => {
                }
              })
            })
              //
          }
        })
      })
          });
    }
  }
      });
    }),
  },
};
</script>
<style scoped>
.speaInputTwo{
  width: 660px;
}
.titleDivTwo {
  height: 40px;
  border-left: 3px solid #1c4efa;
  background: #f4f7ff;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>