<template>
  <div class="signingReview">
    <el-dialog
      :visible.sync="dialog"
      :close-on-click-modal="false"
      title="签约审核"
      append-to-body
      width="450px"
      @close="cancel"
    >
      <div class="review-verify">
        <el-radio-group
          v-model="status"
          style="width: 178px;margin-bottom: 20px;"
        >
          <el-radio :label="0">通过</el-radio>
          <el-radio :label="1">驳回 </el-radio>
        </el-radio-group>
        <!-- :disabled="status === 1 ? false : true" -->
        <el-input
          v-model="examineReason"
          class="review-reason"
          type="textarea"
          :rows="6"
          :maxlength="200"
          :autosize="{ minRows: 6, maxRows: 12 }"
          placeholder="请输入理由"
          size="small"
          show-word-limit
          resize="none"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialog = false">取 消</el-button>
        <el-button type="primary" size="small" @click="save()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { updateStatus } from "@/utils/portfolio";
import { mapGetters } from "vuex";
import { auditTyOrder } from "@/api/order";
export default {
  data() {
    return {
      id: null,
      dialog: false,
      createTime: null,
      data: {},
      examineReason: "",
      status: null
    };
  },
  computed: {
    ...mapGetters(["user"])
  },
  watch: {
    dialog: {
      handler(newName) {
        newName;
      },
      deep: true
    }
  },
  methods: {
    updateStatus,
    async save() {
      if (!this.status && this.status !== 0) {
        return this.$message.error("请选择审核结果");
      }
      if (!this.examineReason.trim()) {
        return this.$message.error("请输入理由");
      }
      const params = {};
      params.orderId = this.id;
      params.status = this.status;
      params.reason = this.examineReason;
      // if (this.status === 1) {
      //   params.reason = this.examineReason
      // } else {
      //   params.reason = ''
      // }
      // if (params) {
      //   console.log(params)
      //   return
      // }
      const data = await auditTyOrder(params);
      if (data.code === 0) {
        this.$message.success("操作成功");
        // this.resetForm()
        this.dialog = false;
      } else {
        this.$message.error(data.message);
      }
      console.log(data);
    },
    cancel() {
      this.resetForm();
    },
    resetForm() {
      // console.log('clear')
      this.id = null;
      this.createTime = null;
      this.examineReason = "";
      this.status = null;
      this.data = {};
      this.dialog = false;
      this.$parent.getOrderList();
    },
    getPeriod(period) {
      // switch (period) {
      //   case 0:
      //     return '免费永久,单笔提佣'
      //   case 7:
      //     return '周'
      //   case 14:
      //     return '月'
      //   case 16:
      //     return '季度'
      //   case 19:
      //     return '半年'
      //   case 20:
      //     return '年'
      //   case 99:
      //     return '收费永久,单篇收费'
      //   default:
      //     break
      // }
      switch (period) {
        case 1:
          return "周";
        case 2:
          return "月";
        case 3:
          return "季度";
        case 4:
          return "半年";
        case 5:
          return "年";
        case 0:
          return "收费永久,单篇收费";
        default:
          break;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.signingReview {
  display: inline-block;
  .review-verify {
    .review-reason {
      width: 100%;
    }
  }
}
</style>
