<template>
  <el-dialog :title="title" :close-on-click-modal="false" :visible.sync="open" width="700px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="客户名称" prop="nickName">
            <el-input v-model="form.nickName" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="客户电话" prop="phoneNumber">
            <el-input v-model="form.phoneNumber" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="金额变化" prop="account">
            <el-input-number v-model="form.account" placeholder="请输入修改后的金额" />
          </el-form-item>
        </el-col>
      </el-row>
<!--      <el-row>
        <el-col :span="24">
          <el-form-item label="原因" prop="operatorRemark">
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入原因"
              v-model="form.operatorRemark">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>-->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import ImageUpload from '@/components/ImageUpload/index'
  import { getDkCustomer, updateDkCustomer } from '@/api/dk/dkCustomer'
  export default {
    components: {
      ImageUpload,
    },
    data () {
      return {
        open: false,
        title: '',
        form:{
          account: undefined,
          id: undefined,
          nickName: undefined,
          phoneNumber: undefined,
          operatorRemark: undefined,
        },
        rules:{
          account: [
            { required: true, message: '金额变化不能为空', trigger: 'blur' },
          ],
          /* operatorRemark: [
            { required: true, message: '修改原因不能为空', trigger: 'blur' },
          ], */
        },
        buttonLoading:false,
      }
    },
    created() {
    },
    methods: {
      init (id) {
        this.form.id = id || undefined;
        this.open = true;
        this.$nextTick(() => {
          this.$refs['form'].resetFields();
          getDkCustomer(id).then(response => {
            this.form.id = response.data.id;
            this.form.nickName = response.data.nickName;
            this.form.phoneNumber = response.data.phoneNumber;
            this.form.account = response.data.account;
            this.open = true;
            this.title = "修改商家余额";
          });
        })
      },
      // 表单提交
      submitForm () {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.buttonLoading = true;
            updateDkCustomer({
              id: this.form.id,
              account: this.form.account
            }).then(data => {
                this.$modal.msgSuccess("修改成功");
                this.buttonLoading = false;
                this.open = false
                this.$emit('refreshDataList')
            }).catch(() => {
                this.buttonLoading = false;
            });
          }
        })
      },
    }
  }
</script>
