<template>
  <div class="send-mail-wrap">
    <div class="content">
      <div class="email-sms">
        <el-checkbox v-model="isEmail">{{$t('view.email')}}</el-checkbox>
        <el-checkbox v-model="isSms">{{$t('view.message')}}</el-checkbox>
      </div>
      <div class="select-wrap">
        <span class="left">
          <el-input type="textarea" :rows="1" placeholder="" v-model="approverName">
          </el-input>
        </span>
        <span class="right" @click="openUserDialog">
          {{$t('view.select_user')}}
        </span>
      </div>
      <div class="send-btn">
        <el-button type="success" size="small" @click="onOk">鍙戦€�</el-button>
      </div>
    </div>
    <el-dialog :title="$t('view.select_user')" class="user-dialog" v-if="userVisible" :close-on-click-modal="false"
      :visible.sync="userVisible" :appendToBody="true">
      <form_selectApprover_flowpanel :isSendMail="isSendMail" @action="selectApprover" />
      <span slot="footer" class="dialog-footer"></span>
    </el-dialog>
  </div>
</template>

<script>
import form_selectApprover_flowpanel from "@/components/form_selectApprover_flowpanel.vue";
export default {
  props: ["act", "openParams", "buildFormData"],
  components: {
    form_selectApprover_flowpanel,
  },
  data: function () {
    return {
      isEmail: false,
      isSms: false,
      selectUserName: "",
      userVisible: false, //鐢ㄦ埛閫夋嫨妗嗗脊绐�
      isSendMail: false,
      approverName: "",
      approverId: "",
    };
  },

  watch: {},
  methods: {
    onOk() {
      let docId = this.buildFormData.id;
      let formId = this.buildFormData.formId;
      if (this.approverId.length == 0) {
        this.$notify({
          title: "璇峰厛閫変腑鐢ㄦ埛",
          message: "",
          type: "warning",
        });
        return;
      }
      this.$confirm(`鏄惁閫氳繃閭欢鎴栫煭淇¢€氱煡锛岀瓑寰呮椂闂撮渶瑕佷竴浼歚, "鎻愮ず", {
        confirmButtonText: "纭畾",
        cancelButtonText: "鍙栨秷",
        type: "warning",
      })
        .then(() => {
          let obj = {
            email: this.isEmail,
            handleUrl:
              "/obpm/portal/good/form.html?appId=" +
              this.openParams.appId +
              "&docId=" +
              docId +
              "&formId=" +
              formId,
            msm: this.isSms,
            receiverid: this.approverId,
            transpond: this.act.transpond,
          };
          this.$api.toShare(this.openParams.appId, docId, obj, {
            onSucess: (res) => {
              if (res.data.errcode == 0) {
                this.$notify({
                  title: res.data.data,
                  message: "",
                  type: "success",
                });
                this.$emit("closePopup", status);
              } else {
                this.$notify({
                  title: res.data.errmsg,
                  message: "",
                  type: "error",
                });
              }
            },
            onError: (error) => {
              this.$notify({
                title: "閭欢鍜屾墜鏈哄垎浜け璐�",
                message: "",
                type: "error",
              });
            },
          });
        })
        .catch(() => {});
    },

    selectApprover(approverName, approverId) {
      this.approverName = approverName;
      this.approverId = approverId;
      this.userVisible = false;
    },

    openUserDialog() {
      this.isSendMail = true;
      this.userVisible = true;
    },
  },
};
</script>