<template>
  <div class="mod-config">
    <div style="display: flex;align-items: center;">
      <p
        class="info_bg"
        style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;margin-right: 20px;"
      >
        提示：以下充值商品只针对于<span style="color: #17b3a3; font-weight: 600"
          >【安卓】</span
        >平台
      </p>

      <el-button
        size="mini"
        icon="el-icon-refresh "
        @click="
          pageIndex = 1;
          getDataList();
        "
        >刷新</el-button
      >
      <el-button
        icon="el-icon-plus"
        size="mini"
        type="primary"
        @click="addOrUpdateHandle()"
        >新增</el-button
      >
    </div>

    <el-table
      height="70vh"
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%"
    >
      <el-table-column label="ID" width="70" align="center" prop="priceTypeId">
      </el-table-column>

      <el-table-column
        prop="realMoney"
        header-align="center"
        align="center"
        label="充值金额"
      >
       
      </el-table-column>
      <el-table-column
        prop="money"
        header-align="center"
        align="center"
        label="天医币"
      >
      
      </el-table-column>

      <el-table-column
        prop="givejf"
        width="120"
        header-align="center"
        align="center"
        label="赠送积分"
      >
      </el-table-column>
      <el-table-column
        prop="description"
        header-align="center"
        align="center"
        label="商品描述"
      >
      </el-table-column>
      <el-table-column
        width="200"
        prop="effective"
        header-align="center"
        align="center"
        label="有效时长"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.effective == '0'">
            长期有效
          </span>
          <span v-if="scope.row.effective == '1'">
           开始： {{ scope.row.startTime }}<br />
           结束： {{ scope.row.endTime }}
          </span>
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="100"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click.native="addOrUpdateHandle(scope.row.priceTypeId)"
            >修改</el-button
          >
          <el-button
            style="color:red"
            type="text"
            size="small"
            @click="deleteHandle(scope.row.priceTypeId)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getDataList"
      @showchooseBookf="showchooseBookf"
    ></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./views/add.vue";

export default {
  data() {
    return {
      dataForm: {
        key: "",
        qudao: "Android"
      },
      goodsTypeList: [
        {
          id: 0,
          title: "Android",
          value: "Android"
        }
      ],
      dataList: [],
      publishStatus: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      chooseBookVisible: false,
      curriculumVisible: false,
      bookIds: [],
      LinkCouponVisible: false, // 显示优惠券弹窗
      curProductId: undefined // 当前的商品id
    };
  },
  components: {
    AddOrUpdate
  },
  activated() {
    this.getDataList();
  },
  methods: {
    showLinkCoupon(id) {
      this.curProductId = id;
      this.LinkCouponVisible = true;
    },
    proCouponClose() {
      this.LinkCouponVisible = false;
    },

    handleEditTags(id) {
      this.$nextTick(() => {
        this.$refs.commonTags.open(id);
      });
    },
    handleEditCorrelation(id) {
      this.$nextTick(() => {
        this.$refs.correlation.open(id);
      });
    },
    closeBookf() {
      this.chooseBookVisible = false;
    },
    showchooseBookf(e) {
      // 显示图书列表
      this.chooseBookVisible = true;
      // console.log(this.bookIds,'this.bookIds')
      // this.$nextTick(() => {
      //   this.$refs.chooseBook.getBookList()
      //   this.bookIds = e.bookIds
      //   })
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;

      this.$http
        .request({
          url: this.$http.adornUrl(`/master/BuyConfig/getBookBuyConfigList`),

          method: "POST",
          data: {
            page: this.pageIndex,
            limit: this.pageSize,
            type: "point",

            qudao: this.dataForm.qudao
          },
          header: {
            //默认 无 说明：请求头
            "Content-Type": "application/json"
          }
        })
        .then(({ data }) => {
          if (data && data.code === 0) {
            this.dataList = data.result.records;
            this.totalPage = data.result.total;
            this.pageIndex = data.result.current;
          } else {
            this.dataList = [];
            this.totalPage = 0;
            this.pageIndex = 1;
          }
          setTimeout(() => {
            this.dataListLoading = false;
          }, 100);
        });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id);
      });
    },
    handleEditCurriculum(id) {
      this.curriculumVisible = true;
      this.$nextTick(() => {
        this.$refs.curriculum.init(id);
      });
    },
    // 删除
    deleteHandle(id) {
      var ids = id;

      this.$confirm(
        `确定对[id=${ids}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl("/master/BuyConfig/delBookBuyConfig"),
          method: "post",
          data: this.$http.adornData({
            id: ids
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.getDataList();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
    SwitchChange(event) {
      /*点击时他会自动把你绑定的值变更，直接去请求数据就可以了*/
      var parms = {
        publishStatus: event.publishStatus,
        productId: event.productId
      };
      // console.log(parms)
      this.$http({
        url: this.$http.adornUrl("/book/shopproduct/update"),
        method: "post",
        data: parms
      })
        .then(res => {
          this.$message({
            message: "成功",
            type: "success"
          });
          this.loading = false;
          this.getDataList();
        })
        .catch(error => {
          this.loading = false;
          console.log(error);
        });
      console.log(event);
    }
  }
};
</script>

<style scoped lang="less">
.info_bg {
  background: #e0dede;
  height: 28px;
  line-height: 28px;
  padding-left: 10px;
  // padding: 8px 5px;
  box-sizing: border-box;
  // margin-top: -10px;
  border-radius: 4px;
  font-size: 14px;
  width: calc(100% - 120px);
  float: left;
}
</style>
