<template>
  <div class="my-customer-wrap common-set-wrap">
    <common-detail-top :topMenuData="topMenuData" :activeId="activeId"></common-detail-top>
    <div class="daily-set-content boder-box">
      <div class="table-condition flex flex-space-between">
        <div class="table-condition-left">
          <el-select v-model="conditionObj.completed" placeholder="请选择" class="w-105">
            <el-option v-for="item in completedOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>
          <el-select v-model="conditionObj.overdue" placeholder="请选择" class="w-105">
            <el-option v-for="item in overOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>
        </div>
        <div class="table-condition-right">
          <el-button type="info">批量删除</el-button>
          <el-button type="primary">导出</el-button>
        </div>
      </div>
      <el-table class="select-table" ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%">
        <el-table-column type="selection" width="55" :filters="[{ text: '选择当页', value: '1' }, { text: '选择全部', value: '2' }]" filter-placement="bottom-start"> </el-table-column>
        <el-table-column label="指派对象" width="120">
          <template slot-scope="scope">{{ scope.row.clerkName }}</template>
        </el-table-column>
        <el-table-column prop="name" label="创建时间" width="120">
          <template slot-scope="scope">{{ scope.row.createTime }}</template>
        </el-table-column>
        <el-table-column prop="" label="完成期限" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.completeTime }}</template>
        </el-table-column>
        <el-table-column label="逾期情况" width="120">
          <template slot-scope="scope">{{ scope.row.date }}</template>
        </el-table-column>
        <el-table-column label="完成情况" width="120">
          <template slot-scope="scope">{{ scope.row.date }}</template>
        </el-table-column>
        <el-table-column label="完成时间" width="120">
          <template slot-scope="scope">{{ scope.row.completeTime }}</template>
          <el-table-column label="完成备注" width="120">
            <template slot-scope="scope">{{ scope.row.date }}</template>
          </el-table-column>
          <el-table-column label="放弃备注" width="120">
            <template slot-scope="scope">{{ scope.row.date }}</template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
            <el-button type="text" size="small" @click="handlePreview(scope.$index, scope.row)">预览</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block common-wrap__page text-right" v-if="tableData.length != 0">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import appDetail from '@/components/app/app-detail.vue';
import commonDetailTop from '@/components/app/common-detail-top.vue';
import { getRequest, postRequest } from '@/api/api';
import errMsg from '@/common/js/error';
import QRCode from 'qrcodejs2';
export default {
  name: 'reviewed',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      tableH: window.screen.availHeight - 464 - 126 + 'px',
      activeTab: '1',
      activeBrand: this.brandId,
      tabListData: [
        {
          tabId: '1',
          tabName: '云日报记录',
          icon: 'icon-ribao'
        },
        {
          tabId: '2',
          tabName: '云日报设置',
          icon: 'icon-ribaoshezhi',
          children: [
            {
              tabId: '21',
              tabName: '模板配置',
              icon: '',
              children: [
                {
                  tabId: '211',
                  tabName: '系统报表',
                  icon: ''
                },
                {
                  tabId: '212',
                  tabName: '自定义报表',
                  icon: ''
                }
              ]
            },
            {
              tabId: '22',
              tabName: '任务下发设置',
              icon: ''
            }
          ]
        }
      ],
      // 条件
      conditionObj: {
        completed: '',
        overdue: ''
      },
      completedOptions: [
        {
          label: '已完成',
          value: '1'
        },
        {
          label: '联营',
          value: '2'
        }
      ],
      overOptions: [
        {
          label: '已逾期',
          value: '1'
        },
        {
          label: '联营',
          value: '2'
        }
      ],
      tableData: [
        {
          storeName: '1111',
          headImgUrl: '222',
          clerkName: '对象',
          clerkId: '',
          completed: '',
          overdue: '',
          taskId: '',
          storeId: '',
          createTime: '',
          completeTime: '',
          lastTime: ''
        }
      ],
      multipleSelection: [],
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0
    };
  },
  computed: {},
  methods: {
    /**
     * 返回 的 brandId
     */
    selectBrandId(id) {
      let that = this;
      that.activeBrand = id;
    },

    setSelectTab(item) {
      let that = this;
      that.activeTab = item.tabId;
    },

    /**
     * 表格选择
     */
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    /**
     * 批量删除
     */
    multDel() {
      let that = this;
      if (!that.multipleSelection.length) {
        that.$message.error({
          duration: 1000,
          message: '请选择删除项'
        });
        return false;
      }
      that.dialogRadio = true;
    },

    /**
     * 导出
     */
    exportExcel() {
      let that = this;
      let para = {
        brandId: that.activeBrand
      };
      postRequest('/haoban-manage-web/daily/page-task', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    /**
     * 分页---页码变化
     */
    handleSizeChange(val) {
      const that = this;
      that.pageSize = val;
      that.getTableList();
    },

    /**
     * 分页---当前页变化
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
      // let fullPath = that.$route.fullPath;
      that.getTableList();
    },

    /**
     * 删除
     */
    handleDel(index, row) {
      let that = this;
      that.postDel();
    },

    postDel() {
      return false;
    },

    /**
     * 预览
     */
    handlePreview(index, row) {
      let that = this;
      that.postPreview();
    },

    /**
     *  预览---api
     */
    postPreview(data) {
      const that = this;
      let para = {
        templateContent: JSON.stringify(data)
      };
      postRequest('/haoban-manage-web/record/record-template-preview.json', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            // 生成二维码需要的 url
            let webUrl = `${window.location.origin}/office-mobile/#/staffRecordsTemplate?enterpriseId=${resData.result}`;
            that.qrcode(webUrl);
            that.dialogVisible = true;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    /**
     *  生成二维码
     */
    qrcode(text) {
      const that = this;
      if (!!that.qrcodeCase) {
        document.getElementById('qrcode').innerHTML = '';
        that.qrcodeCase.clear(); // 先清除原有的
      }
      let qrObj = {
        type: 'record',
        data: text
      };
      that.qrcodeCase = new QRCode('qrcode', {
        width: 210,
        height: 210, // 高度
        text: JSON.stringify(qrObj) // 二维码内容 //
        //render: 'canvas', // 设置渲染方式（有两种方式 table和canvas，默认是canvas） //
        //background: '#f0f',
        //foreground: '#ff0'
      });
    },

    /**
     * 获取列表数据
     */
    getTableList(val) {
      const that = this;
      let para = {
        storeId: that.conditionObj.storeId || '', // 门店
        overdue: that.conditionObj.overdue || '', // 逾期
        completed: that.conditionObj.completed || '',
        currentPage: that.currentPage, // 当前页
        pageSize: that.pageSize, // 一页显示个数
        brandId: that.activeBrand
      };
      getRequest('/haoban-manage-web/daily/page-task-items', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result && !!resData.result.result.legnth) {
              resData.result.result.forEach(function(ele, index) {
                if (!!ele.createTime) {
                  return false;
                }
              });
            }
            that.tableData = resData.result.result;
            that.total = resData.result.totalCount;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    brandId: function(newData, oldData) {
      const that = this;
      that.activeBrand = newData;
    }
  },
  mounted() {
    document.documentElement.style.backgroundColor = '#f0f2f5';
    this.$emit('showTab', '1');
    this.activeBrand = this.brandId;
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {
    appDetail,
    commonDetailTop
  }
};
</script>
<style type="text/scss" lang="scss" scoped>
.depart-item-content {
  width: 213px;
  height: 32px;
  overflow: hidden;
  white-space: nowrap;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  cursor: pointer;
}

.item-cell-select {
  /deep/ .el-select__tags {
    white-space: nowrap;
    overflow: hidden;
  }
}

.depart-cell {
  position: relative;
  margin: 0 24px 24px 0;

  .el-icon-circle-close {
    position: absolute;
    top: -10px;
    right: -10px;
    font-size: 16px;
    color: #808995;
    cursor: pointer;
  }
}
</style>
