<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="68px">          
          <el-form-item label="项目名称" prop="projectId">
        <el-select v-model="queryParams.projectId" filterable  placeholder="请选择项目" clearable @change="handleQuery">
          <el-option v-for="(item, index) in projectOptions" :key="index" :label="item.projectName" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

          <el-form-item label="责任主体" prop="projectDeptId" v-hasPermi="['project:project:zgs']">
            <el-select v-model="queryParams.projectDeptId" placeholder="请选择责任主体" clearable>
              <el-option v-for="dict in depts" :key="dict.deptId" :label="dict.deptName"
                :value="dict.deptId"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="提交时间">
            <el-date-picker v-model="daterangeMarksTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
              range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </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" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="24">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button v-if="1 == 2" type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
              v-hasPermi="['project:surProjectSchedule: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="['project:surProjectSchedule: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="['project:surProjectSchedule: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="['project:surProjectSchedule:export']">导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="surProjectScheduleList" @selection-change="handleSelectionChange" stripe>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" v-if="1==2"/>
      <el-table-column label="项目名称" align="left" prop="projectName" show-overflow-tooltip width="200" />
      <el-table-column label="形象图片" align="center" prop="image" width="100">
        <template slot-scope="scope">
          <el-image ref="preview" style="width: 50px; height: 50px" :src="getImageUrl(scope.row.image)"
            @click="onPreview(scope.row.image)"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="计划节点" align="left" prop="plannedNode" show-overflow-tooltip />
      <el-table-column label="实际节点" align="left" prop="actualNode" show-overflow-tooltip />
      <el-table-column label="融资、招采进展" align="left" prop="purchaseProgress" show-overflow-tooltip width="160" />
      <el-table-column label="报建、设计进展" align="left" prop="designProgress" show-overflow-tooltip width="160" />
      <el-table-column label="施工进展" align="left" prop="constructionProgress" show-overflow-tooltip />
      <el-table-column label="验收进展" align="left" prop="acceptanceProgress" show-overflow-tooltip />
      <el-table-column label="下周计划" align="left" prop="planForNextWeek" show-overflow-tooltip />
      <el-table-column label="存在问题" align="celeftnter" prop="existingProblem" show-overflow-tooltip />
      <el-table-column label="问题推进情况" align="left" prop="problemProgress" show-overflow-tooltip width="160" />
      <el-table-column label="提交人" align="left" prop="createUser" show-overflow-tooltip width="160" />
      <el-table-column label="提交时间" align="left" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" fixed="right">
        <template slot-scope="scope">
          <el-button v-if="1 == 2" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['project:surProjectSchedule:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['project:surProjectSchedule: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" v-if="open" :visible.sync="open" width="1200px" append-to-body
      :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-col :span="24">
          <el-form-item label="形象图片" prop="image">
            <image-upload v-model="form.image" :limit="5" :fileSize="15" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="计划节点" prop="plannedNode">
            <el-input v-model="form.plannedNode" type="textarea" placeholder="请输入内容" />
          </el-form-item> </el-col><el-col :span="12">
          <el-form-item label="实际节点" prop="actualNode">
            <el-input v-model="form.actualNode" type="textarea" placeholder="请输入内容" />
          </el-form-item> </el-col><el-col :span="12">
          <el-form-item label="融资、招采进展" prop="purchaseProgress">
            <el-input v-model="form.purchaseProgress" type="textarea" placeholder="请输入内容" />
          </el-form-item> </el-col><el-col :span="12">
          <el-form-item label="报建、设计进展" prop="designProgress">
            <el-input v-model="form.designProgress" type="textarea" placeholder="请输入内容" />
          </el-form-item> </el-col><el-col :span="24">
          <el-form-item label="施工进展" prop="constructionProgress">
            <el-input v-model="form.constructionProgress" type="textarea" placeholder="请输入内容" />
          </el-form-item> </el-col><el-col :span="12">
          <el-form-item label="验收进展" prop="acceptanceProgress">
            <el-input v-model="form.acceptanceProgress" type="textarea" placeholder="请输入内容" />
          </el-form-item> </el-col><el-col :span="12">
          <el-form-item label="下周计划" prop="planForNextWeek">
            <el-input v-model="form.planForNextWeek" type="textarea" placeholder="请输入内容" />
          </el-form-item> </el-col><el-col :span="24">
          <el-form-item label="存在问题" prop="existingProblem">
            <el-input v-model="form.existingProblem" type="textarea" placeholder="请输入内容" />
          </el-form-item> </el-col><el-col :span="24">
          <el-form-item label="问题推进情况" prop="problemProgress">
            <el-input v-model="form.problemProgress" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </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-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="previewList" />
  </div>
</template>

<script>
import {
  listSurProjectSchedule,
  getSurProjectSchedule,
  delSurProjectSchedule,
  addSurProjectSchedule,
  updateSurProjectSchedule,
} from "@/api/project/surProjectSchedule";
import ElImageViewer from "element-ui/packages/image/src/image-viewer";

export default {
  name: "SurProjectSchedule",
  components: {
    ElImageViewer,
  },
  dicts: ["sys_common_isdel"],
  data() {
    return {
      showViewer: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 形象进度表格数据
      surProjectScheduleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 发布时间时间范围
      daterangeMarksTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        plannedNode: null,
        actualNode: null,
        purchaseProgress: null,
        designProgress: null,
        constructionProgress: null,
        acceptanceProgress: null,
        planForNextWeek: null,
        existingProblem: null,
        problemProgress: null,
        isDel: null,
        projectDeptId: null,
      },
      depts: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      previewList: [],
      projectOptions:[],
    };
  },
  created() {
    this.getList();
    this.$api.publics.getZgsDeptList().then((d) => {
      this.depts = d?.data || [];
    });
    this.$api.publics.getMyProjectList({}).then((response) => {
        this.projectOptions = response.rows;
    }); 
  },
  methods: {
    getImageUrl(url) {
      return process.env.VUE_APP_BASE_API + url.split(",")[0] + ".min.jpg";
    },
    onPreview(url) {
      this.previewList = [];
      url.split(",").forEach((item) => {
        this.previewList.push(process.env.VUE_APP_BASE_API + item);
      });
      this.showViewer = true;
    },
    closeViewer() {
      this.showViewer = false;
    },
    /** 查询形象进度列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeMarksTime && "" != this.daterangeMarksTime) {
        this.queryParams.params["beginMarksTime"] = this.daterangeMarksTime[0];
        this.queryParams.params["endMarksTime"] = this.daterangeMarksTime[1];
      }
      listSurProjectSchedule(this.queryParams).then((response) => {
        this.surProjectScheduleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        image: null,
        plannedNode: null,
        actualNode: null,
        purchaseProgress: null,
        designProgress: null,
        constructionProgress: null,
        acceptanceProgress: null,
        planForNextWeek: null,
        existingProblem: null,
        problemProgress: null,
        isDel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      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;
      getSurProjectSchedule(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改形象进度";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id) {
            updateSurProjectSchedule(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSurProjectSchedule(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 delSurProjectSchedule(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "project/surProjectSchedule/export",
        {
          ...this.queryParams,
        },
        `surProjectSchedule_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
