<template>
  <div class="table-wrap">
    <el-table :data="tableData" ref="tableRef" highlight-current-row size="mini" stripe border >

      <el-table-column type="index" label="序号"  width="60" show-overflow-tooltip>
      </el-table-column>

      <el-table-column v-for="(item, index) in colunms" :key="index"
            :prop="item.prop"
            :label="item.label"
            :fixed="item.fixed"
            :class-name="item.prop =='reviewStatusKey'?'c357F':'' "
            :show-overflow-tooltip="item.tooltip"
            :min-width="item.width"
            >
      </el-table-column>

      <el-table-column  label="操作" v-if="projectStatus ==='draft'|| projectStatus ==='audited'|| projectStatus ==='filed'" min-width="100"  >
        <template slot-scope="scope"  >
          <el-button  @click="handleDetail(scope.row)" type="text">详情</el-button>
          <el-button v-if=" scope.row.reviewStatus == 'draft' " @click="handleEdit(scope.row)" type="text">编辑</el-button>
          <el-button v-if=" scope.row.reviewStatus == 'draft' " @click="handleDelete(scope.row)" type="text">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页-->
    <ls-pagination :pager.sync="pager"  @query="doQuery"></ls-pagination>
  </div>
</template>

<script>

  export default {
    name: 'project-progress-table',
    created() {
      this.doQuery();
    },
    mounted() {

    },
    methods: {
      // 查询数据
      doQuery () {

        let param = {
          currPage: this.pager.curPage,
          pageSize: this.pager.size,
          queryParam: {
             projectId: this.projectid,
             reportBigType: 'projectReport',
          }
        };
        this.$ajax.post({
          domain: 'crmUrl',
          url: 'project.projectWorklist',
          data: param,
          requestType: 'body',
          showLoad: true,
          success: function (res) {
            if (res.errorCode === 200) {
                 this.tableData = res.data.records || [];
                 this.pager.totals = res.data.total || 0;
            }
          }.bind(this),
          error: function (res) {
            this.$message({
              type: 'error',
              message: res.body.msg || res.msg
            })
          }.bind(this)
        })
      },

      //新增项目重要进展
      handleProgress(){
        this.$router.push({
          path: 'addWork',
          query: {
            projectId: this.projectid,
            openTitle: '新增项目进展',
            projectObj: {
              projectId: this.projectid,
              customer: this.customer,
              customerId: this.customerId,
              projectCode: this.projectCode,
            }
          }
        });
      },
      //编辑
      handleEdit(row){
        this.$router.push({
          path: 'addWork',
          query: {
            rowData: row,
            projectId: row.projectId,
            openTitle: '编辑项目进展',
            projectObj: {
              projectId: this.projectid,
              customer: this.customer,
              customerId: this.customerId,
              projectCode: this.projectCode,
            }
          }
        });
      },
      //详情
      handleDetail(row) {
        this.$router.push({
          path: 'detailswork',
          query: {
            rowData: row,
            projectId: this.projectid
          }
        });
      },
      //删除
      handleDelete (row){

        this.$confirm('确定删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            this.$ajax.post({
              domain: 'crmUrl',
              url: 'work.deleteDraftWork',
              data: {id: row.id},
              requestType: 'body',
              showLoad: true,
              success: function (res) {
                if (res.errorCode === 200) {
                   this.$message({
                     type: 'success',
                     message: '删除成功'
                  })
                  this.doQuery();
                }
              }.bind(this),
              error: function (res) {
                this.$message({
                  type: 'error',
                  message: res.body.msg || res.msg
                })
              }.bind(this)
            })
        }).catch(() => { });

      },

    },
    props: ['projectid', 'projectStatus', 'customer', 'customerId', 'projectCode'],
    data() {
      return {

        //分页参数
        pager: {
          curPage: 1,
          size: 10,
          pageOptions: [10, 20, 30],
          totals: 0
        },

        tableData: [],

        //表格列
        colunms: [
           { prop: 'workTitle', label: '记录日期',   width: 100, fixed: false,  tooltip: true },
           { prop: 'creater', label: '提交人员',   width: 100, fixed: false,  tooltip: true },
           { prop: 'theme', label: '进展主题',   width: 100, fixed: false,  tooltip: true },
           { prop: 'reviewStatusKey', label: '状态',   width: 100, fixed: false,  tooltip: true },
           { prop: 'createDateFormat', label: '提交时间',   width: 100, fixed: false,  tooltip: true },
        ]

      }
    },

  }
</script>

<style>
</style>
