<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-08-26 10:05:42
 -->
<template>
  <div class="my-customer-wrap common-set-wrap">
    <!-- <nav-crumb :navpath="navpath"> </nav-crumb> -->
    <div class="right-content">
      <div class="right-box" :style="{ 'min-height': bgHeight }">
        <div class="apps-content flex" :style="{ 'min-height': bgHeight }">
          <div class="apps-content-right">
            <div class="overstore-body">
              <div class="overstore-tip">
                <div role="alert" class="el-alert el-alert--info flex flex-align-start ">
                  <i class="el-alert__icon el-icon-warning font-12 color-2f54eb"></i>
                  <div class="el-alert__content">
                    <span class="el-alert__title color-303133 font-13">仅展示近一年数据，数据截取时间：{{ dateStart | timeStampToYmd }} 至 {{ dateEnd | timeStampToYmd }}</span>
                  </div>
                </div>
                <el-popover placement="bottom-start" width="550" trigger="click" popper-class="salesleads-popover">
                  <div class="tips-content">
                    <p>展示所选期间内的导购线索，以线索为主体，不以时间为主体。</p>
                    <p class="temp">如 所选时间为 20210401~20210403，则显示期间相关的导购线索数据。</p>
                    <p class="m-b-14">导购线索：计划中触达到门店导购端的都归入导购线索，包括话务、企微任务。</p>
                    <p class="m-l--6">【 任务完成率 】：</p>
                    <p class="m-b-10">导购任务完成数 / 任务总数，任务完成数不含放弃数。</p>
                    <p class="m-l--6">【 触达转化收益 】：</p>
                    <p>
                      通过导购线索触达，且触达的会员在触达效益计算有效期内前来消费的人数。<br />
                      多个导购线索任务触达的，转化只记在首个触达任务上；收益只计销售单，<br />
                      不看退货单和换货单；金额是应付还是实付看ERP传入的值。数据更新频率：1天1次
                    </p>
                  </div>
                  <div slot="reference" role="tips" class="tips flex flex-align-center">
                    <i class="el-icon-warning-outline font-14 color-2f54eb"></i>
                    <div class="el-alert__content">查看指标说明</div>
                  </div>
                </el-popover>
              </div>
              <div class="table-condition-search m-t-20">
                <el-input placeholder="请输入计划名称" prefix-icon="el-icon-search" v-model="pageParams.ecmPlanName" class="w-260" @change="reFetch" clearable @clear="clearInput"> </el-input>
                <el-date-picker class="m-l-10" prefix-icon="el-icon-time" :picker-options="pickerOptions" v-model="pageParams.date" @change="reFetch" :value-format="'yyyy-MM-dd'" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间"> </el-date-picker>
              </div>
              <div class="m-t-20">
                <el-table v-loading="loading" class="select-table" ref="multipleTable" :data="tableData" tooltip-effect="dark" :style="{ width: '100%', minHeight: tableH }">
                  <el-table-column label="计划名称" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.ecmPlanName || '--' }}</template>
                  </el-table-column>
                  <el-table-column prop="" label="任务总数">
                    <template slot-scope="scope">{{ scope.row.taskCnt || '--' }}</template>
                  </el-table-column>
                  <el-table-column prop="" label="已完成">
                    <template slot-scope="scope">{{ scope.row.cplTaskCnt || '--' }}</template>
                  </el-table-column>
                  <el-table-column prop="" label="完成率">
                    <template slot-scope="scope">{{ (scope.row.completionRate * 100).toFixed(2) + '%' || '--' }}</template>
                  </el-table-column>
                  <el-table-column prop="" label="待完成">
                    <template slot-scope="scope">{{ scope.row.waitFinishCount || '--' }}</template>
                  </el-table-column>
                  <el-table-column prop="" label="逾期中">
                    <template slot-scope="scope">{{ scope.row.ovincplTaskCnt || '--' }}</template>
                  </el-table-column>
                  <el-table-column prop="" label="操作">
                    <template slot-scope="scope">
                      <el-button type="text" @click="showDetail(scope.row)">查看详情</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <div class="block common-wrap__page text-right m-t-24" v-if="tableData.length != 0">
                  <dm-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum" :page-sizes="[20, 40, 60, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </dm-pagination>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- <vue-gic-footer></vue-gic-footer> -->
  </div>
</template>
<script>
import navCrumb from '@/components/nav/nav.vue';
import { getRequest } from '@/api/api';
import errMsg from '@/common/js/error';
import { _debounce } from '@/common/js/public';

export default {
  name: 'taskList',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      bgHeight: window.screen.availHeight - 298 + 'px',
      dateStart: new Date().getTime() - 3600 * 1000 * 24 * 365,
      dateEnd: new Date(),
      loading: false,
      // 面包屑参数
      navpath: [
        {
          name: '首页',
          path: '/index'
        },
        {
          name: '销售线索',
          path: ''
        }
      ],
      pageParams: {
        pageNum: 1,
        pageSize: 20
      },
      // 分页参数
      total: 0,
      tableData: [
        // {
        //   enterpriseId: '', // 企业id
        //   ecmPlanId: '', // 计划id
        //   ecmPlanName: '', // 计划名称
        //   taskCnt: '', // 任务总数
        //   cplTaskCnt: '', // 任务完成数
        //   completionRate: '', // 任务完成率
        //   itincplTaskCnt: '', // 未逾期任务未完成数
        //   ovincplTaskCnt: '', // 逾期任务未完成数
        // }
      ],
      pickerOptions: {
        disabledDate: time => {
          const end = new Date();
          return time.getTime() < end.getTime() - 3600 * 1000 * 24 * 365 || time.getTime() > end.getTime();
        }
      }
    };
  },
  computed: {},
  methods: {
    /**
     * 路由跳转
     */
    changeRoute(path) {
      this.$router.push(path);
    },
    /**
     * 筛选
     */
    reFetch: _debounce(function(e, value) {
      const that = this;
      that.pageParams.pageNum = 1;
      that.getTableList();
    }, 500),
    /**
     * 分页---页码变化
     *  @param {Number} val
     */
    handleSizeChange(val) {
      const that = this;
      that.pageParams.pageNum = 1;
      that.pageParams.pageSize = val;
      that.getTableList();
    },

    /**
     * 分页---当前页变化
     *  @param {Number} val
     */
    handleCurrentChange(val) {
      const that = this;
      that.pageParams.pageNum = val;
      that.getTableList();
    },
    /**
     * 获取列表数据
     */
    getTableList(val) {
      const that = this;
      that.loading = true;
      let para = {
        ...that.pageParams,
        enterpriseId: localStorage.getItem('userInfoBrandId'),
        qywxEnterpriseId: JSON.parse(localStorage.getItem('userInfos')).wxEnterpriseId
      };
      if (para.date) {
        para.startTime = para.date[0];
        para.endTime = para.date[1];
        delete para.date;
      }
      getRequest('/haoban-task-manage-web/market/clue/web/plan-list', para)
        .then(res => {
          that.loading = false;
          let resData = res.data;
          if (resData.errorCode == 1 && resData.result) {
            that.tableData = resData.result.list || [];
            that.total = resData.result.total;
          } else {
            that.tableData = [];
            errMsg.errorMsg(resData);
          }
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    showDetail(item) {
      this.$router.push(`storeList?ecmPlanId=${item.ecmPlanId}`);
    }
  },
  watch: {
    brandId(newV) {
      this.getTableList();
    }
  },
  mounted() {
    const that = this;
    that.getTableList();
    that.$emit('showTab', 2);
    document.documentElement.style.backgroundColor = '#f0f2f5';
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {
    navCrumb
  }
};
</script>
<style type="text/scss" lang="scss" scoped>
.bg-82C5FF {
  background: #82c5ff;
}
.color-508CEE {
  color: #508cee;
}
.color-FF585C {
  color: #ff585c;
}
.line-h-18 {
  line-height: 18px;
}
.tooltip-text {
  width: 100%;
  white-space: pre-wrap;
  word-break: break-all;
}
.w-260 {
  width: 260px;
}
.el-alert--info {
  background: rgba(240, 245, 255, 1);
  border-radius: 2px;
  border: 1px solid rgba(133, 165, 255, 1);
  -webkit-box-align: flex-start;
  -webkit-align-items: flex-start;
  -ms-flex-align: flex-start;
  align-items: flex-start;
  .el-alert__icon {
    font-size: 12px;
  }
}
.my-customer-wrap {
  height: 100%;
}
.right-content {
  /*width: 100%;*/
  padding: 0;
  min-height: calc(100% - 160px);
  .right-box {
    background: #fff;
    min-height: 500px;
    padding: 0px;
    .apps-content {
      .apps-content-right {
        width: 100%;
        padding: 20px;
        background: #fff;
        .overstore-body {
          background: #fff;
          .overstore-tip {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            .el-alert--info {
              align-items: center;
              width: 444px;
              height: 32px;
              padding: 0 0 0 17px;
              margin-right: 17px;
              .el-alert__content {
                padding-left: 0;
              }
            }
            .tips {
              cursor: pointer;
              .el-alert__content {
                font-size: 13px;
                font-weight: 400;
                color: #2f54eb;
                line-height: 1;
              }
            }
          }
        }
        .daily-set-wrap {
          height: 100%;
          background: #fff;
        }
        .app-detail-wrap {
          height: 100%;
          background: #fff;
        }
        .common-set-wrap {
          height: 100%;
          background: #fff;
        }
      }
    }
  }
}
</style>
