<template>
  <div class="templateMarket">
    <div class="template_comheader">
      <div>
        <span>模板市场</span>
        <el-button type="primary" size="small" @click="CommonJump('templateMarketManage',{})">模板市场管理</el-button>
      </div>
    </div>
    <div class="content">
      <div class="searchInput" style="margin:10px 0 20px 20px;">
        <el-input style="display:inline-block;width:225px;height:30px" placeholder="请输入模板名称" v-model="qMsg.Name"
          size="small" clearable @keyup.enter.native="qMsg.pageIndex=1,getList()" @clear="qMsg.pageIndex=1,getList()">
        </el-input>
        <span class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"
          @click="qMsg.pageIndex=1,getList()"> </span>
      </div>
      <br>
      <div class="template_MarketList">
        <div class="Market_List" v-for="(item,index) in dataList" :key="index">
          <div class="MarketInner">
            <div flex="dir:top cross:center main:center" class="dialog-img">
              <div class="choose-btn market_useBtn" @click="LoadTemplate(item)">加载模板</div>
              <div class="choose-btn" @click="getImgSrc(item)">预览模板</div>
            </div>
            <div class="show-img" :style="{backgroundImage:'url('+item.Pics+')'}">
            </div>
            <div class="Market_Info">
              <div flex="dir:top main:center">
                <div flex="main:justify">
                  <div class="item-name">{{item.Name}}</div>
                </div>
                <div>
                  <div flex="cross:center main:justify">
                    <div class="price">
                      ￥{{item.Price}}
                    </div>
                    <button type="button" class="el-button el-button--primary el-button--mini">
                      <span @click="LoadTemplate(item)">加载</span>
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <el-pagination style="text-align:right" background @current-change="handleCurrentChange"
        :page-size="qMsg.pageSize" layout="prev, pager, next" :total="total">
      </el-pagination>
    </div>
    <el-dialog title="手机端预览" :visible.sync="viewDialog" width="600px">
      <div class="MarketView" ref="MarketView">
        <img :src="imgUrl" alt="" style="width: 375px;">
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="viewDialog = false" size="small">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        //预览弹窗
        viewDialog: false,
        imgUrl: '',
        dataList: [],
        qMsg: {
          pageIndex: 1,
          pageSize: 16,
          IsUse: 1,
          IsShow: 1,
          Name: "", //模板名称
        },
        total: 0,
      };
    },
    components: {

    },
    created() {

    },
    methods: {
      getImgSrc(item) {
        this.viewDialog = true;
        this.imgUrl = item.Pics;
      },
      //关闭
      closeDialog() {
        this.viewDialog = false;
        this.$refs.MarketView.scrollTop = 0;
      },
      handleCurrentChange(val) {
        this.qMsg.pageIndex = val;
        this.getList();
      },
      getList() {
        this.apipost("/api/Template/GetTemplateMarketPageListModule", this.qMsg, res => {
          if (res.data.resultCode == 1) {
            this.dataList = res.data.data.pageData;
            this.total = res.data.data.count;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //加载模板
      LoadTemplate(item) {
        var that = this;
        that.apipost("/api/Template/LoadTemplateMarket", {
          Id: item.Id
        }, res => {
          if (res.data.resultCode == 1) {
            that.Confirm("是否前往编辑新模板?", function () {
              that.CommonJump('templateEdit', {
                Id: res.data.data.Id
              });
            });
          } else {
            that.Info(res.data.message);
          }
        })
      }
    },
    mounted() {
      this.getList();
    }
  };

</script>
<style>
  .templateMarket .content {
    background: #fff;
    padding-top: 10px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }

  .templateMarket .template_comheader {
    padding: 13px 20px;
    border-bottom: 1px solid #EBEEF5;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background: #fff;
    margin-bottom: 10px;
  }

  .templateMarket .template_comheader>div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: row;
  }

  .templateMarket .template_MarketList {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .templateMarket .Market_List {
    width: 207.5px;
    height: 370px;
    padding: 0 0 20px 20px;
  }

  .templateMarket .MarketInner {
    width: 187.5px;
    position: relative;
    top: 0;
    border: 1px solid #e2e2e2;
    border-radius: 5px;
    height: 350px;
  }

  .MarketInner:hover .dialog-img {
    display: flex;
  }

  .Market_List:hover .MarketInner {
    top: -10px;
    box-shadow: 0 4px 4px 4px #ECECEC;
  }

  .templateMarket .dialog-img {
    background-color: rgba(0, 0, 0, .4);
    position: absolute;
    left: 0;
    top: 0;
    z-index: 10;
    width: 187.5px;
    height: 270px;
    display: none;
  }

  .dialog-img .choose-btn {
    cursor: pointer;
    border-radius: 6px;
    height: 40px;
    line-height: 38px;
    width: 120px;
    margin: 10px auto;
    text-align: center;
    border: 1px solid #fff;
    color: #fff;
    font-size: 16px;
  }

  .templateMarket .market_useBtn {
    border: 1px solid #3399ff !important;
    background-color: #3399ff;
  }

  .templateMarket .show-img {
    width: 187.5px;
    height: 270px;
    overflow: hidden;
    background-size: cover;
    background-position: 0 0;
    background-repeat: no-repeat;
  }

  .templateMarket .Market_Info {
    padding: 0 10px;
    width: 100%;
    background-color: #fff;
  }

  .templateMarket .item-name {
    font-size: 16px;
    margin: 5px 0;
    width: 80%;
  }

  .templateMarket .price {
    color: #ff4544;
  }

  .MarketView {
    height: 600px;
    overflow-y: auto;
    text-align: center;
  }

</style>
