瀏覽代碼

商品规则对接完成

谢杰标 3 年之前
父節點
當前提交
47f8780438

+ 22 - 3
src/api/resource/good.js

@@ -9,19 +9,38 @@ export function getSpecList(query) {
     })
 }
 
-// 新增规格模板
-export function addSpec(data) {
+
+// 新增或修改模板
+export function changeSpec(data, t) {
     return request({
-        url: '/system/template/addSpec',
+        url: `/system/template/${t ? 'edit' : 'addSpec'}`,
         method: 'post',
         data
     })
 }
 
+
 // 删除规格模板
 export function delSpec(id) {
     return request({
         url: '/system/template/del/' + id,
         method: 'get',
     })
+}
+
+// 模板详情
+export function getSpecDetail(id) {
+    return request({
+        url: '/system/template/detail/' + id,
+        method: 'get',
+    })
+}
+
+// 新增规格属性关联
+export function relation(data, b) {
+    return request({
+        url: `/system/relation/${b ? 'edit' : ''}`,
+        method: 'post',
+        data
+    })
 }

+ 46 - 13
src/components/tableList.vue

@@ -1,6 +1,6 @@
 <template>
   <div id="tableList">
-    <div class="headerNavTool">
+    <div class="headerNavTool" v-if="navText.headShow !== false">
       <div class="leftIndexText">
         {{ navText.title }} <strong>{{ navText.index }}</strong>
         {{ navText.ch }}
@@ -77,6 +77,7 @@
     </div>
     <el-table
       :data="tableData"
+      :span-method="objectSpanMethod"
       stripe
       style="width: 100%"
       @select-all="selectAll"
@@ -95,6 +96,23 @@
       }"
       :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
     >
+      <el-table-column
+        v-if="navText.choiceRadio"
+        align="center"
+        type="selection"
+        fixed="left"
+        width="55"
+      >
+        <template slot-scope="scope">
+          <el-radio
+            style="margin-left: 10px"
+            v-model="tableRadio"
+            :label="scope.row[navText.radioKey]"
+            @change="radioChange"
+            >{{ "" }}</el-radio
+          >
+        </template>
+      </el-table-column>
       <el-table-column
         v-if="navText.choice"
         :reserve-selection="navText.openCheckMore"
@@ -158,15 +176,18 @@
               @change="blurBackData(scope.row)"
             ></el-input-number>
           </div>
-          <span v-else-if="item.scope === 'status'">{{
-            Number(scope.row[item.prop]) === 1
-              ? "启用"
-              : Number(scope.row[item.prop]) === 0
-              ? "关闭"
-              : Number(scope.row[item.prop]) === -1
-              ? "已删除"
-              : "未知"
-          }}</span>
+          <span
+            v-else-if="item.scope === 'status' && scope.row[item.prop] != null"
+            >{{
+              Number(scope.row[item.prop]) === 1
+                ? "启用"
+                : Number(scope.row[item.prop]) === 0
+                ? "关闭"
+                : Number(scope.row[item.prop]) === -1
+                ? "已删除"
+                : "未知"
+            }}</span
+          >
           <span v-else-if="item.scope === 'hasTime'">{{
             Number(scope.row[item.prop]) === 1
               ? "有效"
@@ -935,7 +956,7 @@
           </span>
           <span v-else-if="item.scope === 'TimeLists'"
             >{{ $methodsTools.onlyForma(scope.row[item.prop1], item.Diszing) }}
-            至
+            {{ scope.row[item.prop1] ? "" : "" }}
             {{
               $methodsTools.onlyForma(scope.row[item.prop2], item.Diszing)
             }}</span
@@ -1866,6 +1887,8 @@ export default {
     "rowKey",
     "loading",
     "studentTable",
+    "objectSpanMethod",
+    "radio",
   ],
   data: function () {
     return {
@@ -1917,6 +1940,14 @@ export default {
     };
   },
   computed: {
+    tableRadio: {
+      get() {
+        return this.radio;
+      },
+      set(val) {
+        this.$emit("update:radio", val);
+      },
+    },
     compTableSet: function () {
       return function (options) {
         var arrays = options.filter((item) => {
@@ -1960,6 +1991,7 @@ export default {
     this.initTR();
   },
   methods: {
+    radioChange(val) {},
     /**
      * 学习账号标记跳转班级
      */
@@ -2487,7 +2519,6 @@ export default {
     },
     //自定义列全选按钮触发
     handleCheckAllChange(val) {
-      console.log(val, "val");
       this.checkedCities = val ? this.cities : [];
       this.isIndeterminate = false;
       if (val) {
@@ -2701,6 +2732,7 @@ export default {
       this.allCheckData = value;
     },
     select(value) {
+      console.log(value);
       this.allCheckData = value;
     },
     load(tree, treeNode, resolve) {
@@ -2830,7 +2862,7 @@ export default {
 </style>
 <style lang="less" scoped>
 #tableList {
-  padding: 0px 16px 16px;
+  padding: 16px 16px 16px;
   border-radius: 8px;
   box-shadow: 0px 0px 9px 1px rgba(28, 41, 90, 0.1);
   background: #ffffff;
@@ -2839,6 +2871,7 @@ export default {
     display: flex;
     justify-content: space-between;
     align-items: center;
+    margin-top: -16px;
     .rightBtnBox {
       display: flex;
       align-items: center;

+ 56 - 4
src/views/Marketing/goods/spec/compoent/SpecBox.vue

@@ -9,11 +9,11 @@
       label-width="20px"
     >
       <div class="fBtn">
-        <el-button type="text">规格值排序</el-button>
+        <el-button type="text" @click="valueSort">规格值排序</el-button>
         <el-button type="text" @click="delSpec">删除规则</el-button>
       </div>
       <el-form-item label=" " prop="name">
-        <el-input v-model="form.name"></el-input>
+        <el-input v-model="form.name" style="width: 220px"></el-input>
       </el-form-item>
       <div class="line"></div>
       <el-form-item
@@ -33,10 +33,31 @@
           ></el-input
         >
       </el-form-item>
-      <el-button @click="add" style="margin: 20px 0 0 20px" type="text"
+      <el-button @click="add" style="margin: 30px 0 0 0" type="text"
         >添加</el-button
       >
     </el-form>
+    <el-dialog
+      title="规格值排序"
+      :visible.sync="dialogFormVisible"
+      width="400px"
+    >
+      <div class="box" v-for="item in copyList" :key="item.name">
+        <el-input-number
+          style="width: 50px; margin-right: 10px"
+          v-model="item.sort"
+          :min="1"
+          :max="20"
+          label="描述文字"
+          :controls="false"
+        ></el-input-number>
+        {{ item.name }}
+      </div>
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="dialogFormVisible = false">取 消</el-button>
+        <el-button type="primary" @click="submit">确 定</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
@@ -68,6 +89,8 @@ export default {
       rules: {
         name: [{ validator: checkName, trigger: "blur" }],
       },
+      dialogFormVisible: false,
+      copyList: [],
     };
   },
   computed: {
@@ -76,6 +99,15 @@ export default {
     },
   },
   methods: {
+    valueSort() {
+      this.dialogFormVisible = true;
+      this.copyList = JSON.parse(JSON.stringify(this.form.specAttrList));
+    },
+    submit() {
+      this.form.specAttrList = this.copyList.sort((p, y) => p.sort - y.sort);
+      console.log(this.form.specAttrList);
+      this.dialogFormVisible = false;
+    },
     add() {
       this.form.specAttrList.push({ name: "", sort: undefined });
     },
@@ -89,7 +121,24 @@ export default {
       this.form.specAttrList.splice(index, 1);
     },
     delSpec() {
-      this.obj.splice(this.num, 1);
+      this.$confirm(
+        "删除该规格类型后,当前的规格类型相关数据将丢失,确认要删除吗?",
+        "提示",
+        {
+          confirmButtonText: "确定",
+          cancelButtonText: "取消",
+          type: "warning",
+        }
+      )
+        .then(() => {
+          this.obj.splice(this.num, 1);
+        })
+        .catch(() => {
+          this.$message({
+            type: "info",
+            message: "已取消删除",
+          });
+        });
     },
     checkSpecVal(rule, value, callback) {
       if (!value) {
@@ -126,6 +175,9 @@ export default {
     right: 30px;
     top: 20px;
   }
+  .box {
+    margin-left: 20px;
+  }
   /deep/ {
     .el-input {
       margin-top: 20px;

+ 270 - 106
src/views/Marketing/goods/spec/compoent/configTable.vue

@@ -1,136 +1,300 @@
 <template>
-  <div>
-    <el-table
-      :data="tableData"
-      :span-method="objectSpanMethod"
-      border
-      style="width: 100%; margin-top: 20px"
+  <div class="configTable">
+    <table-list
+      :tableSets="backSet(1)"
+      :tableData="tableData"
+      :navText="backNavText(false)"
+      :objectSpanMethod="objectSpanMethod"
+      :loading="loading"
     >
-      <el-table-column
-        prop="id"
-        :label="item.name + ''"
-        width="180"
-        align="center"
-        v-for="(item, index) in specList"
-        :key="index"
+      <template slot="btn" slot-scope="scope">
+        <el-button
+          type="text"
+          size="small"
+          @click.once="getCourseSubject"
+          @click="configCourse(scope.scope.row)"
+          >配置课程</el-button
+        >
+      </template>
+    </table-list>
+    <el-dialog title="添加" :visible.sync="dialogTableVisible" width="1200px">
+      <search-box-new
+        ref="searchBox"
+        :formData="formData"
+        :formList="formList"
+        @search="search"
+        @init="init"
+      />
+      <table-list
+        :tableSets="backSet(0)"
+        :tableData="courseData"
+        :navText="backNavText(true)"
+        :loading="loading"
+        :radio.sync="tableRadio"
       >
-      </el-table-column>
-      <el-table-column prop="name" label="商品编号" align="center">
-      </el-table-column>
-      <el-table-column prop="amount1" label="商品类型" align="center">
-      </el-table-column>
-      <el-table-column prop="amount2" label="商品名称" align="center">
-      </el-table-column>
-      <el-table-column prop="amount3" label="科目" align="center">
-      </el-table-column>
-      <el-table-column prop="amount3" label="价格" align="center">
-      </el-table-column>
-      <el-table-column prop="amount3" label="商品有效期" align="center">
-      </el-table-column>
-      <el-table-column prop="amount3" label="学习服务期" align="center">
-      </el-table-column>
-      <el-table-column prop="amount3" label="可售状态" align="center">
-      </el-table-column>
-      <el-table-column prop="amount3" label="操作" align="center"
-        ><template slot-scope="scope">
-          <el-button type="text" size="small">查看</el-button>
-          <el-button type="text" size="small">编辑</el-button>
-        </template>
-      </el-table-column>
-    </el-table>
+      </table-list>
+      <pagination
+        :total="total"
+        :pageSize="formData.pageSize"
+        :currentPage="formData.pageNum"
+        @handleSizeChange="handleSizeChange"
+        @handleCurrentChange="handleCurrentChange"
+      />
+      <div slot="footer" class="dialog-footer">
+        <el-button @click="dialogTableVisible = false">取 消</el-button>
+        <el-button type="primary" @click="submit">确 定</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
 <script>
+import searchBoxNew from "@/components/searchBoxNew";
+import tableList from "@/components/tableList";
+import pagination from "@/components/pagination";
+import { relation } from "@/api/resource/good";
 export default {
+  props: ["businessId", "educationTypeId", "tableData", "specList"],
   data() {
     return {
-      tableData: [
+      courseData: [],
+      dialogTableVisible: false,
+      formList: [
         {
-          id: "12987122",
-          name: "王小虎",
-          amount1: "234",
-          amount2: "3.2",
-          amount3: 10,
+          prop: "subjectId",
+          placeholder: "科目",
+          scope: "select",
+          options: [],
         },
         {
-          id: "12987123",
-          name: "王小虎",
-          amount1: "165",
-          amount2: "4.43",
-          amount3: 12,
+          prop: "goodsType",
+          placeholder: "类型",
+          scope: "select",
+          options: [
+            { label: "视频", value: "1" },
+            { label: "直播", value: "6" },
+            { label: "题库", value: "2" },
+          ],
         },
         {
-          id: "12987124",
-          name: "王小虎",
-          amount1: "324",
-          amount2: "1.9",
-          amount3: 9,
+          prop: "code",
+          placeholder: "商品编号",
         },
+      ],
+      formData: {},
+      loading: false,
+      total: 0,
+      tableRadio: "",
+      activeData: {},
+      rowIndexArr: [],
+    };
+  },
+  methods: {
+    submit() {
+      if (!this.tableRadio) {
+        return this.$message({
+          message: "请选择课程",
+          type: "warning",
+        });
+      }
+      let { specTemplateId, attrListVos, goodsId } = this.activeData;
+      let specAttributeIds = attrListVos.map((e) => e.key).toString();
+      relation(
         {
-          id: "12987125",
-          name: "王小虎",
-          amount1: "621",
-          amount2: "2.2",
-          amount3: 17,
+          specTemplateId,
+          specAttributeIds,
+          goodsId: this.tableRadio,
         },
+        goodsId
+      ).then((res) => {
+        this.$message({
+          message: "配置成功",
+          type: "success",
+        });
+        let obj = this.courseData.find((e) => e.goodsId == this.tableRadio);
+        this.activeData = Object.assign(this.activeData, obj);
+        this.dialogTableVisible = false;
+      });
+    },
+    objectSpanMethod({ rowIndex, columnIndex }) {
+      if (columnIndex < this.specList.length - 1) {
+        let index = this.rowIndexArr[columnIndex].indexOf(rowIndex);
+        if (index != -1) {
+          return {
+            rowspan: this.rowIndexArr[columnIndex][index + 1] - rowIndex,
+            colspan: 1,
+          };
+        } else {
+          return {
+            rowspan: 0,
+            colspan: 0,
+          };
+        }
+      }
+    },
+    init() {
+      this.formData = {
+        pageSize: 10,
+        pageNum: 1,
+        businessId: this.businessId,
+        educationTypeId: this.educationTypeId,
+      };
+      this.search();
+    },
+    getCourseSubject() {
+      this.$api
+        .inquireCourseSubject({ status: 1, businessId: this.businessId })
+        .then((res) => {
+          res.rows.map((e) => {
+            e.value = e.id;
+            e.label = e.subjectName;
+          });
+          this.formList[0].options = res.rows;
+        });
+    },
+    configCourse(row) {
+      this.tableRadio = "";
+      this.activeData = row;
+      this.dialogTableVisible = true;
+      this.search();
+    },
+    handleSizeChange(v) {
+      this.formData.pageSize = v;
+      this.formData.pageNum = 1;
+      this.search();
+    },
+    handleCurrentChange(v) {
+      this.formData.pageNum = v;
+      this.search();
+    },
+    search() {
+      this.loading = true;
+      this.$api
+        .inquireGoods(this.formData)
+        .then((res) => {
+          this.courseData = res.rows;
+          this.total = res.total;
+        })
+        .finally(() => {
+          this.loading = false;
+        });
+    },
+    backSet(type) {
+      let tableSet = [
         {
-          id: "12987126",
-          name: "王小虎",
-          amount1: "539",
-          amount2: "4.1",
-          amount3: 15,
+          label: "商品编码",
+          prop: "code",
+          hidden: true,
         },
         {
-          id: "12987126",
-          name: "王小虎",
-          amount1: "539",
-          amount2: "4.1",
-          amount3: 15,
+          label: "商品类型",
+          prop: "code",
+          hidden: true,
         },
-      ],
-      specList: [
-        { name: 1, specAttrList: [{ name: 11, name: 12 }] },
-        { name: 2, specAttrList: [{ name: 21, name: 22, name: 23 }] },
-      ],
-      specN: [[1, 2]],
-    };
-  },
-  methods: {
-    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
-      const item = this.specN[columnIndex];
-      if (item) {
-        for (let i = 0; i < item.length; i++) {
-          const ele = item[i];
-          if (rowIndex == 0 || rowIndex == ele) {
-            return {
-              rowspan: ele + 1,
-              colspan: 1,
-            };
-          }
-          if (rowIndex == ele) {
-            return {
-              rowspan: ele + 1,
-              colspan: 1,
-            };
-          }
-        }
-        // if (item.includes(rowIndex)) {
-        //   return {
-        //     rowspan: rowIndex,
-        //     colspan: 1,
-        //   };
-        // } else {
-        //   return {
-        //     rowspan: 0,
-        //     colspan: 0,
-        //   };
-        // }
+        {
+          label: "商品名称",
+          prop: "goodsName",
+          hidden: true,
+        },
+        {
+          label: "科目",
+          prop: "subjectNames",
+          hidden: true,
+        },
+        {
+          label: "商品价格",
+          prop: "standPrice",
+          hidden: true,
+        },
+        {
+          label: "商品有效期",
+          prop1: "validityStartTime",
+          prop2: "validityEndTime",
+          scope: "TimeLists",
+          Diszing: false,
+          hidden: true,
+        },
+        {
+          label: "学习服务期",
+          prop1: "serviceTimeType",
+          prop2: "serviceTimeNum",
+          prop3: "studyStartTime",
+          prop4: "studyEndTime",
+          scope: "studentServicePeriod",
+          hidden: true,
+        },
+        {
+          label: "可售状态",
+          prop: "goodsStatus",
+          hidden: true,
+          scope: "status",
+        },
+      ];
+      if (type) {
+        this.specList.map((e, i) => {
+          tableSet.splice(i, 0, {
+            label: e.name + "",
+            prop: "value" + i,
+            hidden: true,
+          });
+        });
+      }
+      return tableSet;
+    },
+    backNavText(choice) {
+      return {
+        index: 0,
+        num: false,
+        border: true,
+        choice: false,
+        choiceRadio: choice,
+        radioKey: "goodsId",
+        addHide: !false,
+        tableHide: choice,
+        dontNum: true,
+        headShow: false,
+        backFatherBtn: {
+          status: false,
+          title: "未定义",
+        },
+      };
+    },
+    getRowIndex() {
+      for (let i = 0, len = this.specList.length; i < len - 1; i++) {
+        this.rowIndexArr[i] = this.backIndex(i);
       }
     },
+    backIndex(i) {
+      let arr = [];
+      let len = this.tableData.length;
+      this.tableData.reduce((res, current, index) => {
+        if (res == 0 || res != current["value" + i] || index == len - 1) {
+          arr.push(index == len - 1 ? index + 1 : index);
+        }
+        return current["value" + i];
+      }, 0);
+      return arr;
+    },
+  },
+  created() {
+    this.getRowIndex();
+    this.formData = {
+      pageSize: 10,
+      pageNum: 1,
+      businessId: this.businessId,
+      educationTypeId: this.educationTypeId,
+    };
   },
+  components: { searchBoxNew, tableList, pagination },
 };
 </script>
 
+<style lang="scss" scoped>
+.configTable {
+}
+</style>
 <style>
+.fon_s {
+  display: none;
+}
 </style>

+ 9 - 1
src/views/Marketing/goods/spec/index.vue

@@ -21,7 +21,7 @@
         >添加商品规格模板</el-button
       >
       <template slot="btn" slot-scope="props">
-        <el-button type="text" @click="msgInfo(props.scope.row)"
+        <el-button type="text" @click="handleEdit(props.scope.row)"
           >修改</el-button
         >
         <el-button type="text" @click="handleDel(props.scope.row)"
@@ -147,6 +147,14 @@ export default {
       this.formData.pageNum = 1;
       this.search();
     },
+    handleEdit({ specTemplateId }) {
+      this.$router.push({
+        path: "specEdit",
+        query: {
+          id: specTemplateId,
+        },
+      });
+    },
     handleClick(e) {
       this.$router.push({
         path: "specAdd",

+ 76 - 53
src/views/Marketing/goods/spec/specAdd.vue

@@ -7,48 +7,49 @@
       label-width="170px"
       hide-required-asterisk
     >
-      <el-form-item label="使用的业务层次" required>
-        <div style="display: flex">
-          <el-form-item prop="educationTypeId">
-            <el-select
-              style="margin-right: 24px"
-              v-model="ruleForm.educationTypeId"
-              placeholder="请选择教育类型"
-              :disabled="!!stId"
-              @change="changeEduType"
-            >
-              <el-option
-                v-for="(item, index) in eduTypeOptions"
-                :key="index"
-                :label="item.educationName"
-                :value="item.id"
+      <template v-if="!isNext">
+        <el-form-item label="使用的业务层次" required>
+          <div style="display: flex">
+            <el-form-item prop="educationTypeId">
+              <el-select
+                style="margin-right: 24px"
+                v-model="ruleForm.educationTypeId"
+                placeholder="请选择教育类型"
+                :disabled="isNext"
+                @change="changeEduType"
               >
-              </el-option>
-            </el-select>
-          </el-form-item>
+                <el-option
+                  v-for="(item, index) in eduTypeOptions"
+                  :key="index"
+                  :label="item.educationName"
+                  :value="item.id"
+                >
+                </el-option>
+              </el-select>
+            </el-form-item>
 
-          <el-form-item prop="businessId">
-            <el-select
-              :disabled="!!stId"
-              v-model="ruleForm.businessId"
-              placeholder="请选择业务层次"
-            >
-              <el-option
-                v-for="(item, index) in newCourTypeOptions"
-                :key="index"
-                :label="item.projectName + '-' + item.businessName"
-                :value="item.id"
+            <el-form-item prop="businessId">
+              <el-select
+                :disabled="isNext"
+                v-model="ruleForm.businessId"
+                placeholder="请选择业务层次"
               >
-              </el-option>
-            </el-select>
-          </el-form-item>
-        </div>
-      </el-form-item>
-      <el-form-item label="名称" prop="name">
-        <el-input v-model="ruleForm.name"></el-input>
-      </el-form-item>
-      <template v-if="!stId">
+                <el-option
+                  v-for="(item, index) in newCourTypeOptions"
+                  :key="index"
+                  :label="item.projectName + '-' + item.businessName"
+                  :value="item.id"
+                >
+                </el-option>
+              </el-select>
+            </el-form-item>
+          </div>
+        </el-form-item>
+        <el-form-item label="名称" prop="name">
+          <el-input v-model="ruleForm.name" style="width: 220px"></el-input>
+        </el-form-item>
         <el-form-item label="商品规格" class="eee" prop="specList">
+          <div class="spec-title">最多添加两个商品规格类型</div>
           <Spec-box
             ref="specBox"
             v-for="(item, index) in ruleForm.specList"
@@ -58,6 +59,7 @@
           >
           </Spec-box>
           <el-button
+            :disabled="ruleForm.specList.length >= 2"
             size="mini"
             style="margin: 20px"
             type="primary"
@@ -72,10 +74,16 @@
       >
       <template v-else>
         <el-form-item label="商品配置">
-          <Config-table></Config-table>
+          <Config-table
+            :businessId="ruleForm.businessId"
+            :educationTypeId="ruleForm.educationTypeId"
+            :tableData="tableData"
+            :specList="ruleForm.specList"
+          ></Config-table>
         </el-form-item>
         <el-form-item label=" " style="margin-top: 40px">
-          <el-button type="primary" @click="submitForm">保存</el-button>
+          <el-button type="primary" @click="isNext = false">上一步</el-button>
+          <el-button type="primary" @click="back">返回</el-button>
         </el-form-item>
       </template>
     </el-form>
@@ -85,7 +93,7 @@
 <script>
 import SpecBox from "./compoent/SpecBox.vue";
 import ConfigTable from "./compoent/configTable.vue";
-import { addSpec } from "@/api/resource/good";
+import { changeSpec } from "@/api/resource/good";
 export default {
   data() {
     var checkList = (rule, value, callback) => {
@@ -107,9 +115,10 @@ export default {
         ],
         specList: [{ validator: checkList }],
       },
-      isNext: true,
+      isNext: false,
       eduTypeOptions: [],
       newCourTypeOptions: [],
+      tableData: [],
     };
   },
   methods: {
@@ -129,13 +138,19 @@ export default {
       this.ruleForm = {
         educationTypeId: undefined,
         businessId: undefined,
-        specTemplateId: "123",
+        specTemplateId: "",
         name: "",
         specList: [],
       };
       this.addSpec();
     },
     addSpec() {
+      if (this.ruleForm.specList.length == 2) {
+        return this.$message({
+          message: "最多添加两个商品规格",
+          type: "warning",
+        });
+      }
       this.ruleForm.specList.push({
         name: "",
         specAttrList: [{ name: "", sort: undefined }],
@@ -143,8 +158,15 @@ export default {
     },
     submitForm() {
       this.checkSpecBox() &&
-        addSpec(this.ruleForm).then((res) => {
-          this.ruleForm.specTemplateId = res.data.specTemplateId;
+        changeSpec(this.ruleForm, this.ruleForm.specTemplateId).then((res) => {
+          this.isNext = true;
+          this.ruleForm.specTemplateId = res.data[0].specTemplateId;
+          res.data.map((ele) => {
+            ele.attrListVos.map((e, i) => {
+              ele["value" + i] = e.value;
+            });
+          });
+          this.tableData = res.data;
         });
     },
     checkSpecBox() {
@@ -157,12 +179,11 @@ export default {
       }
       return result;
     },
-  },
-  computed: {
-    stId() {
-      return this.ruleForm.specTemplateId;
+    back() {
+      this.$router.go(-1);
     },
   },
+  computed: {},
   created() {
     this.resetFrom();
     this.$api.inquireCourseEducationType({ status: 1 }).then((res) => {
@@ -179,16 +200,18 @@ export default {
 <style  lang="scss" scoped>
 #specAdd {
   padding-top: 30px;
+  .spec-title {
+    padding-left: 20px;
+    height: 20px;
+    color: #999;
+  }
   .el-form {
     /deep/ {
-      .el-input__inner {
-        width: 220px;
-      }
       .eee {
         .el-form-item__content {
+          margin-top: 10px;
           background: #eee;
           min-height: 60px;
-          //   padding-bottom: 10px;
         }
       }
     }

+ 221 - 3
src/views/Marketing/goods/spec/specEdit.vue

@@ -1,10 +1,228 @@
 <template>
-  <div>edit</div>
+  <div id="specAdd">
+    <el-form
+      :model="ruleForm"
+      :rules="rules"
+      ref="ruleForm"
+      label-width="170px"
+      hide-required-asterisk
+    >
+      <template v-if="!isNext">
+        <el-form-item label="使用的业务层次" required>
+          <div style="display: flex">
+            <el-form-item prop="educationTypeId">
+              <el-select
+                style="margin-right: 24px"
+                v-model="ruleForm.educationTypeId"
+                placeholder="请选择教育类型"
+                disabled
+              >
+                <el-option
+                  v-for="(item, index) in eduTypeOptions"
+                  :key="index"
+                  :label="item.educationName"
+                  :value="item.id"
+                >
+                </el-option>
+              </el-select>
+            </el-form-item>
+
+            <el-form-item prop="businessId">
+              <el-select
+                disabled
+                v-model="ruleForm.businessId"
+                placeholder="请选择业务层次"
+              >
+                <el-option
+                  v-for="(item, index) in newCourTypeOptions"
+                  :key="index"
+                  :label="item.projectName + '-' + item.businessName"
+                  :value="item.id"
+                >
+                </el-option>
+              </el-select>
+            </el-form-item>
+          </div>
+        </el-form-item>
+        <el-form-item label="名称" prop="name">
+          <el-input v-model="ruleForm.name" style="width: 220px"></el-input>
+        </el-form-item>
+        <el-form-item label="商品规格" class="eee" prop="specList">
+          <div class="spec-title">最多添加两个商品规格类型</div>
+          <Spec-box
+            ref="specBox"
+            v-for="(item, index) in ruleForm.specList"
+            :key="index"
+            v-model="ruleForm.specList"
+            :num="index"
+          >
+          </Spec-box>
+          <el-button
+            :disabled="ruleForm.specList.length >= 2"
+            size="mini"
+            style="margin: 20px"
+            type="primary"
+            icon="el-icon-plus"
+            @click="addSpec"
+            >添加规则</el-button
+          >
+        </el-form-item>
+        <el-form-item label=" " style="margin-top: 40px">
+          <el-button type="primary" @click="submitForm">下一步</el-button>
+        </el-form-item></template
+      >
+      <template v-else>
+        <el-form-item label="商品配置">
+          <Config-table
+            :businessId="ruleForm.businessId"
+            :educationTypeId="ruleForm.educationTypeId"
+            :tableData="tableData"
+            :specList="ruleForm.specList"
+          ></Config-table>
+        </el-form-item>
+        <el-form-item label=" " style="margin-top: 40px">
+          <el-button type="primary" @click="isNext = false">上一步</el-button>
+          <el-button type="primary" @click="back">返回</el-button>
+        </el-form-item>
+      </template>
+    </el-form>
+  </div>
 </template>
 
 <script>
-export default {};
+import SpecBox from "./compoent/SpecBox.vue";
+import ConfigTable from "./compoent/configTable.vue";
+import { getSpecDetail, changeSpec } from "@/api/resource/good";
+export default {
+  data() {
+    var checkList = (rule, value, callback) => {
+      if (!this.ruleForm.specList.length) {
+        callback(new Error("请先添加规则"));
+      } else {
+        callback();
+      }
+    };
+    return {
+      ruleForm: {},
+      rules: {
+        name: [{ required: true, message: "请输入名称", trigger: "blur" }],
+        educationTypeId: [
+          { required: true, message: "请选择教育类型", trigger: "change" },
+        ],
+        businessId: [
+          { required: true, message: "请选择业务层次", trigger: "change" },
+        ],
+        specList: [{ validator: checkList }],
+      },
+      isNext: false,
+      eduTypeOptions: [],
+      newCourTypeOptions: [],
+      tableData: [],
+    };
+  },
+  methods: {
+    changeEduType() {
+      this.$api
+        .inquirebusinessList({
+          status: 1,
+          educationId: this.ruleForm.educationTypeId,
+        })
+        .then((res) => {
+          this.newCourTypeOptions = res.rows;
+        });
+    },
+    resetFrom() {
+      this.ruleForm = {
+        educationTypeId: undefined,
+        businessId: undefined,
+        specTemplateId: "",
+        name: "",
+        specList: [],
+      };
+      this.addSpec();
+    },
+    addSpec() {
+      if (this.ruleForm.specList.length == 2) {
+        return this.$message({
+          message: "最多添加两个商品规格",
+          type: "warning",
+        });
+      }
+      this.ruleForm.specList.push({
+        name: "",
+        specAttrList: [{ name: "", sort: undefined }],
+      });
+    },
+    submitForm() {
+      this.checkSpecBox() &&
+        changeSpec(this.ruleForm, true).then((res) => {
+          this.isNext = true;
+          res.data.map((ele) => {
+            ele.attrListVos.map((e, i) => {
+              ele["value" + i] = e.value;
+            });
+          });
+          this.tableData = res.data;
+        });
+    },
+    checkSpecBox() {
+      let boxs = [this, ...this.$refs.specBox];
+      let result = true;
+      for (const box of boxs) {
+        box.$refs["ruleForm"].validate((valid) => {
+          if (!valid) result = false;
+        });
+      }
+      return result;
+    },
+    getSpecDetail() {
+      getSpecDetail(this.$route.query.id).then((res) => {
+        Object.keys(this.ruleForm).map((e) => {
+          this.ruleForm[e] = res.data[e];
+        });
+        this.changeEduType();
+      });
+    },
+    init() {
+      this.resetFrom();
+      this.getSpecDetail();
+      this.$api.inquireCourseEducationType({ status: 1 }).then((res) => {
+        this.eduTypeOptions = res.rows;
+      });
+    },
+    back() {
+      this.$router.go(-1);
+    },
+  },
+  computed: {},
+  created() {
+    this.init();
+  },
+  components: {
+    SpecBox,
+    ConfigTable,
+  },
+};
 </script>
 
-<style>
+<style  lang="scss" scoped>
+#specAdd {
+  padding-top: 30px;
+  .spec-title {
+    padding-left: 20px;
+    height: 20px;
+    color: #999;
+  }
+  .el-form {
+    /deep/ {
+      .eee {
+        .el-form-item__content {
+          margin-top: 10px;
+          background: #eee;
+          min-height: 60px;
+        }
+      }
+    }
+  }
+}
 </style>