<!--
 * @Description: 党建管理 => 组织关系变更
 * @Author: Rockery
 * @Date: 2021-12-10 10:45:41
 * @LastEditors: Rockery
 * @LastEditTime: 2022-01-21 16:07:36
 * @FilePath: \party_construct_web\src\views\PartyBuildingMgr\OrgRelationship\OrgRelationshipIndex.vue
 * @Copyright: Copyright (c) 2016~2021 Rockery(1113269755@qq.com)
-->

<template>
  <div
    class="app-container orgrelationship"
    :class="['ADD','VIEW'].includes(pageType) ? 'desc-page':''"
  >
    <template v-if="pageType === 'LIST'">
      <div class="orgrelationship-main">
        <el-row :gutter="10">
          <el-col :span="24">
            <div class="orgrelationship-main-title">
              <div>
                <img
                  :src="require('@/assets/logo/home-main-title-logo.png')"
                  @error="imgViewerOnerror"
                />
              </div>
              <div>组织关系变更</div>
            </div>
          </el-col>
          <div v-loading="loading">
            <el-col :span="24" class="mt20">
              <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
                <el-form-item prop="beginTime">
                  <el-date-picker
                    v-model="queryParams.beginTime"
                    type="date"
                    size="small"
                    clearable
                    format="yyyy年MM月dd日"
                    value-format="yyyy-MM-dd"
                    style="width: 100%;"
                    placeholder="请选择开始时间"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item prop="endTime">
                  <el-date-picker
                    v-model="queryParams.endTime"
                    type="date"
                    size="small"
                    clearable
                    format="yyyy年MM月dd日"
                    value-format="yyyy-MM-dd"
                    style="width: 100%;"
                    placeholder="请选择结束时间"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item prop="name">
                  <el-input
                    v-model="queryParams.name"
                    placeholder="请输入姓名/身份证号"
                    clearable
                    size="small"
                    style="width: 100%;"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    v-hasPermi="['partybuildingmgr:orgrelationship:query']"
                    type="primary"
                    icon="el-icon-search"
                    @click="handleQueryClick"
                  >搜索</el-button>
                  <el-button
                    v-hasPermi="['partybuildingmgr:orgrelationship:reset']"
                    icon="el-icon-refresh"
                    @click="resetQueryClick"
                  >重置</el-button>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="24">
              <el-button
                v-hasPermi="['partybuildingmgr:orgrelationship:add']"
                type="rocpartyprimarybtn"
                icon="el-icon-circle-plus-outline"
                class="fr mb10"
                @click="handleReactivateClick"
              >转入</el-button>
            </el-col>
            <el-col :span="24">
              <el-table
                :data="list"
                stripe
                border
                :header-cell-style="{'text-align':'center'}"
                header-row-class-name="orgrelationship-table_header-row"
                class="orgrelationship-main-table"
                style="width: 100%;"
              >
                <el-table-column label="姓名" prop="name" :show-overflow-tooltip="true" />
                <el-table-column label="身份证号" prop="cardNo" :show-overflow-tooltip="true">
                  <template slot-scope="scope">
                    <span>{{ scope.row.cardNo || '—' }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="类型"
                  prop="modifyType"
                  align="center"
                  :show-overflow-tooltip="true"
                >
                  <template slot-scope="scope">
                    <span>{{ orgRelationChangeTypeFormat(scope.row) || '—' }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="备注" prop="remark" :show-overflow-tooltip="true">
                  <template slot-scope="scope">
                    <span>{{ scope.row.remark || '—' }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="时间"
                  align="center"
                  prop="modifyTime"
                  width="180"
                  :show-overflow-tooltip="true"
                >
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.modifyTime, '{y}年{m}月{d}日') || '—' }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  align="center"
                  fixed="right"
                  width="160"
                  class-name="small-padding fixed-width"
                >
                  <template slot-scope="scope">
                    <el-button
                      v-if="scope.row.modifyType === 0"
                      v-hasPermi="['partybuildingmgr:orgrelationship:edit']"
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      style="color: #de0010;"
                      @click="handleEditClick(scope.row)"
                    >完善资料</el-button>
                    <el-button
                      v-hasPermi="['partybuildingmgr:orgrelationship:view']"
                      size="mini"
                      type="text"
                      icon="el-icon-view"
                      style="color: #909399;"
                      @click="handleViewClick(scope.row)"
                    >详情</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
            <el-col :span="24">
              <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="initData"
              />
            </el-col>
          </div>
        </el-row>
      </div>
    </template>
    <template v-else-if="pageType === 'VIEW'">
      <div class="orgrelationship-viewpage">
        <el-row>
          <el-col :span="24">
            <div class="orgrelationship-viewpage-title">
              <div>
                <img
                  :src="require('@/assets/logo/home-main-title-logo.png')"
                  @error="imgViewerOnerror"
                />
              </div>
              <div>组织关系变更详情</div>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="orgrelationship-viewpage-line"></div>
          </el-col>
          <el-col :span="24">
            <el-form
              ref="orgRelationshipViewpageFormRef"
              :model="viewPageFormObj.formModel"
              label-width="120px"
              class="orgrelationship-viewpage-form"
            >
              <el-row>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                  <el-form-item label prop="modifyTime">
                    <div slot="label" class="roc-form-item-label">变更时间：</div>
                    <div
                      class="roc-form-item-input"
                    >{{ parseTime(viewPageFormObj.formModel.modifyTime, '{y}年{m}月{d}日') || '—' }}</div>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                  <el-form-item label="姓名：" prop="memberName">
                    <div slot="label" class="roc-form-item-label">姓名：</div>
                    <div
                      class="roc-form-item-input"
                    >{{ viewPageFormObj.formModel.name || viewPageFormObj.formModel.memberName || '—' }}</div>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                  <el-form-item label="身份证号：" prop="cardNo">
                    <div slot="label" class="roc-form-item-label">身份证号：</div>
                    <div class="roc-form-item-input">{{ viewPageFormObj.formModel.cardNo || '—' }}</div>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
                  <el-form-item label="类型：" prop="modifyType">
                    <div slot="label" class="roc-form-item-label">类型：</div>
                    <div
                      class="roc-form-item-input"
                    >{{ orgRelationChangeTypeFormat(viewPageFormObj.formModel) || '—' }}</div>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="相关材料：" prop="relatedFile">
                    <div slot="label" class="roc-form-item-label">相关材料：</div>
                    <div class="orgrelationship-viewpage-form-desc">
                      <div @click="handleViewPageCheckClick(viewPageFormObj.formModel)">查看</div>
                      <div
                        @click="handleViewPageDownloadClick(viewPageFormObj.formModel.relatedFile, '党建管理-组织关系变更-详情-相关材料')"
                      >下载</div>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="说明：" prop="remark">
                    <div slot="label" class="roc-form-item-label">说明：</div>
                    <div class="roc-form-item-input">{{ viewPageFormObj.formModel.remark || '—' }}</div>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-col>
        </el-row>
        <div class="pagefooter-btngroup">
          <el-button
            type="rocpartyprimaryplainbtn"
            icon="el-icon-circle-close"
            @click="handleViewPageCloseClick"
          >关 闭</el-button>
        </div>
      </div>
    </template>
    <template v-else-if="pageType === 'COMPLETEINFO'">
      <div class="toptitlepage">
        <div class="toptitlepage-head">
          <div class="toptitlepage-head-title">
            <div>
              <img
                :src="require('@/assets/logo/home-main-title-logo.png')"
                @error="imgViewerOnerror"
              />
            </div>
            <div>组织关系变更（完善资料）</div>
          </div>
        </div>
        <update-party-develop
          :id="currentRow.memberId"
          operate-type="EDIT"
          @page-submit="handleAddPageSubmitClick"
          @page-close="handleAddPageCloseClick"
        />
      </div>
    </template>
    <template v-else>
      <div>&nbsp;</div>
    </template>

    <roc-vue-pdf-dialog
      v-if="pdfDialogVisible"
      :visible.sync="pdfDialogVisible"
      :pdfUrl="viewPdfFileUrlPrefix + viewPageFormObj.formModel.relatedFile"
    ></roc-vue-pdf-dialog>

    <!-- 组织关系变更对话框 -->
    <el-dialog
      title="组织关系变更"
      :visible.sync="orgRelationChangeObj.open"
      width="700px"
      append-to-body
      :destroy-on-close="true"
      :close-on-click-modal="false"
      class="orgrelationchange-dialog"
    >
      <el-form
        ref="orgRelationChangeFormRef"
        :model="orgRelationChangeObj.form"
        :rules="orgRelationChangeObj.rules"
        label-width="100px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="变更时间：" prop="modifyTime">
              <el-date-picker
                v-model="orgRelationChangeObj.form.modifyTime"
                type="date"
                clearable
                format="yyyy年MM月dd日"
                value-format="yyyy-MM-dd"
                style="width: 100%;"
                placeholder="请选择变更时间"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名：" prop="memberName">
              <el-input
                v-model="orgRelationChangeObj.form.memberName"
                clearable
                placeholder="请输入姓名"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号：" prop="cardNo">
              <el-input v-model="orgRelationChangeObj.form.cardNo" clearable placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类型：" prop="modifyType">
              <el-select
                v-model="orgRelationChangeObj.form.modifyType"
                placeholder="请选择类型"
                clearable
                size="small"
                style="width: 100%;"
                disabled
              >
                <el-option label="转入" value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="相关材料：" prop="relatedFile">
              <roc-pdf-file-upload
                key="ROCPDFFILEUPLOADFULLPARTYMEMBERATTACHMENTKEY"
                v-model="orgRelationChangeObj.form.relatedFile"
                upload-file-title="相关材料"
              ></roc-pdf-file-upload>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="说明：" prop="remark">
              <el-input
                v-model="orgRelationChangeObj.form.remark"
                type="textarea"
                :autosize="{ minRows: 4}"
                placeholder="请输入说明"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="rocpartyprimaryplainbtn" @click="orgRelationChangeCancelClick">取 消</el-button>
        <el-button
          :disabled="!orgRelationChangeObj.form.modifyTime || !orgRelationChangeObj.form.memberName || !orgRelationChangeObj.form.cardNo || !orgRelationChangeObj.form.modifyType"
          type="rocpartyprimarybtn"
          @click="orgRelationChangeSubmitForm"
        >下一步</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrgRelationship,
  addOrgRelationship,
  viewOrgRelationship,
} from "@/api/PartyBuildingMgr/OrgRelationship";
import { regularDownloadPdfFile } from "@/utils/rockeryutil";

export default {
  name: "Orgrelationship",
  components: {
    'roc-vue-pdf-dialog': () => import('@/components/RocVuePdfDialog'),
    'roc-pdf-file-upload': () => import('@/components/RocPdfFileUpload'),
    'update-party-develop': () => import('@/components/UpdatePartyDevelop')
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      pageType: 'LIST',
      // 情况说明人选项列表
      situationExplainerOptions: [],
      total: 0,
      queryParams: {
        beginTime: undefined,
        endTime: undefined,
        name: undefined,
        pageNum: 1,
        pageSize: 10
      },
      list: [],
      viewPageFormObj: {
        formModel: {}
      },
      orgRelationChangeObj: {
        open: false,
        form: {},
        rules: {
          modifyTime: [
            { required: true, message: "变更时间不能为空", trigger: ['change', 'blur'] }
          ],
          memberName: [
            { required: true, message: "姓名不能为空", trigger: 'blur' }
          ],
          cardNo: [
            { required: true, message: "身份证号不能为空", trigger: 'blur' },
            {
              pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
              message: "请输入正确身份证号",
              trigger: 'blur'
            }
          ],
          modifyType: [
            { required: true, message: "类型不能为空", trigger: ['change', 'blur'] }
          ]
        }
      },
      currentRow: {},
      orgRelationChangeTypeOptions: [],
      pdfDialogVisible: false,
      viewPdfFileUrlPrefix: `${window.origin}${process.env.VUE_APP_FILE_VIEW_API}`
    };
  },
  created() {
    this.initData();
  },
  methods: {
    /**
    * 初始化数据
    */
    async initData() {
      await this.getSubOptions();
      this.getList();
    },
    /**
    * 获取表格数据
    */
    getList() {
      this.loading = true;
      listOrgRelationship(this.queryParams).then(
        response => {
          this.list = response.rows || [];
          this.total = response.total ?? 0;
          this.loading = false;
          this.pageType = 'LIST';
        }
      );
    },
    /**
     * 获取次要选项列表
     */
    async getSubOptions() {
      // 组织关系变更类型列表
      await this.getDicts('org_relation_change_type').then(response => {
        this.orgRelationChangeTypeOptions = response?.data || [];
      });
    },
    /** 组织关系变更类型格式化 */
    orgRelationChangeTypeFormat(row) {
      return this.selectDictLabel(this.orgRelationChangeTypeOptions, row?.modifyType);
    },
    /**
    * 搜索按钮事件
    */
    handleQueryClick() {
      this.queryParams.pageNum = 1;
      this.initData();
    },
    /**
    * 重置按钮事件
    */
    resetQueryClick() {
      this.resetForm("queryForm");
      this.handleQueryClick();
    },
    /**
    * 完善资料按钮事件
    */
    handleEditClick(row) {
      if (!row?.memberId) return;
      this.currentRow = row;
      this.pageType = 'COMPLETEINFO';
    },
    /**
    * 详情按钮事件
    */
    handleViewClick(row) {
      if (!row.id) return;

      // 获取数据
      viewOrgRelationship(row.id).then(
        viewResp => {
          this.viewPageFormObj.formModel = viewResp.data || {};
          this.pageType = 'VIEW';
        }
      );
    },
    /**
     * 详情页面查看按钮事件
     */
    handleViewPageCheckClick() {
      this.pdfDialogVisible = true;
    },
    /**
     * 详情页面下载按钮事件
     */
    handleViewPageDownloadClick(pdfFilePath, pdfFileName = 'pdf-file') {
      if (!pdfFilePath) return;
      regularDownloadPdfFile(`${window.origin}${process.env.VUE_APP_FILE_VIEW_API}${pdfFilePath}`, pdfFileName);
    },
    /**
     * 详情页面关闭按钮事件
     */
    handleViewPageCloseClick() {
      this.pageType = 'LIST';
    },
    /**
     * 预览PDF页面关闭按钮事件
     */
    handleViewPdfPageCloseClick() {
      this.pageType = 'VIEW';
    },
    /**
     * 组织关系变更事件
     */
    async handleReactivateClick() {
      // 初始化数据
      this.orgRelationChangeObj.form = {};
      this.resetForm("orgRelationChangeFormRef");
      await this.getSubOptions();
      this.orgRelationChangeObj.form = {
        modifyType: '0'
      };
      this.orgRelationChangeObj.open = true;
    },
    /**
     * 组织关系变更对话框下一步按钮事件
     */
    orgRelationChangeSubmitForm() {
      this.$refs["orgRelationChangeFormRef"].validate(valid => {
        if (valid) {
          this.$confirm('是否确认当前【下一步】操作?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            addOrgRelationship(this.orgRelationChangeObj.form).then(
              (addOrgResp) => {
                if (addOrgResp.code === 200) {
                  this.currentRow = {
                    memberId: addOrgResp.data
                  };
                  this.orgRelationChangeCancelClick();
                  this.msgSuccess("组织关系转入成功！稍后自动跳转完善资料页面！");
                  this.pageType = 'COMPLETEINFO';
                } else {
                  this.msgError("组织关系转入失败！");
                }
              }
            );
          }).catch(() => { });
        }
      });
    },
    /**
     * 组织关系变更对话框取消按钮事件
     */
    orgRelationChangeCancelClick() {
      this.orgRelationChangeObj.open = false;
      this.orgRelationChangeObj.form = {};
      this.resetForm("orgRelationChangeFormRef");
    },
    /**
     * 信息录入页面保存按钮事件
     */
    handleAddPageSubmitClick(param) {
      this.pageType = param;
      this.initData();
    },
    /**
     * 信息录入页面取消按钮事件
     */
    handleAddPageCloseClick(param) {
      this.pageType = param;
      this.initData();
    }
  }
};
</script>

<style  lang="scss" scoped>
.orgrelationship {
  .orgrelationship-main {
    padding: 20px 20px 72px;
    min-height: 750px;
    background: url("../../../assets/images/home-head-img.png"), #ffffff;
    background-size: 67px 67px, cover;
    background-position: right 20px bottom 5px, center;
    background-repeat: no-repeat, no-repeat;
    border-radius: 10px;

    &-title {
      display: flex;
      align-items: center;

      div {
        &:first-child {
          height: 37px;
          line-height: 37px;
        }

        &:last-child {
          margin-left: 15px;
          height: 37px;
          font-size: 26px;
          font-weight: 400;
          color: #4f4f4f;
          line-height: 37px;
          letter-spacing: 1px;
        }

        img {
          width: 34px;
          height: 34px;
        }
      }
    }

    &-tabs.el-tabs {
      margin-top: 20px;

      ::v-deep {
        .el-tabs__item {
          font-size: 18px;
          font-weight: 500;
          color: #4f4f4f;
          opacity: 0.9;
        }

        .el-tabs__active-bar {
          background-color: #de0010;
        }

        .el-tabs__item.is-active {
          color: #de0010;
          background: #f9e9ea;
        }
      }
    }

    &-table {
      ::v-deep {
        .orgrelationship-table_header-row th.el-table__cell {
          background-color: #e5d4b4;
        }

        .el-table__row {
          background-color: #ffffff;
        }

        .el-table__row.el-table__row--striped {
          background-color: #f0f0f0;
        }
      }
    }
  }

  &-viewpage {
    width: 100%;

    &-title {
      display: flex;
      align-items: center;
      margin-bottom: 5px;

      div {
        &:first-child {
          height: 37px;
          line-height: 37px;
        }

        &:last-child {
          margin-left: 15px;
          height: 37px;
          font-size: 26px;
          font-weight: 400;
          color: #4f4f4f;
          line-height: 37px;
          letter-spacing: 1px;
        }

        img {
          width: 34px;
          height: 34px;
        }
      }
    }

    &-line {
      width: 100%;
      height: 1px;
      background: #d8dce5;
      margin-bottom: 15px;
    }

    &-form {
      padding: 0 10%;

      &-desc {
        display: flex;
        align-items: center;
        width: 100%;
        height: 36px;
        line-height: 36px;

        div {
          display: flex;
          align-items: center;
          justify-content: center;
          height: 36px;
          font-weight: 400;
          font-style: normal;
          font-size: 18px;
          color: rgba(24, 144, 255, 0.996);
          line-height: 36px;
          cursor: pointer;

          &:last-child {
            margin-left: 20px;
          }

          &:hover {
            text-decoration: underline;
          }
        }
      }

      &-processnode {
        ::v-deep {
          .el-checkbox {
            display: flex;
            align-items: center;

            .el-checkbox__input {
              display: flex;
              align-items: center;
              justify-content: center;
              height: 36px;
              line-height: 36px;
            }

            .el-checkbox__label {
              display: flex;
              align-items: center;
            }

            &.is-disabled {
              cursor: not-allowed;
            }
          }
        }
        .processnode-circle {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 24px;
          height: 24px;
          font-size: 14px;
          color: #323232;
          background: #ffffff;
          border: 1px solid #323232;
          border-radius: 50%;
          line-height: 36px;
          opacity: 0.9;
        }

        .processnode-label {
          display: flex;
          align-items: center;
          margin-left: 5px;
          height: 36px;
          font-size: 16px;
          font-weight: 400;
          color: #333333;
          line-height: 36px;
          opacity: 0.9;
        }
      }
    }
  }
}
</style>