<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="" prop="taskName">
        <el-input
          v-model="queryParams.taskName"
          placeholder="请输入任务名称"
          clearable
          @input="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <!-- <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        > -->
        <el-button icon="el-icon-refresh" type="btr" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['workingArrangements:worktaskplan:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['workingArrangements:worktaskplan:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['workingArrangements:worktaskplan:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['workingArrangements:worktaskplan:export']"
          >导出</el-button
        >
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="worktaskplanList"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ background: '#003C69', color: 'white' }"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center">
        <template scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务名称" align="center" prop="taskName" />
      <el-table-column
        label="开始时间"
        align="center"
        prop="startTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="结束时间"
        align="center"
        prop="endTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务总数" align="center" prop="annex" />
      <el-table-column label="当前进度" align="center" prop="annex" />
      <el-table-column label="执行单位数" align="center" prop="annex" />
      <!-- <el-table-column label="任务附件" align="center" prop="annex" /> -->
      <el-table-column label="备注" align="center" prop="remarkInfo" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['workingArrangements:worktaskplan:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['workingArrangements:worktaskplan:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改任务计划基本信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="700px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        inline
      >
        <el-form-item label="任务名称" prop="taskName">
          <el-input v-model="form.taskName" placeholder="" class="ren_wu" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker
            clearable
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder=""
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker
            clearable
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder=""
          >
          </el-date-picker>
        </el-form-item>
        <div class="jiben">任务附件</div>
        <fileUpload v-model="form.annexList" class="m-l-20" :limit="5" />
        <div class="jiben">备注</div>
        <el-form-item label="" prop="remarkInfo">
          <el-input
            v-model="form.remarkInfo"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        inline
      >
        <el-form-item label="任务名称" prop="taskName">
          <el-input v-model="form.taskName" placeholder="请输入任务名称" />
        </el-form-item>
        <el-form-item label="任务开始时间" prop="startTime">
          <el-date-picker
            clearable
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择任务开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="任务结束时间" prop="endTime">
          <el-date-picker
            clearable
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择任务结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="任务附件" prop="annex">
          <el-input v-model="form.annex" placeholder="请输入任务附件" />
        </el-form-item>
        <el-form-item label="任务备注" prop="remarkInfo">
          <el-input v-model="form.remarkInfo" placeholder="请输入任务备注" />
        </el-form-item>
        <el-divider content-position="center">任务计划执行详情信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddBdglWorkTaskPlanDetail"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteBdglWorkTaskPlanDetail"
              >删除</el-button
            >
          </el-col>
        </el-row>
        <el-table
          :data="bdglWorkTaskPlanDetailList"
          :row-class-name="rowBdglWorkTaskPlanDetailIndex"
          @selection-change="handleBdglWorkTaskPlanDetailSelectionChange"
          ref="bdglWorkTaskPlanDetail"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          />
          <el-table-column label="单位ID" prop="unitId" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.unitId" placeholder="请输入单位ID" />
            </template>
          </el-table-column>
          <el-table-column label="任务执行人" prop="peopleName" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.peopleName"
                placeholder="请输入任务执行人"
              />
            </template>
          </el-table-column>
          <el-table-column label="任务描述" prop="taskDescription" width="150">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.taskDescription"
                placeholder="请输入任务描述"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="任务执行情况0.待审核1.未完成2.已完成3.驳回"
            prop="taskStatus"
            width="150"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.taskStatus"
                placeholder="请选择任务执行情况0.待审核1.未完成2.已完成3.驳回"
              >
                <el-option label="请选择字典生成" value="" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="任务反馈时间" prop="feedbackTime" width="240">
            <template slot-scope="scope">
              <el-date-picker
                clearable
                v-model="scope.row.feedbackTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择任务反馈时间"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="反馈内容"
            prop="feedbackDescription"
            width="150"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.feedbackDescription"
                placeholder="请输入反馈内容"
              />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import {
  listWorktaskplan,
  getWorktaskplan,
  delWorktaskplan,
  addWorktaskplan,
  updateWorktaskplan,
} from "@/api/workingArrangements/worktaskplan";

export default {
  name: "Worktaskplan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedBdglWorkTaskPlanDetail: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务计划基本信息表格数据
      worktaskplanList: [],
      // 任务计划执行详情表格数据
      bdglWorkTaskPlanDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskName: null,
        startTime: null,
        endTime: null,
        annex: null,
        remarkInfo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        taskName: [
          { required: true, message: "任务名称不能为空", trigger: "blur" },
        ],
        startTime: [
          { required: true, message: "任务开始时间不能为空", trigger: "blur" },
        ],
        endTime: [
          { required: true, message: "任务结束时间不能为空", trigger: "blur" },
        ],
        annex: [
          { required: true, message: "任务附件不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询任务计划基本信息列表 */
    getList() {
      this.loading = true;
      listWorktaskplan(this.queryParams).then((response) => {
        this.worktaskplanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        taskName: null,
        startTime: null,
        endTime: null,
        annex: null,
        remarkInfo: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.bdglWorkTaskPlanDetailList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增工作任务";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getWorktaskplan(id).then((response) => {
        this.form = response.data;
        this.bdglWorkTaskPlanDetailList =
          response.data.bdglWorkTaskPlanDetailList;
        this.open = true;
        this.title = "修改工作任务";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.bdglWorkTaskPlanDetailList =
            this.bdglWorkTaskPlanDetailList;
          if (this.form.id != null) {
            updateWorktaskplan(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWorktaskplan(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除任务计划基本信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delWorktaskplan(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 任务计划执行详情序号 */
    rowBdglWorkTaskPlanDetailIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 任务计划执行详情添加按钮操作 */
    handleAddBdglWorkTaskPlanDetail() {
      let obj = {};
      obj.unitId = "";
      obj.peopleName = "";
      obj.taskDescription = "";
      obj.taskStatus = "";
      obj.feedbackTime = "";
      obj.feedbackDescription = "";
      this.bdglWorkTaskPlanDetailList.push(obj);
    },
    /** 任务计划执行详情删除按钮操作 */
    handleDeleteBdglWorkTaskPlanDetail() {
      if (this.checkedBdglWorkTaskPlanDetail.length == 0) {
        this.$modal.msgError("请先选择要删除的任务计划执行详情数据");
      } else {
        const bdglWorkTaskPlanDetailList = this.bdglWorkTaskPlanDetailList;
        const checkedBdglWorkTaskPlanDetail =
          this.checkedBdglWorkTaskPlanDetail;
        this.bdglWorkTaskPlanDetailList = bdglWorkTaskPlanDetailList.filter(
          function (item) {
            return checkedBdglWorkTaskPlanDetail.indexOf(item.index) == -1;
          }
        );
      }
    },
    /** 复选框选中数据 */
    handleBdglWorkTaskPlanDetailSelectionChange(selection) {
      this.checkedBdglWorkTaskPlanDetail = selection.map((item) => item.index);
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "workingArrangements/worktaskplan/export",
        {
          ...this.queryParams,
        },
        `worktaskplan_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped>
.el-input__inner {
  height: 36px;
  background-color: #00365f;
  color: #fff;
  border: 1px solid white !important;
}
.el-select-dropdown {
  background-color: white;
}
.el-dialog__wrapper .el-form-item__label {
  color: white !important;
}
.el-dialog {
  background-color: #004d86 !important;
}
.el-form-item__label {
  width: 30%;
}
.el-textarea {
  width: 70%;
}
.el-dialog__title {
  color: white;
}
.el-dialog__header {
  border-bottom: 1px solid #718a9d;
}
.el-textarea__inner {
  width: 945px;
  height: 104px;
}
::v-deep .el-textarea__inner {
  width: 566px;
  height: 104px;
}
/* 表宽度 */
.el-input {
  width: 200px;
}
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 200px;
}
/* 执行 */
#execute {
  width: 510px;
  /* width: auto; */
}
.el-input--suffix {
  width: auto;
}
/* 上传附件样式 */
.el-icon-document {
  padding: 3px 5px;
  color: white;
}
.el-upload-list__item:hover {
  background-color: #00365f;
}
/* 上传附件的删除按钮样式 */
.el-link--inner {
  margin-left: 3px;
}
/* 弹框背景 */
.el-dialog {
  background: #00365f;
}
.el-dialog__title {
  color: white;
}
.el-input .el-input__inner {
  background: rgba(0, 0, 0, 0);
}
/* 下拉框样式 */
.el-select-dropdown__wrap .el-scrollbar__view {
  background-color: white;
}
/* 上传附件样式 */
.el-icon-document {
  padding: 3px 5px;
  color: white;
}
.el-upload-list__item:hover {
  background-color: #00365f;
}
/* 修改编号样式 */
.ipt .el-input__inner {
  background-color: #004d86 !important;
}
/* 进度查看 */
.el-button--btlook.is-active,
.el-button--btlook:active {
  background: #32a5d3;
  border-color: #32a5d3;
  color: #ffffff;
}
.el-button--btlook:focus,
.el-button--btlook:hover {
  background: #32a5d3;
  border-color: #32a5d3;
  color: #ffffff;
}
.el-button--btlook {
  width: 70px !important;
  border: 1px solid transparent;
  padding: 3px 8px;
  font-size: 14px;
  line-height: 1.5;
  border-radius: 3px;
  color: #fff;
  background-color: #32a5d3;
}
.big .el-input__inner {
  width: 940px;
}
/* 树形 */
.threeselects {
  width: 200px;
}
.threeselects .vue-treeselect__input {
  background-color: #004d86;
  /* color: white; */
}
.el-form-item__content {
  /* color: white; */
  border-bottom: 1px solid #004d86;
}
.vue-treeselect__control {
  background-color: #004d86;
  border-bottom: 1px solid white;
  /* color: whi; */
  /* color: white; */
}
.vue-treeselect__placeholder {
  color: white;
}

.change_plan_type .el-input__inner {
  width: 200px;
}
/* 表格样式 */
.el-table__empty-block {
  background-color: #004d86;
}
.el-table {
  background-color: #004d86;
}
.comtimer .el-input__inner {
  width: 940px;
}
/* 备注 */
.thistext {
  color: white;
  width: 930px;
  border: 1px solid #fff;
  border-radius: 4px;
  min-height: 35px;
  height: auto !important;
  line-height: 35px;
  text-indent: 1em;
  margin-bottom: 20px;
}
/* 完成进度 */
.complue .el-input__inner {
  width: 940px;
}
.complue {
  width: 940px;
}
/* 进度 */
.jinduProgress {
  width: 740px;
  position: absolute;
  left: 210px;
  top: 5px;
}
/* 表格 */
.tabless .el-table__row {
  background-color: #004d86;
}

.has-gutter {
  background-color: #004d86;
}
.el-dialog__body .el-table tr:nth-child(odd) {
  background-color: #004d86 !important;
}
.el-dialog__body .el-table tr:nth-child(even) {
  background-color: #004d86 !important;
}
.el-dialog__body table td {
  border-bottom: 1px solid white !important;
}
.el-dialog__body .el-table th.is-leaf {
  border: 1px solid white !important;
}
/* 下载按钮 */
.downloadfile {
  border: 1px solid white;
  display: inline-block;
  width: 100px;
  height: 33px;
  border-radius: 5px;
  line-height: 33px;
  text-align: center;
}
.el-table__row {
  border-bottom: 1px solid white;
}
.el-input-number__increase {
  background-color: #004d86;
}
.el-input-number__decrease {
  background-color: #004d86;
}
/* 进度条百分比 */
.el-progress-bar__innerText {
  color: #004d86;
}
.el-progress-bar__outer {
  background-color: rgba(25, 98, 153, 1);
}
/* 上下箭头 */
.el-icon-arrow-up,
.el-icon-arrow-down {
  color: white;
}
.vue-treeselect__single-value {
  color: white;
}
/* 文字多余部分省略 */
.el-table_1_column_8 .cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.el-table__empty-block {
  border-bottom: 1px solid white;
}
.vue-treeselect__control {
  background-color: transparent !important;
}
.threeselects .vue-treeselect__input {
  background-color: transparent !important;
}
.el-table__body-wrapper .el-table__empty-block {
  border: none !important;
}
.vue-treeselect__placeholder {
  color: #ccc;
}
.el-form-item__content {
  border-bottom: none !important;
}
::v-deep .el-input__inner {
  border: 1px solid white !important;
}
.el-select-dropdown__item.selected {
  color: #000;
  font-weight: bold;
}
.vue-treeselect__menu {
  color: #606266;
}
/* 日历样式 */
.el-date-picker__editor-wrap .el-input .el-input__inner {
  width: 100px !important;
}
.el-date-picker__time-header {
  border-bottom: none;
}
::v-deep .el-input--small .el-input__inner {
  height: 36px;
}
::v-deep .el-upload__tip {
  position: static !important;
  margin-left: 3px;
  margin-bottom: 21px;
}
.ren_wu {
  width: 501px;
}
/* 基本信息背景 */
.jiben {
  width: 700px;
  height: 32px;
  background-image: url(../../../images/小标题底.png);
  margin-bottom: 25px;
  color: #fff;
  padding-left: 16px;
  line-height: 32px;
  background-size: 100%;
}
::v-deep .el-form--inline .el-form-item {
  margin-right: 21px;
}
::v-deep .el-dialog__body {
  margin-left: 40px;
}
</style>
