<template>
  <el-dialog
    :title="modalTitle"
    :visible.sync="modalVisible"
    :width="formLabelWidth"
    top="2vh"
    @close="handleCancel">
    <div class="mobile">
        <el-form label-width="90px" :model="form" :rules="rules" ref="from" class="from">
            <el-form-item label="审核状态:" prop="checkState">
              <el-radio-group v-model="form.checkState">
                <el-radio label="1">审核通过</el-radio>
                <el-radio label="2">审核未通过</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="备注说明:" prop="checkRemark" v-if="form.checkState == 2">
                <el-input type="textarea" v-model="form.checkRemark" :disabled="limit.isRead"></el-input>
            </el-form-item>
        </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取 消</el-button>
      <el-button type="primary" @click="submit" v-if="!limit.isRead">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { checkPrice } from "@/api/productManage/priceManage";
export default {
  name: 'checkMobiel',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: 'title'
    },
    action: {
      type: String,
      default: 'add'
    },
    selectRow: {
      type: Object,
      default:null
    }
  },
  watch: {
    visible(newVal, oldVal) {
      this.modalVisible = newVal;
    },
    title(newVal, oldVal) {
      this.modalTitle = newVal;
    },
    action(newVal, oldVal) {
      this.modalAction = newVal;
    },
    selectRow(newVal, oldVal) {
      this.modalSelectRow = newVal;
    }
  },
  data() {
    return {
      modalTitle: this.title,
      modalVisible: this.visible,
      modalAction: this.action,
      modalSelectRow: this.selectRow,
      formLabelWidth: '624px',
      //窗口权限
      limit: {
        isRead: false, //是否只读
        isAdd: false //是否可写
      },
      priceTypelist:[],
      //验证
      rules: {
        checkState: [{ required: true, message: '审核状态不能为空!', trigger: 'blur' }],
        checkRemark: [{ required: true, message: '备注不能为空!', trigger: 'blur' }],
      },
      //表单
      form: {
        checkState:'1'
      }
    };
  },
  created() {
    switch (this.modalAction) {
      case 'add':
        this.limit.isAdd = true;
        break;
      default:
        break;
    }
  },
  methods: {
    //表单提交
    submit() {
      this.$refs.from.validate(valid => {
        if (valid) {
          let params = Object.assign({},this.form)
          params.guid = this.modalSelectRow.guid
          console.log(params)
          checkPrice(params).then(res => {
              if (res.retHead.errCode === 0) {
                this.msgSuccess("操作成功");
                this.modalVisible = false
                this.$emit('closeCheckModal', true);
              }
          });
        } else {
          return false;
        }
      });
    },
    //窗口关闭
    handleCancel() {
      this.$emit('closeCheckModal', false);
    }
  }
};
</script>

<style lang="scss" scoped>
  .hc-box{
    border:1px solid #e9e9e9;
    margin-bottom:20px;
    .hc-box-header{
        height:40px;
        line-height:40px;
        background:#fafafa;
        font-weight:bold;
        color:#333;
        padding:0 15px;
        .action{
          margin-left:10px;
          color:#304FFE
        }
    }
  }
</style>
