changePrice.vue 2.48 KB
<template>
  <div class="updatePrice">
    <el-dialog
      :visible.sync="visible"
      :close-on-click-modal="false"
        custom-class="bian_css"
      title="商品改价"
        width="65%"
    >
      <el-form
        ref="ruleForm"
        :model="ruleForm"
        :rules="rules"
        label-width="120px"
      >
        <el-form-item label="订单应付价格" prop="price">
          <el-input v-model="ruleForm.price" disabled />
        </el-form-item>
        <el-form-item label="修改价格" prop="newPrice">
          <el-input
            v-model="ruleForm.newPrice"
            @change="
              (val) => {
                scope.row.newPrice = parseFloat(val) ? parseFloat(val) : 1;
              }
            "
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="loading" @click="changeOrderPrice('ruleForm')" style="background-color: #3F9B6A;color: #fff">确 定</el-button>
        <el-button @click="cancel('ruleForm')"    class="buttonHover"
                  style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { updateOrderPrice } from '@/api/order'
export default {
  data() {
    return {
      visible: false,
      loading: false,
      ruleForm: {
        orderId: null,
        price: 0,
        newPrice: 0
      },
      rules: {
        newPrice: [
          { required: true, message: '请输入修改后的价格', trigger: 'blur' }
        ],
      }
    }
  },
  methods: {
    show(row) {
      this.visible = true
      this.ruleForm.orderId = row.orderId
      this.ruleForm.price = row.price
    },
    cancel(ref) {
      this.$refs[ref].resetFields();
      this.visible = false
    },
    changeOrderPrice(ref) {
      this.$refs[ref].validate((valid) => {
        if (valid && !this.loading) {
          this.loading = true
          updateOrderPrice({
            orderId: this.ruleForm.orderId,
            price: this.ruleForm.newPrice,
          }).then(res => {
            if (res.code === '') {
              this.$message.success('修改成功')
              this.visible = false
              this.$emit('success')
            }
          }).catch(err => {
            console.log(err)
          }).finally(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>

<style lang="scss">
@import url("../../../../styles/elDialog.scss");
</style>