<!--
  <select-card-template :selectTemp="selectTemp" @returnData="returnData"  @closeTemp="closeTemp"></select-card-template>
  import selectCardTemplate from '@/components/app/protectCard/select-card-template.vue';
 -->
<template>
  <el-dialog title="选择模板" :visible.sync="dialogVisible" width="700px" :before-close="handleClose">
    <div class="">
      <el-table class="select-table" ref="multipleTable" height="450" :data="tableData" tooltip-effect="dark" :style="{ width: '100%', minHeight: tableH }" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="卡券模板名称" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.dataName }}</template>
        </el-table-column>
        <el-table-column prop="" label="卡券类型" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.cardType == 0">抵金券</span>
            <span v-if="scope.row.cardType == 1">折扣券</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="提交人" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.chainName }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="submitForm">确定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import navCrumb from '@/components/nav/nav.vue';
import setDepartment from '@/components/company/set-department.vue';
import { getRequest } from '@/api/api';
import errMsg from '@/common/js/error';
// import { _debounce } from '@/common/js/public';
export default {
  name: 'select-card-template',
  props: {
    selectTemp: {
      type: [Object, Array],
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      dialogVisible: true,
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
      multipleSelection: []
    };
  },
  computed: {},
  methods: {
    /**
     *  选择模板
     */
    handleSelectionChange(val) {
      const that = this;
      that.multipleSelection = val;
    },
    handleClose() {
      const that = this;
      that.$emit('closeTemp');
    },
    submitForm() {
      const that = this;
      that.$emit('returnData', that.multipleSelection);
    },
    /**
     * 路由跳转
     */
    changeRoute(path) {
      this.$router.push(path);
    },

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

    /**
     * 分页---当前页变化
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
      that.getTableList();
    },
    /**
     * 获取列表数据
     */
    getTableList(val) {
      const that = this;
      let para = {
        keyWord: that.searchInput || '', // 搜索字段
        taskId: that.taskId,
        pageNum: that.currentPage, // 当前页
        pageSize: that.pageSize // 一页显示个数
      };
      getRequest('/haoban-manage3-web/sync-task-detail', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            that.tableData = resData.result.result || [];
            that.total = resData.result.totalCount;
            return false;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    selectTemp(newData, oldData) {
      const that = this;
      if (newData.length) {
        const arr = newData.map(ele => ele.templateId);
        that.tableData.forEach(ele => {
          if (arr.includes(ele.templateId)) {
            that.$refs.multipleTable.toggleRowSelection(ele);
          }
        });
      }
    }
  },
  mounted() {
    const that = this;
    that.getTableList();
    document.documentElement.style.backgroundColor = '#f0f2f5';
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {
    navCrumb,
    setDepartment
  }
};
</script>
<style type="text/less" lang="less" scoped>
.span-dot {
  display: inline-block;
  vertical-align: middle;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 3px;
  &.bg-52c41a {
    background: #52c41a;
  }
  &.bg-f5222d {
    background: #f5222d;
  }
}
.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-293 {
  width: 293px;
}
.w-191 {
  width: 191px;
}
.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;
    padding-top: 3px;
  }
}
.my-customer-wrap {
  height: 100%;
}
.right-content {
  /*width: 100%;*/
  padding: 0 20px 20px 20px;
  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;
        }
        .daily-set-wrap {
          height: 100%;
          background: #fff;
        }
        .app-detail-wrap {
          height: 100%;
          background: #fff;
        }
        .common-set-wrap {
          height: 100%;
          background: #fff;
        }
      }
    }
  }
}
</style>
