<template>
  <div class="content" style="background: #f9f9f9">
    <div class="main">
      <div class="tit">商品配置</div>
      <div>
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-row>
            <el-col :span="4">
              <el-form-item prop="sort" label="排序">
                <el-input
                  :disabled="ifadd == 3 ? true : false"
                  v-model="form.sort"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col>
              <el-form-item prop="cover" label="上传封面">
                <imageUpload
                  :disabled="ifadd == 3 ? true : false"
                  v-model="form.cover"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row style="margin-top: 10px">
            <el-col :span="18">
              <el-form-item label="内容" required prop="content">
                <editor
                  ref="sptwEditor"
                  v-model="form.content"
                  :readOnly="ifadd == 3 ? true : false"
                  :min-height="196"
                  :uploadUrl="uploadImgUrl"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="footer">
      <div style="margin: 0 auto">
        <el-button
          class="thebtn"
          style="background: #f9f9f9; border: none"
          @click="cancelCz"
        >
          {{ '取消' }}</el-button
        >
        <el-button
          type="primary"
          class="thebtn"
          style="margin-left: 20px"
          @click="saveDate('form')"
        >
          {{ '确认' }}</el-button
        >
      </div>
    </div>
  </div>
</template>
    
    <script>
import topBar from "@/components/topBar";
import * as equ from "@/api/equipment.js";
import ImageUpload from "@/components/ImageUpload";
import Editor from "@/components/Editor";
export default {
  components: {
    topBar,
    ImageUpload,
    Editor,
  },
  data() {
    return {
      ifadd: true,
      form: {
        sort: "",
        type: 2,
        cover: "",
        content: "",
      },
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/system/upload",
      rules: {
        cover: [
          { required: true, message: '请输入规格类型', trigger: "blur" },
        ],
        content: [{ required: true, message: "请输入", trigger: "blur" }],
      },
    };
  },
  created() {
    if (this.$route.query.dataForm) {
      this.form = JSON.parse(this.$route.query.dataForm);
      this.form.type = 2;
    }
    this.ifadd = this.$route.query.ifAdd;
  },
  methods: {
    saveDate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = "";
          if (this.ifadd == 1) {
            url = equ.saveBanner;
          } else if (this.ifadd == 2) {
            url = equ.updateBanner;
          }
          url(this.form).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.visibleShow = false;
              this.$refs[formName].resetFields();
              this.$router.push({
                path: "equipmentProduct",
              });
            }
          });
        }
      });
    },

    cancelCz() {
      this.$router.push({
        path: "equipmentProduct",
      });
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-date-editor--datetimerange {
  width: auto !important;
}
::v-deep .el-upload--picture-card i {
  color: #c8161d;
}
// ::v-deep .el-upload--picture-card {
//   min-width: 50px !important;
//   min-height: 50px !important;
// }
// ::v-deep .el-image {
//   width: 50px !important;
//   height: 50px !important;
//   display: flex;
//   justify-content: center;
//   align-items: center;
// }

.content {
  background: #fff;
  padding: 0 30px;
  box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
  border-radius: 8px 8px 8px 8px;
}
::v-deep th {
  border: none !important;
}

.main {
  overflow: hidden;
  background: #ffffff;
  border-radius: 8px;
  //margin: 0 20px;
  height: calc(100vh - 230px);
  padding-bottom: 20px;
  box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
}
::v-deep .el-select {
  width: 100%;
}
// }
.footer {
  height: 68px;
  background: #ffffff;
  box-shadow: 0px -3px 20px 0px rgba(204, 204, 204, 0.5);
  // margin: 0 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  bottom: 0px;
  width: 100%;
  .thebtn1 {
    background: #3181e5;
    color: #ffffff;
    padding: 9px 45px;
  }
  .thebtn2 {
    background: #cccccc;
    color: #ffffff;
    padding: 9px 45px;
  }
}
.thebtn {
  width: 137px;
  height: 38px;
}
.tit {
  font-size: 14px;
  font-weight: bold;
  color: #333333;
  padding: 0 20px;
  border-left: 5px solid #c8161d;
  margin: 20px 0 10px 0;
}
.xian {
  height: 1px;
  background: rgba(0, 0, 0, 0.1);
}
::v-deep .el-date-editor--datetimerange {
  width: auto !important;
}
.flexed {
  display: flex;
}
.flexed_l {
  margin-right: 20px;
}
.table {
  padding: 0 40px 100px 40px;
  margin-top: 1px;
  margin-top: 30px;
  max-height: 630px;
  overflow-y: auto;
  width: 800px;
}

table {
  width: 100%;
  background: #fff;
  border-collapse: collapse;
  border: 1px solid #cccccc;
  border-spacing: 0;
  table-layout: fixed;
  border-collapse: collapse;
  //   合并内外边距
  // (去除表格单元格默认的2个像素内外边距*/
}

th {
  padding: 10px 10px;
  text-align: center;
  border: 1px solid #cccccc;
  overflow: hidden;
  border-top: 0;
}
td {
  padding: 10px 10px;
  text-align: center;
  border: 1px solid #cccccc;
  border-top: 0;
  overflow: hidden;
}
.tableFlex {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  .tableFlex_i {
    flex: 1;
    ::v-deep .el-input__inner {
      width: 90%;
    }
  }
}
.tableAdd {
  width: 50px;
  img {
    width: 19px;
    height: 19px;
  }
}
.tableAddPro {
  display: flex;
  align-items: center;
  justify-content: center;
  img {
    width: 19px;
    height: 19px;
    margin-left: 10px;
  }
}
.tableLeft {
  text-align: left;
  border: 0 !important;
}
.tabList {
  display: flex;
  align-items: center;
  padding: 20px 0px 0 20px;
  .tabList_i {
    padding: 10px;
    font-size: 14px;
    font-weight: 400;
    color: #999999;
    cursor: pointer;
  }
  .tabAct {
    background: #108ee9;
    color: #fff;
  }
}
.clearBtm {
  border-bottom: 0;
}
.cpHeight {
  height: 50vh;
  overflow-y: auto;
}
.blueCor {
  color: #589ff8;
  cursor: pointer;
}
::v-deep .el-input__icon {
  line-height: 33px;
}
::v-deep .el-button {
  margin-top: 0;
}
</style>
    