<template>
  <div id="commodityManageMent">
    <table-list
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      @addClick="addClick"
      :loading="loading"
      @editInfo="editInfo"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="addClick(props.scope.row, 0)"
          >修改</el-button
        >
        <el-button type="text" @click="changeStatus(props.scope.row)">{{
          props.scope.row.goodsStatus === 1 ? "下架" : "上架"
        }}</el-button>
        <el-button type="text" @click="del(props.scope.row)">删除</el-button>
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="pageSize"
      :currentPage="currentPage"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
  </div>
</template>

<script>
import searchBox from "@/components/searchBox";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
export default {
  components: { searchBox, tableList, pagination },
  data() {
    return {
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "商品列表",
        index: 0,
        ch: "条",
        num: false,
        choice: true,
        addHide: false,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      // 表单
      tableSet: [
        {
          label: "商品名称",
          prop: "goodsName",
          scope: "editInfo",
          hidden: true,
        },
        {
          label: "商品编码",
          prop: "code",
          hidden: true,
        },
        {
          label: "专业",
          prop: "categoryName",
          hidden: true,
        },
        {
          label: "院校",
          prop: "schoolName",
          hidden: true,
        },
        // {
        //   label: "业务层级",
        //   prop: "businessList",
        //   hidden: true,
        //   scope:"mapTypesMores",
        //   width:"400"
        // },
        {
          label: "教育类型",
          prop: "educationName",
          hidden: true,
        },
        // {
        //   label: "学时",
        //   prop: "classHours",
        //   prop1: "studyStartTime",
        //   prop2: "studyEndTime",
        //   hidden: true,
        // },
        // {
        //   label: "商品内容视图",
        //   prop: "educationName",
        //   hidden: true,
        // },
        {
          label: "商品价格",
          prop: "standPrice",
          hidden: true,
        },
        {
          label: "商品状态",
          prop: "status",
          hidden: true,
          scope: "hasTime",
        },
        {
          label: "有效期",
          prop1: "validityStartTime",
          prop2: "validityEndTime",
          scope: "TimeLists",
          width: 220,
          Diszing: false,
          hidden: true,
        },
        {
          label: "供应方（服务）",
          prop: "supplyName",
          hidden: true,
        },
        {
          label: "最后编辑时间",
          prop: "updateTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "创建时间",
          prop: "createTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "可售状态",
          prop: "goodsStatus",
          hidden: true,
          scope: "status",
        },
      ],
      tableData: [], //表单数据
      total: 0, //一共多少条
      pageSize: 10, //每页多少条数据
      currentPage: 1, //当前页码
    };
  },
  mounted() {
    this.search();
  },
  methods: {
    editInfo(v) {
      this.addClick(v, 0);
    },
    search(v) {
      this.loading = true;
      var data = {
        status: 1,
        pageSize: this.pageSize,
        pageNum: this.currentPage,
      };
      this.$api.inquireGoods(data).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.navText.index = res.total;
      });
      this.loading = false;
    },
    init() {
      this.search();
    },
    del(v) {
      this.$alert(
        "确定删除此内容？<br />内容删除后将无法恢复，请慎重考虑",
        "提示",
        {
          dangerouslyUseHTMLString: true,
        }
      )
        .then(() => {
          var data = {
            courseId: v.courseId,
            status: -1,
          };
          this.$api.editGoods(data).then((res) => {
            this.$message.success("删除成功");
            this.search();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    addClick(v, int) {
      if (v === undefined) {
        this.$router.push({
          path: "commodityManageMentAdd",
        });
      } else {
        this.$router.push({
          path: "commodityManageMentEdit",
          query: {
            id: v.goodsId,
          },
        });
      }
    },
    handleSizeChange(v) {
      this.pageSize = v;
      this.currentPage = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.currentPage = v;
      this.search();
    },
    changeStatus(item) {
      var status = item.goodsStatus === 1 ? 0 : 1;
      this.$api
        .editGoods({ goodsId: item.goodsId, goodsStatus: status })
        .then((res) => {
          if (item.goodsStatus === 1) {
            this.$message.success("下架成功");
          } else {
            this.$message.success("上架成功");
          }
          this.search();
        });
    },
  },
};
</script>

<style lang="less" 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;
  }
}
</style>

