<!--  -->
<template>
  <div>
    <div class="pending">
      <el-tabs v-model="activeName">
        <el-tab-pane label="活动信息" name="first">
          <div class="shop_info">
            <h3 class="detail_title">活动信息</h3>
            <div class="shopInfo_left">
              <p class="detail_text">
                <span>活动名称：</span>
                <span class="text">{{ form.currencyName }}</span>
              </p>
              <p class="detail_text">
                <span>活动备注：</span>
                <span class="text">{{ form.remark }}</span>
              </p>
              <p class="detail_text">
                <span>报名时间：</span>
                <span class="text">{{ form.signStartTime }}-{{ form.signEndTime }}</span>
              </p>
              <p class="detail_text">
                <span>起止时间：</span>
                <span class="text">{{ form.startTime }}-{{ form.endTime }}</span>
              </p>
              <p class="detail_text">
                <span>活动保证金：</span>
                <span class="text textColor ">
                  <el-radio-group v-model="form.ifBond">
                    <el-radio :label="1" disabled>需要</el-radio>
                    <el-radio :label="0" disabled>不需要</el-radio>
                  </el-radio-group>
                </span>
              </p>
              <p v-if="form.ifBond" class="detail_text">
                <span>保证金金额：</span>
                <span class="text">{{ form.bondMoney }}</span>
              </p>
              <p class="detail_text">
                <span>活动状态：</span>
                <span v-if="form.state === 0" class="text">报名未开始</span>
                <span v-if="form.state === 1" class="text">报名进行中</span>
                <span v-if="form.state === 2" class="text">活动待开始</span>
                <span v-if="form.state === 3" class="text">活动进行中</span>
                <span v-if="form.state === 4" class="text">活动已结束</span>
              </p>
            </div>
          </div>
          <div class="shop_info">
            <h3 class="detail_title">优惠规则</h3>
            <p class="detail_text">
              <span>优惠方案：</span>
              <template v-if="form.setRules == 2">
                <span class="text">比例优惠{{ form.currencyMoney }}%</span>
              </template>
              <template v-else-if="form.setRules == 1">
                <span class="text">直降{{ form.currencyMoney }}元</span>
              </template>
            </p>
            <p class="detail_text">
              <span>是否限购：</span>
              <span class="text textColor ">
                <el-radio-group v-model="form.ifLimit">
                  <el-radio :label="2" disabled>限购</el-radio>
                  <el-radio :label="1" disabled>不限购</el-radio>
                </el-radio-group>
              </span>
            </p>
            <p v-if="form.ifLimit == 2" class="detail_text">
              <span>商品限购：</span>
              <span class="text">限购{{ form.limitNumber || 0 }}人</span>
            </p>
            <p class="detail_text">
              <span>优惠券叠加：</span>
              <span class="text textColor ">
                <el-radio-group v-model="form.ifAdd">
                  <el-radio :label="1" disabled>叠加</el-radio>
                  <el-radio :label="0" disabled>不叠加</el-radio>
                </el-radio-group>
              </span>
            </p>
          </div>
        </el-tab-pane>
        <el-tab-pane label="参与店铺" name="second">
          <!-- 搜索 -->
          <div class="formSearch">
            <el-form :inline="true" :model="shopQuery" class="demo-form-inline">
              <el-form-item label="店铺名称">
                <el-input v-model="shopQuery.shopName" maxlength="20" placeholder="请输入店铺名称" />
              </el-form-item>
              <el-form-item label="店铺编码">
                <el-input v-model="shopQuery.shopCode" maxlength="20" placeholder="请输入店铺编码" />
              </el-form-item>
              <el-form-item label="审核状态">
                <el-select v-model="shopQuery.state" clearable placeholder="请选择审核状态">
                  <el-option label="待审核" value="0" />
                  <el-option label="报名成功" value="1" />
                  <el-option label="报名失败" value="2" />
                  <el-option label="报名进行中" value="3" />
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" plain @click="search">查询</el-button>
              </el-form-item>
            </el-form>
          </div>
          <!-- 表格 -->
          <div class="tableBox">
            <el-table ref="multipleTable" :data="tableData" border
              :header-cell-style="{ background: '#EEF3FF', color: '#333333' }" tooltip-effect="dark"
              style="width: 100%">
              <el-table-column label="店铺名称" width="220">
                <template slot-scope="scope">{{ scope.row.shopName }}</template>
              </el-table-column>
              <el-table-column prop="shopCode" label="店铺编码" />
              <el-table-column prop="products" label="参与商品数" />
              <el-table-column prop="examines" label="审核次数" />
              <el-table-column label="审核状态">
                <template slot-scope="scope">
                  <span v-if="scope.row.state == 0">待审核</span>
                  <span v-if="scope.row.state == 1">报名成功</span>
                  <span v-if="scope.row.state == 2">报名失败</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" show-overflow-tooltip>
                <template slot-scope="scope">
                  <div class="btnList">
                    <el-button type="text" @click="seeMore(scope.row)">查看商品</el-button>
                    <el-button type="text" @click="checkList(scope.row)">审核记录</el-button>
                    <el-button v-if="scope.row.state === 0" type="text" @click="examine(scope.row)">审核</el-button>

                    <el-button v-if="scope.row.state === 1" type="text" @click="liquidation(scope.row)">清退</el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="fenye">
              <el-pagination :current-page="shopQuery.page" :page-sizes="[10, 20, 50, 100]" :page-size="10"
                layout="total, sizes, prev, pager, next, jumper" :total="tableTotal" @size-change="handleSizeChange"
                @current-change="handleCurrentChange" />
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="活动数据" name="chart">
          <DetailComponent :info-list="infoList">
            <template #table>
              <div class="table">
                <el-table :data="activityTable" border :header-cell-style="{ background: '#EEF3FF', color: '#333333' }"
                  style="width: 100%">
                  >
                  <el-table-column prop="shopName" label="店铺名称" />
                  <el-table-column prop="shopCode" label="店铺编码" />
                  <el-table-column prop="products" label="参与商品数(件)" />
                  <el-table-column prop="persons" label="访客数" />
                  <el-table-column prop="orders" label="提交订单数" />
                  <el-table-column prop="finish" label="成交比数" />
                  <el-table-column prop="total" label="成交总额" />
                </el-table>
              </div>
            </template>
          </DetailComponent>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!-- 活动商品记录弹框 -->
    <el-dialog title="活动商品" :visible.sync="foodsDia" center width="70%" :close-on-click-modal="false"
      :modal-append-to-body="false" :modal="false">
      <div class="diaddStyle">
        <el-table ref="multipleTable" :data="tableProducts" border
          :header-cell-style="{ background: '#EEF3FF', color: '#333333' }" tooltip-effect="dark" style="width: 100%">
          <el-table-column label="产品主图" width="220">
            <template slot-scope="scope">
              <img :src="scope.row.image" width="50" height="50" alt srcset>
            </template>
          </el-table-column>
          <el-table-column prop="productName" label="产品名称" />
          <el-table-column prop="productId" label="产品id" />
          <el-table-column prop="price" label="售价(元)" />
          <el-table-column prop="originalPrice" label="原价(元)" />
          <el-table-column prop="stockNumber" label="库存(件)" />
          <el-table-column prop="volume" label="累计销量(件)" />
          <el-table-column label="上架状态">
            <template slot-scope="scope">
              <span v-if="scope.row.shelveState == 1">上架</span>
              <span v-if="scope.row.shelveState == 0">下架</span>
            </template>
          </el-table-column>
        </el-table>
        <!-- <div class="fenye">
          <el-pagination :current-page="currentPages" :page-sizes="[10, 20, 50, 100]" :page-size="10"
            layout="total, prev, pager, next, jumper" :total="totals" @size-change="handleSizeChanges"
            @current-change="handleCurrentChanges" />
        </div> -->
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="foodsDia = false">确定</el-button>
      </span>
    </el-dialog>

    <!-- 审核清退 -->
    <el-dialog append-to-body :title="checkObj.title" :visible.sync="checkObj.show" center width="30%"
      :close-on-click-modal="false">
      <div v-if="checkObj.type === 1" class="diaddStyle">
        <el-form ref="form" :model="addform" label-width="80px">
          <el-form-item label="审核状态">
            <el-radio-group v-model="addform.state">
              <el-radio label="1">报名成功</el-radio>
              <el-radio label="2">报名失败</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="addform.remark" maxlength="200" type="textarea" />
          </el-form-item>
        </el-form>
      </div>
      <div v-else class="diaddStyle">
        <div class="text">确认要清退本商家吗？</div>
        <div class="text">清退后商家的所有商品将退出本次活动</div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="enter">确定</el-button>
        <el-button @click="checkDIa = checkObj.show = false">取消</el-button>
      </span>
    </el-dialog>

    <!-- 审核记录弹框 -->
    <el-dialog title="审核记录" :visible.sync="checkDIa" center width="30%" :close-on-click-modal="false"
      :modal-append-to-body="false" :modal="false">
      <div class="diaddStyle">
        <el-table ref="multipleTable" :data="checkLists" border
          :header-cell-style="{ background: '#EEF3FF', color: '#333333' }" tooltip-effect="dark" style="width: 100%">
          <el-table-column label="动态" width="220">
            <template slot-scope="scope">
              {{
        scope.row.operationDescribtion
      }}
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="时间" />
          <el-table-column prop="name" label="操作人" />
          <el-table-column prop="remark" label="其他信息" />
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="checkDIa = false">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getBeeInfo, getShopList, getBeeData, activeGetProducts, activExamine, activeLiquidation, activeGetExamines } from '@/api/active/active_bee.js'
import DetailComponent from '@/views/active/component/detail.vue'
export default {
  props: {
    beeData: {
      typeof: Object,
      default: {}
    },
    activclean: {
      type: Boolean,
      default: false
    }
  },
  components: {
    // List,
    DetailComponent
  },
  created() {
    const { currencyId } = this.beeData;
    this.shopQuery.currencyId = currencyId;
    this.chartQuery.currencyId = currencyId;
    //  请求活动具体信息
    this.getBeeInfoList()
    //  请求店铺数据
    this.getShopAll();
    //  请求活动的数据
    this.getBeeDataList()
  },
  data() {
    return {
      activeName: 'first',
      //  活动详情渲染
      form: {},
      //  活动参与的店铺查询参数
      shopQuery: {
        currencyId: null,
        shopName: "",
        shopCode: "",
        state: "",
        page: 1,
        pageSize: 10
      },
      //  参与店铺的数据
      tableData: [],
      //  店铺总数
      tableTotal: 0,
      //  活动数据
      infoList: [
        { name: '', value: '', fields: 'money' }
      ],
      //  获取活动数据的参数
      chartQuery: {
        currencyId: null,
        page: 1,
        pageSize: 10
      },
      //  查看当前店铺下参与的商品弹框
      foodsDia: false,
      //  查看当前店铺下参与的商品列表
      tableProducts: [],
      //  用于判断是审核还是清退
      checkObj: {},
      addform: {
        signId: '', // 报名id
        state: '1', // 审核状态 1-报名成功 2-报名失败
        remark: '' // 备注
      },
      //  活动数据类表格
      activityTable: [],
      chartTotal: 1,
      chartQuery: {
        page: 1,
        pageSize: 10
      },
      // 审核记录列表
      checkLists: [],
      // 审核记录弹窗
      checkDIa: false,
    }
  },
  methods: {
    //  请求活动详情
    async getBeeInfoList() {
      try {
        let res = await getBeeInfo(this.shopQuery.currencyId);
        this.form = res.data;
      } catch (error) {
        console.log(error);
      }
    },
    //  获取活动参与的店铺
    async getShopAll() {
      try {
        let res = await getShopList(this.shopQuery);
        this.tableData = res.data.list;
        this.tableTotal = res.data.total;
      } catch (error) {
        console.log(error);
      }
    },
    //  获取活动参数的数据
    async getBeeDataList() {
      try {
        let res = await getBeeData(this.chartQuery);
        this.infoList = this.formateInfoList(res)
      } catch (error) {
        console.log(error);
      }
    },
    //  分页数据修改
    handleSizeChange(val) {
      this.shopQuery.pageSize = val;
      this.getShopAll();
    },
    //  数据条数修改
    handleCurrentChange(val) {
      this.shopQuery.page = val;
      this.getShopAll();
    },
    //  查询店铺数据
    search() {
      this.getShopAll()
    },
    //  查看商品
    async seeMore(row) {
      let res = await activeGetProducts({
        signId: row.signId,
        page: 1,
        pageSize: 10
      })
      this.tableProducts = res.data.list;
      // console.log(this.tableProducts);
      // console.log(res)
      this.foodsDia = true;
    },
    //  审核
    examine(row) {
      this.addform.signId = row.signId
      this.checkObj = {
        title: '审核',
        show: true,
        arr: row,
        type: 1
      }
    },
    // 清退
    async liquidation(row) {
      this.checkObj = {
        title: '清退',
        show: true,
        arr: row,
        type: 2
      }
    },
    //  确定
    async enter() {
      if (this.checkObj.type === 1) {
        const res = await activExamine(this.addform)
        if (res.code == '') {
          this.$message({
            message: '处理成功',
            type: 'success'
          })
          this.checkObj.show = false
          this.getShopAll()
        }
      } else {
        const res = await activeLiquidation({
          signId: this.checkObj.arr.signId
        })
        if (res.code === '') {
          this.$message({
            message: '清退成功',
            type: 'success'
          })
          this.checkObj.show = false
          this.getShopAll()
        }
      }
    },
    // 格式化卡片统计渲染
    formateInfoList(res) {
      return [
        {
          name: '浏览量',
          value: res.data.visit || 0
        },
        {
          name: '支付订单数',
          value: res.data.orders || 0
        },
        {
          name: '	支付买家数',
          value: res.data.pays || 0
        },
        {
          name: '支付转化率',
          value: res.data.conversion || 0
        },
        {
          name: '参与商家数',
          value: res.data.shops || 0
        },
        {
          name: '参与商品数',
          value: res.data.products || 0
        },
        {
          name: '活动成交金额',
          value: res.data.total || 0
        }
      ]
    },
    formateTableList(res) {
      if (!Array.isArray(res)) {
        return res
      }
      return res.map((item) => ({
        shopName: item.shopName,
        shopCode: item.shopCode,
        products: item.products,
        persons: item.persons,
        orders: item.orders,
        finish: item.finish,
        total: item.total
      }))
    },
    // 审核记录
    async checkList(row) {
      this.checkDIa = true
      const res = await activeGetExamines({
        only: `${row.shopId}-${row.currencyId}-${row.signId}`
      })
      this.checkLists = res.data
    },
  },
  watch: {
    activclean(newVal, oldVal) {
      if (!newVal) {
        this.activeName = 'first'
        const defaultShopQuery = {
          shopName: "",
          shopCode: "",
          state: "",
          page: 1,
          pageSize: 10
        };
        this.shopQuery = { ...this.shopQuery, ...defaultShopQuery }
        return
      }
      const { currencyId } = this.beeData;
      this.shopQuery.currencyId = currencyId;
      this.chartQuery.currencyId = currencyId;
      //  请求店铺数据
      this.getShopAll();
      //  请求活动的数据
      this.getBeeDataList()
      //  请求活动详情
      this.getBeeInfoList()
    }
  }
}
</script>

<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../../../styles/elDialog.scss");

.pending {
  padding: 30px;
}

.fenye {
  margin-top: 20px;
}

.diaddStyle {
  .text {
    text-align: center;
  }
}

.detail_title {
  font-size: 22px;
  color: #333333;
  position: relative;
  margin: 50px 20px 20px;

  &:before {
    content: "";
    display: block;
    position: absolute;
    top: 5px;
    left: -20px;
    width: 4px;
    height: 24px;
    background-color: #3a68f2;
  }
}

.detail_text {
  padding: 0 120px;

  //  font-size: 16px;
  .text {
    color: #666666;
    line-height: 40px;
    margin-left: 20px;
  }

  .Margin {
    margin-left: 90px;
  }
}

.shop_info {
  overflow: hidden;

  .shopInfo_left {
    float: left;
  }
}

.mf {
  margin-left: 20px;

  .el-tag {
    margin-bottom: 20px;
  }
}

// radio默认选中修改颜色
.el-radio__input.is-disabled+span.el-radio__label {
  color: #409EFF !important;
}
</style>