<template>
  <div class="liveRoomPage">
    <nav>
      <el-form :inline="true" :model="listQuery" class="demo-form-inline">
        <el-form-item label="状态：" label-width="100px">
          <el-radio-group v-model="listQuery.state" @change="searchTypeChange">
            <el-radio-button
              v-for="item in searchType"
              :key="item.value"
              :label="item.value"
            >
              {{ item.label }}
            </el-radio-button>
          </el-radio-group>
        </el-form-item>
        <br>
        <el-form-item label="关键字：" label-width="100px">
          <el-input
            v-model="listQuery.search"
            placeholder="请输入商品名称/ID"
            class="inputKeyWord"
            style="width:400px;"
          >
            <el-button slot="append" icon="el-icon-search" @click="getList" />
          </el-input>
        </el-form-item>
      </el-form>
    </nav>
    <section>
      <el-table
        ref="multipleTable"
        :data="roomList"
        border
        :header-cell-style="{ background: '#EEF3FF', color: '#333333' }"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column prop="id" label="直播商品ID" />
        <el-table-column prop="productName" label="商品名称" />
        <el-table-column prop="productId" label="关联商品ID" />
        <el-table-column width="100" prop="productImage" label="商品图片">
          <template slot-scope="scope">
            <img
              style="width: 40px; height: 40px"
              :src="scope.row.productImage"
              alt=""
            >
          </template>
        </el-table-column>
        <el-table-column prop="startTime" label="商品小程序路径">
          <template slot-scope="scope">
            /pages_category_page1/goodsModule/goodsDetails?productId=
            {{ scope.row.productId }}
          </template>
        </el-table-column>
        <el-table-column label="价格类型" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.priceType == 1">
              一口价
            </el-tag>
            <el-tag v-if="scope.row.priceType == 2" type="success">
              价格区间
            </el-tag>
            <el-tag v-if="scope.row.priceType == 3" type="danger">
              折扣价
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="审核状态" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.state == 0" type="warning">
              待审核
            </el-tag>
            <el-tag v-if="scope.row.state == 1" type="success">
              已通过
            </el-tag>
            <el-tag v-if="scope.row.state == 2" type="danger">
              未通过
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="微信审核状态" width="120">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.wxAuditStatus == 0" type="info">
              未审核
            </el-tag>
            <el-tag v-if="scope.row.wxAuditStatus == 1" type="success">
              审核中
            </el-tag>
            <el-tag v-if="scope.row.wxAuditStatus == 2" type="warning">
              审核通过
            </el-tag>
            <el-tag v-if="scope.row.wxAuditStatus == 3" type="danger">
              审核失败
            </el-tag>
            <el-tag v-if="scope.row.wxAuditStatus == -1">
              未提交
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="添加时间" />
        <el-table-column label="操作" show-overflow-tooltip>
          <template slot-scope="scope">
            <div class="btnList">
              <el-button
                v-if="scope.row.state == 0"
                type="text"
                @click="audit(scope.row)"
              >审核</el-button>
              <el-button
                type="text"
                @click="seeMore(scope.row)"
              >详情</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          :current-page="listQuery.page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </section>

    <el-dialog
      :title="'直播间商品信息'"
      :visible.sync="DetailsShow"
      width="50%"
      center
      :close-on-click-modal="false"
    >
      <el-row>
        <el-col :span="12">
          <el-form :model="ProForm" size="mini" label-width="180px">
            <el-form-item label="商品名称:">
              {{ ProForm.productName }}
            </el-form-item>
            <el-form-item label="商品库存:">
              {{ ProForm.stockNumber }}
            </el-form-item>
            <el-form-item label="商品图片:">
              <img
                style="width: 140px; height: 140px"
                :src="ProForm.productImage"
                alt=""
                srcset=""
              >
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="12">
          <el-form :model="ProForm" size="mini" label-width="180px">
            <el-form-item label="商品价格:">
              <span v-if="ProForm.priceType == 1">
                一口价: {{ ProForm.fixedPrice }}
              </span>
              <span v-if="ProForm.priceType == 2">
                最低价： {{ ProForm.minPrice }} - 最高价：{{ ProForm.maxPrice }}
              </span>
              <span v-if="ProForm.priceType == 3">
                现价: {{ ProForm.marketPrice }}
              </span>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <div v-if="ProForm.remark" style="text-align: center; margin-top: 20px">
        <span style="color: red">备注：</span>
        {{ ProForm.remark }}
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="DetailsShow = false">关 闭</el-button>
      </span>
    </el-dialog>

    <!-- 审核 -->
    <el-dialog
      :title="'审核'"
      :visible.sync="auditShow"
      width="30%"
      center
      :close-on-click-modal="false"
    >
      <el-form :model="auditForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="审核状态">
          <el-radio-group v-model="auditFormState">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">未通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="auditFormState == 2" label="理由">
          <el-input
            v-model="auditForm.remark"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="auditShow = false">取 消</el-button>
        <el-button @click="submint">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  // liveGetList,
  // liveGetById,
  // livePutAudit,
  // liveGetProduct,
  liveProGetAll,
  liveProAudit,
} from '@/api/live';
export default {
  data () {
    return {
      searchType: [
        {
          label: '全部',
          value: null,
        },
        {
          label: '待审核',
          value: 0,
        },
        {
          label: '审核已通过',
          value: 1,
        },
        {
          label: '审核未通过',
          value: 2,
        },
      ],
      listQuery: {
        state: null,
        search: '',
        page: 0,
        pageSize: 10,
        shopId: null,
      },
      proListQuery: {
        liveId: null,
        page: 1,
        pageSize: 10,
        shopId: null,
      },
      roomList: [], // 直播间列表
      roomProList: [], // 直播相关产品列表
      total: 0,
      proTotal: 0,
      DetailsShow: false,
      auditShow: false,
      activeName: 'first',
      disabled: false,
      ProForm: {}, // 添加直播间
      liveRules: [], // 直播间添加验证
      rules: [],
      auditForm: {},
      auditFormState: 1,
    };
  },
  created () {
    this.getList();
  },
  methods: {
    // 获取商品列表
    async getList () {
      const res = await liveProGetAll(this.listQuery);
      this.total = res.data.total;
      this.roomList = res.data.list;
    },
    audit (row) {
      const item = Object.assign({}, row)
      this.auditForm = item;
      this.auditShow = true;
    },
    async submint () {
      this.auditForm.state = this.auditFormState;
      const res = await liveProAudit(this.auditForm);
      this.$message.success('状态审核成功');
      this.auditShow = false;
      this.getList();
    },
    seeMore (row) {
      this.ProForm = row;
      this.DetailsShow = true;
    },
    // 选择查询状态
    searchTypeChange (e) {
      this.listQuery.state = e;
      this.getList();
    },
    // 分页
    handleCurrentChange (e) {
      this.listQuery.page = e;
      this.getList()
    },
    handleSizeChange (e) {
      this.listQuery.pageSize = e;
      this.getList()
    },
    handleCurrentChange1 (e) {
      this.proListQuery.page = e;
      this.getList()
    },
    handleSizeChange1 (e) {
      this.proListQuery.pageSize = e;
      this.getList()
    },
  },
};
</script>

<style lang="scss" scpoed>
.liveRoomPage {
  padding: 32px 20px;
  nav {
    .search {
      line-height: 40px;
      margin: 10px 0;
      display: flex;
      .title {
        min-width: 120px;
        text-align: right;
      }
      .inputKeyWord {
        max-width: 400px;
        min-width: 200px;
      }
    }
  }
  section {
    padding: 12px 8px;
    background-color: #fff;
    .pagination {
      margin-top: 30px;
    }
  }
}
</style>
