<!-- 机构任务 -->
<template>
  <div v-loading="tableLoading">
    <el-card class="query-container" shadow="never">
      <!-- 表格查询条件 -->
      <div>
        <div :span="24">
          <el-form ref="seachForm" :inline="true" class="demo-form-inline">
            <el-form-item label="机构代码">
              <el-input
                v-model="query.branchCode"
                placeholder="请输入"
                maxlength="32"
                clearable
              />
            </el-form-item>
            <el-form-item label="机构名称">
              <el-input
                v-model="query.branchName"
                placeholder="请输入"
                maxlength="32"
                clearable
              />
            </el-form-item>
            <el-form-item label="开始时间">
              <el-date-picker
                v-model="query.startDate"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
                clearable
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间">
              <el-date-picker
                v-model="query.endDate"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
                clearable
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                @click="queryTable"
              >
                查询
              </el-button>
              <el-button
                type="reset"
                icon="el-icon-refresh"
                @click="resetQueryTable"
              >
                重置
              </el-button>
              <el-button
                type="reset"
                icon="el-icon-download"
                @click="exportData"
                >导出
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-card>

    <el-card class="el-row-main-container box-card box-card--table">
      <!-- 表格主体 -->
      <el-table
        ref="multipleTable"
        tooltip-effect="dark"
        :data="tableData"
        class="w100p"
        @selection-change="handleSelectionChange"
        border
        @sort-change="sortChange"
        :default-sort="tableSort"
        header-cell-class-name="duojibiaotou"
      >
        <!-- <el-table-column type="selection" width="50" /> -->
        <el-table-column
          align="center"
          label="机构代码"
          show-overflow-tooltip
          min-width="90"
          prop="branchCode"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="机构名称"
          show-overflow-tooltip
          min-width="160"
          prop="branchName"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="任务标题"
          show-overflow-tooltip
          min-width="160"
          prop="sdTaskOther.taskTitle"
        />
        <el-table-column
          align="center"
          label="开始时间"
          show-overflow-tooltip
          min-width="120"
          prop="sdTaskOther.startDate"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="结束时间"
          show-overflow-tooltip
          min-width="120"
          prop="sdTaskOther.endDate"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="反馈时间"
          show-overflow-tooltip
          min-width="120"
          prop="sdTaskOtherFeedbackByFeedback.feedbackTime"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="反馈状态"
          show-overflow-tooltip
          min-width="90"
        >
          <template v-slot="{ row }">
            <template v-if="row.sdTaskOther && row.sdTaskOther.status === '2'">
              <el-tag
                type="success">已办结</el-tag>
            </template>
            <template v-else-if="row.sdTaskOtherFeedbackByCreate">
              <el-tag v-if="row.sdTaskOtherFeedbackByCreate.status === '1'"
                >已反馈</el-tag
              >
              <el-tag
                v-else-if="row.sdTaskOtherFeedbackByCreate.status === '2'"
                type="success"
                >已通过</el-tag
              >
              <el-tag
                v-else-if="row.sdTaskOtherFeedbackByCreate.status === '-1'"
                type="danger"
                >驳回</el-tag
              >
              <el-tag v-else type="info">未反馈</el-tag>
            </template>
            <el-tag v-else type="info">未反馈</el-tag>
          </template>
        </el-table-column>
        <el-table-column width="80px" align="center" label="操作" fixed="right">
          <template slot-scope="scope">
            <el-link
              class="table-opretar"
              type="primary"
              @click="toEdit(scope.row)"
              >{{ getRowEditTitle(scope.row) }}</el-link
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 表格页脚 -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="page.pageNum"
        :limit.sync="page.pageSize"
        @pagination="getTableList"
      />
    </el-card>
    <AuditDialog ref="editDialog" :isAudit="!isPublish" @refresh="getTableList"></AuditDialog>
  </div>
</template>

<script>
import AuditDialog from "@/views/task-distribut/send/other-task/components/AuditDialog";
import TableMixin from "@/mixins/table-mixin";
import { pageListBranch } from "@/api/task/branch";

export default {
  name: "BranchOtherTask",
  components: {
    AuditDialog,
  },
  mixins: [TableMixin],
  pageInfo: {
    title: "机构任务",
    exportUrl: "/task/other/branch/export",
    pageListApi: pageListBranch,
    // deleteApi: delOther,
    defaultQuery: {
      isPublish: "1",
      taskId: "",
    },
  },
  props: {
    customLoad: {
      type: Boolean,
      default: false,
    },
    // 查询发布的
    isPublish: {
      type: Boolean,
      default: true,
    },
    taskId: {
      type: [Number, String],
      default: "",
    },
  },
  watch: {
    taskId(val) {
      this.$options.pageInfo.defaultQuery.taskId = val;
      this.tableData = [];
      if (!val) {
        return;
      }
      this.resetQueryTable();
    },
  },
  data() {
    return {};
  },
  methods: {
    // isMe(row) {
    //   return row.userId === this.$store.getters?.userInfo?.userId;
    // },
    MXCreated() {
      this.$options.pageInfo.defaultQuery.taskId = null,
      this.query.taskId = null;
      this.$options.pageInfo.customLoad = this.customLoad;
      this.$options.pageInfo.defaultQuery.isPublish = this.isPublish ? "1" : "";
      this.query.isPublish = this.$options.pageInfo.defaultQuery.isPublish;
    },
    getRowEditTitle(row) {
      if (row.sdTaskOther && row.sdTaskOther.status === '2') {
        return "查看";
      }
      if (this.isPublish) {
        if (
          !row.sdTaskOtherFeedbackByCreate?.status ||
          row.sdTaskOtherFeedbackByCreate?.status === "0" ||
          row.sdTaskOtherFeedbackByCreate?.status === "-1"
        ) {
          return "反馈";
        }
        return "查看";
      }
      if (row.sdTaskOtherFeedbackByCreate?.status === "1") {
        return "审核";
      }
      return "查看";
    },
  },
};
</script>
