<template>
  <el-dialog
    title="编辑"
    append-to-body
    :visible.sync="dialogObj.show"
    width="800px">
    <el-form label-width="100px" style="margin-top: 20px;">
      <el-form-item label="收货人" required>
        <el-input v-model="form.receive_name" type="text"></el-input>
      </el-form-item>
      <el-form-item label="收货手机号" required>
        <el-input v-model="form.receive_mobile" type="text"></el-input>
      </el-form-item>
      <el-form-item label="收货地址" required>
        <el-input v-model="form.receive_address" type="text"></el-input>
      </el-form-item>
      <el-form-item label="物流状态">
        <el-radio-group v-model="form.status">
          <el-radio :label="0">待发货</el-radio>
          <el-radio :label="1">已发货</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="物流单号">
        <el-input v-model="form.express_no" type="text"></el-input>
      </el-form-item>
      <el-form-item label="物流名称">
        <el-input v-model="form.express_name" type="text"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogObj.show = false">取 消</el-button>
      <el-button type="primary" @click="saveAddress">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {putDisposableApi} from "../../service/api";

  export default {
    name: "dialogObj",
    props: [
      'dialogObj'
    ],
    data() {
      return {
        form: {

        }
      }
    },
    watch: {
      'dialogObj.show': {
        deep: true,
        handler: function () {
          console.log(this.dialogObj)
          this.form = JSON.parse(JSON.stringify(this.dialogObj))
        }
      }
    },
    methods: {
      saveAddress() {

        if (!this.form.receive_name) {
          this.$message({
            type: 'error',
            message: '请输入收货人名'
          });
          return
        }
        if (!this.form.receive_mobile) {
          this.$message({
            type: 'error',
            message: '请输入收货手机号'
          });
          return
        }
        if (!this.form.receive_address) {
          this.$message({
            type: 'error',
            message: '请输入收货地址'
          });
          return
        }

        this.$confirm('确定保存?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let json = {
            deliver_id: this.form.id,
            receive_address: this.form.receive_address,
            receive_name: this.form.receive_name,
            receive_mobile: this.form.receive_mobile,
            express_no: this.form.express_no,
            express_name: this.form.express_name,
            status: this.form.status
          };
          //this.form.express_no ? json.express_no = this.form.express_no : '';
          //this.form.express_name ? json.express_name = this.form.express_name : '';
          putDisposableApi(this.form.id, json).then(res => {
            this.$message({
              type: 'success',
              message: '修改成功'
            });
            this.dialogObj.show = false;
            this.$emit("reflash");
          });
        })
      },
    },
    mounted() {
      console.log(this.dialogObj)
    }
  }
</script>
