<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="wfTransferSetting">
      <div class="d-header clearfix">
        <div class="fl">
          <i class="el-icon-info" />
          {{ dataId ? $t1("查看转派设置") : $t1("新增转派设置") }}
        </div>
        <div class="fr">
          <el-button
            type="primary"
            plain
            class="button-sty"
            @click="$baseReload()"
            icon="el-icon-refresh-right"
          >
            {{ $t1("重置") }}
          </el-button>
          <el-button
            type="primary"
            class="button-sty"
            icon="el-icon-check"
            @click="saveData"
            >{{ $t1("保存") }}
          </el-button>
        </div>
      </div>
      <baseTabs>
        <baseTabPane :label="$t1('基本信息')">
          <template #default>
            <table class="table-detail">
              <tbody>
                <tr>
                  <th>
                    <em class="f-red">*</em>
                    {{ $t1("审批人") }}
                  </th>
                  <td>
                    <el-form-item
                      prop="transferFromName"
                      :rules="[
                        {
                          required: true,
                          trigger: ['blur', 'change'],
                        },
                      ]"
                    >
                      <el-input
                        class="search-input"
                        max="200"
                        v-model="wfTransferSetting.transferFromName"
                        @clear="
                          wfTransferSetting.transferFromName = null;
                          wfTransferSetting.transferFrom = null;
                        "
                        v-el-readonly
                        clearable
                      >
                        <i
                          slot="suffix"
                          class="el-input__icon el-icon-search"
                          @click="showUserDialog1 = true"
                        ></i>
                      </el-input>
                    </el-form-item>
                  </td>
                  <th>
                    {{ $t1("转派给") }}
                  </th>
                  <td>
                    <el-form-item
                      prop="transferToName"
                      :rules="[
                        {
                          required: false,
                          trigger: ['blur', 'change'],
                        },
                      ]"
                    >
                      <el-input
                        class="search-input"
                        max="200"
                        v-model="wfTransferSetting.transferToName"
                        @clear="
                          wfTransferSetting.transferToName = null;
                          wfTransferSetting.transferTo = null;
                        "
                        v-el-readonly
                        clearable
                      >
                        <i
                          slot="suffix"
                          class="el-input__icon el-icon-search"
                          @click="showUserDialog2 = true"
                        ></i>
                      </el-input>
                    </el-form-item>
                  </td>
                  <th>
                    <em class="f-red">*</em>
                    {{ $t1("有效开始时间") }}
                  </th>
                  <td>
                    <el-form-item
                      prop="startDate"
                      :rules="[
                        {
                          required: true,
                          trigger: ['blur', 'change'],
                        },
                      ]"
                    >
                      <el-date-picker
                        v-model="wfTransferSetting.startDate"
                        type="datetime"
                        size="small"
                        clearable
                        value-format="yyyy-MM-dd HH:mm:ss"
                        default-time="00:00:00"
                        :picker-options="$baseStartPickerOptions(wfTransferSetting.endDate)"
                      ></el-date-picker>
                    </el-form-item>
                  </td>
                  <th>
                    <em class="f-red">*</em>
                    {{ $t1("有效结束时间") }}
                  </th>
                  <td>
                    <el-form-item
                      prop="endDate"
                      :rules="[
                        {
                          required: true,
                          trigger: ['blur', 'change'],
                        },
                      ]"
                    >
                      <el-date-picker
                        v-model="wfTransferSetting.endDate"
                        type="datetime"
                        size="small"
                        clearable
                        value-format="yyyy-MM-dd HH:mm:ss"
                        default-time="23:59:59"
                        :picker-options="$baseEndPickerOptions(wfTransferSetting.startDate)"
                      ></el-date-picker>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <th>{{ $t1("创建人") }}</th>
                  <td>{{ wfTransferSetting._createBy }}</td>
                  <th>{{ $t1("创建时间") }}</th>
                  <td>{{ wfTransferSetting.createDate }}</td>
                  <th>{{ $t1("更新人") }}</th>
                  <td>{{ wfTransferSetting._modifyBy }}</td>
                  <th>{{ $t1("更新时间") }}</th>
                  <td>{{ wfTransferSetting.modifyDate }}</td>
                </tr>
              </tbody>
            </table>
          </template>
        </baseTabPane>
      </baseTabs>
    </el-form>
    <userDialog
      v-if="showUserDialog1"
      :visiable.sync="showUserDialog1"
      @confirm="confirmUserDialog1"
      :multi="false"
      :param="{ enabled: null }"
    />
    <userDialog
      v-if="showUserDialog2"
      :visiable.sync="showUserDialog2"
      @confirm="confirmUserDialog2"
      :multi="false"
    />
  </div>
</template>

<script>
import userDialog from "@base/views/user/user/dialog";
export default {
  name: "wfTransferSettingEdit",
  props: {
    _dataId: [String, Number],
  },
  components: { userDialog },
  data() {
    return {
      isEdit: false,
      tabIndex: "first",
      dataId: "",
      wfTransferSetting: {
        transferFromName: null,
        transferToName: null,
        transferFrom: null,
        transferTo: null,
        startDate: null,
        endDate: null,
      },
      showUserDialog1: false,
      showUserDialog2: false,
    };
  },
  created() {
    if (this._dataId && !isNaN(this._dataId)) this.dataId = this._dataId;
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      if (this.dataId && !isNaN(this.dataId)) {
        this.isEdit = true;
        this.$commonHttp({
          url: USER_PREFIX + `/wf_transfer_setting/get`,
          method: `post`,
          data: {
            id: this.dataId,
          },
          isLoading: true,
          modalStrictly: true,
          success: (res) => {
            this.wfTransferSetting = res.objx || {};
          },
        });
      }
    },
    saveData() {
      this.$refs.editForm.$baseValidate((valid) => {
        if (valid) {
          this.$baseConfirm(this.$t1("您确定要保存吗？")).then(() => {
            var url =
              USER_PREFIX +
              (this.isEdit ? `/wf_transfer_setting/update` : `/wf_transfer_setting/save`);
            this.$http({
              url: url,
              method: `post`,
              data: this.wfTransferSetting,
              isLoading: true,
              success: (res) => {
                this.$message({
                  message: res.content,
                  type: "success",
                  duration: 500,
                  onClose: (t) => {
                    if (this.isEdit) {
                      this.$baseReload();
                    } else {
                      this.$baseReload({
                        updateParam: {
                          _dataId: res.objx,
                        },
                      });
                    }
                  },
                });
              },
            });
          });
        }
      });
    },
    confirmUserDialog1(rows) {
      if (rows.length) {
        let row = rows[0];
        this.wfTransferSetting.transferFrom = row.id;
        this.wfTransferSetting.transferFromName = row.nickName;
      }
    },
    confirmUserDialog2(rows) {
      if (rows.length) {
        let row = rows[0];
        this.wfTransferSetting.transferTo = row.id;
        this.wfTransferSetting.transferToName = row.nickName;
      }
    },
  },
};
</script>
