<template>
  <div id="ActivityList">
    <search-box-new
      ref="searchBox"
      :formData="formData"
      :formList="formList"
      @search="search"
      @init="init"
    />
    <table-list
      rowKey="id"
      ref="tableList"
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      :loading="loading"
      @addClick="addClick"
      @openDialog="openDialog"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="editClick(props.scope.row)"
          >详情</el-button
        ><el-button
          v-if="props.scope.row.publishStatus === 0"
          type="text"
          @click="sendUpload(props.scope.row)"
          >发布</el-button
        ><el-button
          v-if="props.scope.row.publishStatus === 0"
          type="text"
          @click="editClick(props.scope.row,true)"
          >修改</el-button
        >
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="formData.pageSize"
      :currentPage="formData.pageNum"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
    <BaseDialog
      width="500px"
      :isShow.sync="isShow"
      title="海报"
      @close="close"
      @submit="submit"
      :isShowFooter="false"
    >
      <template>
        <div class="posterUrl_style">
          <img style="width: 100%;height:100%;" :src="$methodsTools.splitImgHost(posterUrl)" alt="" />
          <div
            class="code_style"
            v-if="modelData.distribution && modelData.distribution.checked"
            :style="{
              top: modelData.distribution.top + 'px',
              left: modelData.distribution.left + 'px',
              width: modelData.distribution.width + 'px',
              height: modelData.distribution.height + 'px',
            }"
          >
            <img
              v-if="modelData.distribution.name"
              :style="modelData.distribution.css"
              :src="$methodsTools.splitImgHost(modelData.distribution.name)"
              alt=""
            />
          </div>

          <div
            class="code_style"
            v-if="modelData.cardCode && modelData.cardCode.checked"
            :style="{
              top: modelData.cardCode.top + 'px',
              left: modelData.cardCode.left + 'px',
              width: modelData.cardCode.width + 'px',
              height: modelData.cardCode.height + 'px',
            }"
          >
            <img
              v-if="modelData.cardCode.name"
              :style="modelData.cardCode.css"
              :src="$methodsTools.splitImgHost(modelData.cardCode.name)"
              alt=""
            />
          </div>
        </div>
      </template>
    </BaseDialog>
  </div>
</template>

<script>
import searchBoxNew from "@/components/searchBoxNew";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
export default {
  // name: "ActivityList",
  components: { searchBoxNew, tableList, pagination },
  data() {
    return {
      disabledBtn: false,
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "活动管理",
        index: 0,
        ch: "条",
        num: true,
        choice: false,
        addHide: false,
        openCheckMore: true,
        changeWidth: "160px",
        backFatherBtn: {
          status: false,
          title: "配置下单填选模板",
        },
      },
      //搜索
      formList: [
        {
          lable: "活动名称",
          prop: "name",
          placeholder: "请输入活动名称",
        },
      ],
      formData: {
        pageSize: 10,
        pageNum: 1,
      },
      // 表单
      tableSet: [
        {
          label: "活动名称",
          prop: "name",
          hidden: true,
        },
        {
          label: "活动类型",
          prop: "type",
          hidden: true,
          scope: "isOptions",
          options: [
            {
              label: "分销活动",
              value: 1,
            },
          ],
        },
        {
          label: "模板",
          prop: "posterTempName",
          hidden: true,
        },
        {
          label: "活动开始时间",
          prop: "startTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "活动结束时间",
          prop: "endTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "创建时间",
          prop: "createTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "发布状态",
          prop: "publishStatus",
          hidden: true,
          scope: "isOptions",
          options: [
            {
              label: "已发布",
              value: 1,
            },
            {
              label: "未发布",
              value: 0,
            },
          ],
        },
        {
          label: "海报",
          name: "样式",
          prop: "posterUrl",
          hidden: true,
          scope: "openDialog",
        },
        {
          label: "备注",
          prop: "remark",
          hidden: true,
        },
      ],
      tableData: [], //表单数据
      total: 0, //一共多少条
      isShow:false,
      posterUrl: "", //当前预览数据
      modelData: {},
    };
  },
  created() {
    this.search();
  },
  methods: {
    //打开海报预览窗口
    openDialog(row) {
      console.log(row)
      this.posterUrl = row.posterUrl;
      this.isShow = true;
    },
    submit() {},
    close() {},
    addClick() {
      this.$router.push({
        path: "activityInfo",
        status:'add'
      });
      // this.$refs.model.showBox();
    },
    editClick(e,status) {
      this.$router.push({
        path: "activityInfo",
        query: {
          id: e.id,
          status:status?'edit':'info'
        },
      });
    },
    search(v) {
      this.loading = true;
      if (v === 2) {
        this.formData = {
          pageSize: 10,
          pageNum: 1,
        };
      }
      var data = JSON.parse(JSON.stringify(this.formData));
      // if (this.formData.classStartTime) {
      //   data.classStartTime = parseInt(data.classStartTime / 1000);
      // }
      // if (this.formData.classEndTime) {
      //   data.classEndTime = parseInt(data.classEndTime / 1000);
      // }
      this.$api
        .distributiontemplist(data)
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.navText.index = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    init() {
      this.search(2);
    },
    sendUpload(v) {
      this.$alert("是否发布", "提示", {
        dangerouslyUseHTMLString: true,
      })
        .then(() => {
          this.$api.distributiontemppublishdata(v.id).then((res) => {
            this.$message.success("发布成功");
            this.search();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    handleSizeChange(v) {
      this.formData.pageSize = v;
      this.formData.pageNum = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.formData.pageNum = v;
      this.search();
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/.el-button {
  border-radius: 8px;
}
/deep/.el-dialog {
  border-radius: 8px;
  .el-dialog__header {
    padding: 0;
    .hearders {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 18px 0px 20px;
      border-bottom: 1px solid #e2e2e2;
      .leftTitle {
        font-size: 14px;
        font-weight: bold;
        color: #2f4378;
      }
      .rightBoxs {
        display: flex;
        align-items: center;
        img {
          width: 14px;
          height: 14px;
          margin-left: 13px;
          cursor: pointer;
        }
      }
    }
  }
  .el-dialog__footer {
    padding: 0;
    .dialog-footer {
      padding: 0px 40px;
      height: 70px;
      border-top: 1px solid #e2e2e2;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.imgBox {
  width: 100%;
  // height: 210px;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 8px 8px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .imgLabel {
    flex: 1;
    width: 100%;
    border: 1px dotted #e2e2e2;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    .msPhoto {
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 100%;
      max-height: 270px;
      img {
        max-width: 100%;
        max-height: 270px;
      }
    }
    .imgbbx {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      i {
        font-weight: bold;
        margin: 14px 0;
        font-size: 24px;
      }
    }
  }
  p {
    margin: 5px 0px;
  }
}
.numInputs {
  width: 150px;
}
.posterUrl_style {
  width: 375px;
  height: 667px;
  position: relative;
  margin-left: 50%;
  transform: translateX(-50%);
  & > .code_style {
    position: absolute;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
