<!--
 * @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-select class="w-103" v-model="pageParams.finishOverStatus" slot="prepend" placeholder="所有完成情况" @change="reFetch">
                  <el-option :label="item.text" :value="item.id" v-for="item in filterOpts" :key="'filter' + item.id"></el-option>
                </el-select>
              </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 min-width="170">
                    <template slot-scope="scope">{{ scope.row.taskTitle || '--' }}</template>
                  </el-table-column>
                  <el-table-column prop="" label="指派对象" min-width="200">
                    <template slot-scope="scope">
                      <div class="flex flex-align-center personal-info">
                        <el-image :src="scope.row.executeClerkClerkImgUrl || headDefault" fit="cover"></el-image>
                        <div>
                          <p class="color-303133 line-20">{{ scope.row.executeClerkName || '--' }}</p>
                          <p class="color-909399 line-20">{{ scope.row.executeClerkPhoneNum || '--' }}</p>
                        </div>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column prop="" label="会员" min-width="200">
                    <template slot-scope="scope">
                      <div class="flex flex-align-center personal-info">
                        <el-image :src="scope.row.memberImgUrl || headDefault" fit="cover"></el-image>
                        <div>
                          <p class="color-303133 line-20">{{ scope.row.memberName || '--' }}</p>
                          <p class="color-909399 line-20">{{ scope.row.memberCardNum || '--' }}</p>
                        </div>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column prop="" label="创建时间" min-width="122">
                    <template slot-scope="scope">
                      <div class="color-606266 line-20">{{ scope.row.createTime | timeStampToYmd }}</div>
                      <div class="color-606266 line-20">{{ scope.row.createTime | timeStampToHms }}</div>
                    </template>
                  </el-table-column>
                  <el-table-column prop="" label="逾期期限" min-width="122">
                    <template slot-scope="scope">
                      <div class="color-606266 line-20">{{ scope.row.overdueTime | timeStampToYmd }}</div>
                      <div class="color-606266 line-20">{{ scope.row.overdueTime | timeStampToHms }}</div>
                    </template>
                  </el-table-column>
                  <el-table-column prop="" label="逾期情况" min-width="122">
                    <template slot-scope="scope"><span class="point" :style="'background:' + overdueStyle[scope.row.overdueStatus] + ';'"></span>{{ scope.row.overdueStatus === 1 ? '已逾期' : scope.row.overdueStatus === 2 ? '未逾期' : '' }}</template>
                  </el-table-column>
                  <el-table-column prop="" label="完成状态" min-width="122">
                    <template slot-scope="scope"><span class="point" :style="'background:' + taskStyle[scope.row.taskStatus] + ';'"></span>{{ scope.row.taskStatus === 1 ? '未完成' : scope.row.taskStatus === 2 ? '已完成' : '' }}</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-column prop="" label="操作" width="150">
                    <template slot-scope="scope">
                      <el-button type="text" @click="showDetail(scope.row)">预览</el-button>
                      <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="pageParams.pageNum" :page-sizes="[20, 40, 60, 80]" :page-size="pageParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </dm-pagination>
                </div>
              </div>
              <salesleads-taskinfo :item="confirmDetail" v-if="confirmDetailShow" @close="close"></salesleads-taskinfo>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- <vue-gic-footer></vue-gic-footer> -->
  </div>
</template>
<script>
import salesleadsTaskinfo from '@/components/review/salesleads-task-info.vue';
import headDefault from '@/assets/head_default.jpg';
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: 'storeDetail',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      headDefault,
      bgHeight: window.screen.availHeight - 298 + 'px',
      loading: false,
      dateStart: new Date().getTime() - 3600 * 1000 * 24 * 365,
      dateEnd: new Date(),
      // 面包屑参数
      navpath: [
        {
          name: '首页',
          path: '/index'
        },
        {
          name: '销售线索',
          path: ''
        }
      ],
      pageParams: {
        storeId: this.$route.params.id,
        finishOverStatus: '',
        pageNum: 1,
        pageSize: 20
      },
      filterOpts: [],
      // 分页参数
      total: 0,
      tableData: [
        // {
        //   taskId: '', // 任务id
        //   taskTitle: '', // 任务标题
        //   executeClerkId: '', // 指派导购id
        //   executeClerkName: '', // 指派导购名字
        //   executeClerkPhoneNum: '', // 指派导购手机号
        //   executeClerkClerkImgUrl: null, // 指派导购头像
        //   memberId: '', // 会员id
        //   memberName: '', // 会员名字
        //   memberImgUrl: '', // 会员头像
        //   memberCardNum: '', // 会员卡号
        //   createTime: null, // 创建时间
        //   overdueTime: null, // 逾期时间
        //   overdueStatus: null, // 逾期状态(1:逾期,2:未逾期)
        //   taskStatus: null // 完成状态(1:未完成,2:完成)
        // }
      ],
      overdueStyle: ['none', '#F5222D', '#2F54EB'],
      taskStyle: ['none', '#F5222D', '#33AF4A'],
      confirmDetailShow: false,
      confirmDetail: {},
      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'),
        // storeId: 'ff80808175acbdbd0175aff217960011'
        storeId: that.$route.params.id
        // (ecmPlanId )
      };
      if (this.$route.query.ecmPlanId) {
        para.ecmPlanId = this.$route.query.ecmPlanId;
      }
      getRequest('/haoban-task-manage-web/market/clue/web/task-info-list', para)
        .then(res => {
          that.loading = false;
          let resData = res.data;
          if (resData.errorCode == 1) {
            that.tableData = resData.result.list || [];
            that.total = resData.result.pageInfo.total || 0;
          } else {
            errMsg.errorMsg(resData);
          }
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    getFilterOpts() {
      const that = this;
      getRequest('/haoban-task-manage-web/market/clue/web/query', {})
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1 && resData.result) {
            that.filterOpts = resData.result;
            that.pageParams.finishOverStatus = '0';
          } else {
            errMsg.errorMsg(resData);
          }
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    showDetail(item) {
      const that = this;
      that.loading = true;
      const para = {
        enterpriseId: localStorage.getItem('userInfoBrandId'),
        taskId: item.taskId
      };
      getRequest('/haoban-task-manage-web/market/clue/web/task-finish-info', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1 && resData.result) {
            that.confirmDetail = { ...resData.result };
            if (resData.result.remarkImgUrl) {
              that.confirmDetail.remarkImgUrl = resData.result.remarkImgUrl.split(',');
            } else {
              that.confirmDetail.remarkImgUrl = [];
            }
            this.confirmDetailShow = true;
          } else {
            errMsg.errorMsg(resData);
          }
          that.loading = false;
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    close() {
      this.confirmDetailShow = false;
      this.confirmDetail = {};
    }
  },
  watch: {
    brandId(newV) {
      this.getTableList();
    }
  },
  mounted() {
    const that = this;
    that.getFilterOpts();
    that.getTableList();
    if (that.$route.query.tab) {
      that.$emit('showTab', 2);
    } else {
      that.$emit('showTab', 1);
    }
    document.documentElement.style.backgroundColor = '#f0f2f5';
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {
    navCrumb,
    salesleadsTaskinfo
  }
};
</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: 291px;
              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;
        }
      }
    }
  }
}
.personal-info {
  .el-image {
    width: 40px;
    height: 40px;
    margin-right: 10px;
  }
}
.point {
  display: inline-block;
  width: 6px;
  height: 6px;
  vertical-align: top;
  margin-top: 8px;
  border-radius: 100%;
  margin-right: 5px;
}
</style>
<style lang="sass"></style>
