From ef37c59e055a990ce247b265b27d3fcef430a243 Mon Sep 17 00:00:00 2001
From: 杨磊 <505174330@qq.com>
Date: 星期五, 15 八月 2025 10:19:18 +0800
Subject: [PATCH] first submit

---
 src/views/teachingServices/applyBookPaper.vue |  690 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 690 insertions(+), 0 deletions(-)

diff --git a/src/views/teachingServices/applyBookPaper.vue b/src/views/teachingServices/applyBookPaper.vue
new file mode 100644
index 0000000..5895f62
--- /dev/null
+++ b/src/views/teachingServices/applyBookPaper.vue
@@ -0,0 +1,690 @@
+<template>
+  <div class="contentBox">
+    <bookList :title="title" @getList="getBookList" />
+    <div class="classBox">
+      <div class="ruleBox" v-html="ruleText"></div>
+      <div class="classCondition">鎺堣鎯呭喌</div>
+      <div class="formBox">
+        <el-form ref="form" :model="form" :rules="rules" label-width="200px">
+          <el-form-item
+            :label="item.label"
+            :prop="item.prop"
+            v-for="(item, index) in formObj.formItem"
+            :key="index"
+          >
+            <el-input
+              v-model="form[item.prop]"
+              :placeholder="item.placeholder"
+            ></el-input>
+          </el-form-item>
+        </el-form>
+      </div>
+      <div class="classCondition">
+        <div>鏀惰揣浜轰俊鎭�</div>
+        <div class="addAddress" @click="addAddress">+ 鏂板鏀惰揣鍦板潃</div>
+      </div>
+      <div class="tableBox">
+        <el-table
+          :data="tableData"
+          style="width: 100%"
+          v-loading="loading"
+          highlight-current-row
+          @current-change="handleCurrentChange"
+          ref="singleTable"
+        >
+          <el-table-column
+            :prop="item.prop"
+            :label="item.label"
+            v-for="(item, index) in column"
+            :key="index"
+          >
+            <template slot-scope="scope">
+              <span>{{ scope.row[item.prop] }}</span>
+              <span
+                style="color: #ccc; margin-left: 40px"
+                v-if="item.prop == 'address' && scope.row.ifdefalut"
+                >榛樿鍦板潃</span
+              >
+            </template>
+          </el-table-column>
+        </el-table>
+      </div>
+      <div class="btnBox" v-loading="subloading">
+        <el-button @click="$router.go(-1)">鍙栨秷</el-button>
+        <el-button type="primary" @click="submit">鎻愪氦</el-button>
+      </div>
+    </div>
+    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="30%">
+      <el-form
+        ref="addressForm"
+        :model="editForm"
+        :rules="addressRules"
+        label-width="80px"
+      >
+        <el-form-item
+          :label="item.label"
+          :prop="item.prop"
+          v-for="(item, index) in editFormObj.formItem"
+          :key="index"
+        >
+          <el-input
+            v-if="!item.type"
+            v-model="editForm[item.prop]"
+            :placeholder="item.placeholder"
+          ></el-input>
+          <el-cascader
+            v-if="item.type"
+            size="large"
+            :options="options"
+            v-model="selectedOptions"
+            @change="handleChange"
+            style="width: 100%"
+          >
+          </el-cascader>
+        </el-form-item>
+      </el-form>
+      <span slot="footer" class="dialog-footer">
+        <el-button @click="dialogVisible = false">鍙� 娑�</el-button>
+        <el-button type="primary" @click="save" v-loading="saveloading"
+          >纭� 瀹�</el-button
+        >
+      </span>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import bookList from "@/components/detail/bookList.vue";
+import { CodeToText, TextToCode, regionData } from "element-china-area-data";
+import { mapState } from "vuex";
+
+export default {
+  components: {
+    bookList,
+  },
+  data() {
+    let checkPhone = (rule, value, callback) => {
+      let reg =
+        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
+      if (!reg.test(value)) {
+        callback(new Error("璇疯緭鍏ユ纭殑11浣嶆墜鏈哄彿"));
+      } else {
+        callback();
+      }
+    };
+
+    return {
+      ruleText: "",
+      subloading: false,
+      saveloading: false,
+      totalCount: 0,
+      selectedOptions: [],
+      options: regionData,
+      dialogTitle: "鏂板鏀惰揣浜轰俊鎭�",
+      dialogVisible: false,
+      loading: false,
+      tableData: [],
+      column: [
+        {
+          prop: "name",
+          label: "濮撳悕",
+        },
+        {
+          prop: "tel",
+          label: "鑱旂郴鐢佃瘽",
+        },
+        {
+          prop: "city",
+          label: "鍦板潃",
+        },
+        {
+          prop: "address",
+          label: "璇︾粏鍦板潃",
+        },
+      ],
+      title: "涓浗鍐滀笟澶у鍑虹増绀炬牱涔︾敵璇峰崟锛堢焊璐級",
+      editForm: {
+        name: "",
+        tel: "",
+        city: "",
+        ifdefalut: false,
+        address: "",
+      },
+      editFormObj: {
+        formItem: [
+          {
+            label: "濮撳悕",
+            prop: "name",
+            placeholder: "璇疯緭鍏ュ鍚�",
+          },
+          {
+            label: "鑱旂郴鐢佃瘽",
+            prop: "tel",
+            placeholder: "璇疯緭鍏ヨ仈绯荤數璇�",
+          },
+          {
+            type: "address",
+            label: "鍦板潃",
+            prop: "city",
+            placeholder: "璇疯緭鍏ュ湴鍧�",
+          },
+          {
+            label: "璇︾粏鍦板潃",
+            prop: "address",
+            placeholder: "璇疯緭鍏ヨ缁嗗湴鍧�",
+          },
+        ],
+      },
+      form: {},
+      formObj: {
+        formItem: [
+          {
+            label: "璇剧▼鍚嶇О锛�",
+            prop: "courseName",
+            placeholder: "璇疯緭鍏ヨ绋嬪悕绉�",
+          },
+          {
+            label: "瀛︾敓灞傛锛�",
+            prop: "studentLevel",
+            placeholder: "璇疯緭鍏ュ鐢熷眰娆�",
+          },
+          {
+            label: "瀛︾敓浜烘暟/骞达細",
+            prop: "studentsNumber",
+            placeholder: "璇疯緭鍏ュ鐢熶汉鏁�/骞�",
+          },
+          {
+            label: "鐜板湪浣跨敤鏁欐潗鎵�灞炲嚭鐗堢ぞ锛�",
+            prop: "teachingMaterialPress",
+            placeholder: "璇疯緭鍏ョ幇鍦ㄤ娇鐢ㄦ暀鏉愭墍灞炲嚭鐗堢ぞ",
+          },
+          {
+            label: "鎵�鐢ㄦ暀鏉愶細",
+            prop: "teachingMaterials",
+            placeholder: "璇疯緭鍏ユ墍鐢ㄦ暀鏉�",
+          },
+        ],
+      },
+
+      addressRules: {
+        name: [{ required: true, message: "璇疯緭鍏ュ鍚�", trigger: "blur" }],
+        tel: [
+          {
+            required: true,
+            type: "number",
+            validator: checkPhone,
+            trigger: "blur",
+          },
+        ],
+        address: [
+          { required: true, message: "璇疯緭鍏ヨ缁嗗湴鍧�", trigger: "blur" },
+        ],
+        city: [{ required: true, message: "璇烽�夋嫨鎵�鍦ㄥ煄甯�", trigger: "blur" }],
+      },
+      rules: {
+        courseName: [
+          { required: true, message: "璇疯緭鍏ヨ绋嬪悕绉�", trigger: "blur" },
+        ],
+        studentLevel: [
+          { required: true, message: "璇疯緭鍏ュ鐢熷眰娆�", trigger: "blur" },
+        ],
+        studentsNumber: [
+          { required: true, message: "璇疯緭鍏ュ鐢熶汉鏁�/骞�", trigger: "blur" },
+        ],
+        teachingMaterialPress: [
+          {
+            required: true,
+            message: "璇疯緭鍏ョ幇鍦ㄤ娇鐢ㄦ暀鏉愭墍灞炲嚭鐗堢ぞ",
+            trigger: "blur",
+          },
+        ],
+        teachingMaterials: [
+          { required: true, message: "璇疯緭鍏ユ墍鐢ㄦ暀鏉�", trigger: "blur" },
+        ],
+      },
+      workInfo: [],
+      temp_defalutAddress: false,
+      bookList: [],
+      currentAddress: null,
+    };
+  },
+  created() {
+    this.getAddress();
+    this.getTicketRes();
+    this.getType();
+    this.getTeachingSituation();
+    this.getExplainType();
+  },
+  computed: {
+    ...mapState(["userInfo"]),
+  },
+  methods: {
+    //鑾峰彇绾歌川涔﹁鏄�
+    getExplainType() {
+      const data = {
+        refCodes: ["paperSampleApplication"],
+      };
+      this.MG.resource.getCmsTypeByRefCode(data).then((res) => {
+        try {
+          this.ruleText = res[0].description;
+        } catch (e) {
+          this.ruleText = "鏆傛棤瑙勫垯";
+        }
+      });
+    },
+    //
+    getType() {
+      const data = {
+        refCodes: ["paperSampleApplication"],
+        roleId: this.userInfo.roleId,
+      };
+      this.MG.resource.getCmsTypeByRefCode(data).then((res) => {
+        this.workInfo = res[0].cmsTypeLinks[0].children;
+      });
+    },
+    getTeachingSituation() {
+      this.MG.identity
+        .getUserKey({
+          domain: "teachingSituation",
+          keys: [this.userInfo.roleId + ""],
+        })
+        .then((res) => {
+          if (res.length > 0) {
+            this.form = JSON.parse(res[0].value);
+          }
+        });
+    },
+    //鎻愪氦鏍蜂功鐢宠
+    submit() {
+      let that = this;
+      if (this.totalCount == 0) {
+        this.$message({
+          showClose: true,
+          message: "鐢宠娆℃暟宸茬敤瀹岋紒",
+          type: "error",
+        });
+        return;
+      }
+      this.$refs.form.validate((valid) => {
+        if (valid) {
+          let defalutAddress = {};
+          if (this.currentAddress) {
+            defalutAddress = this.currentAddress;
+          } else {
+            this.tableData.forEach((item, index) => {
+              if (item.ifdefalut) return (defalutAddress = item);
+            });
+          }
+          if (!defalutAddress.city) {
+            this.$message({
+              showClose: true,
+              message: "璇烽�夋嫨鍦板潃锛�",
+              type: "error",
+            });
+            return;
+          }
+          defalutAddress = { ...this.form, ...defalutAddress };
+          defalutAddress.phone = defalutAddress.tel;
+          defalutAddress.user = defalutAddress.name;
+          delete defalutAddress.tel;
+          delete defalutAddress.name;
+          defalutAddress = this.tool.worksDataBytool(
+            this.workInfo,
+            defalutAddress
+          );
+          let checkedBook = [];
+          let chenckIndex = [];
+          this.bookList.forEach((item, index) => {
+            if (item.checked) {
+              checkedBook.push(item);
+              chenckIndex.push(index);
+            }
+          });
+          if (checkedBook.length == 0) {
+            this.$message({
+              showClose: true,
+              message: "璇烽�夋嫨涔︾睄锛�",
+              type: "error",
+            });
+            return;
+          }
+          if (checkedBook.length > 3) {
+            this.$message({
+              showClose: true,
+              message: "鍗曟鐢宠涔︾睄涓嶈兘瓒呰繃涓夋湰锛�",
+              type: "error",
+            });
+            return;
+          }
+          const data = {
+            topicIdOrRefCode: "applyEntityBook",
+            name: "绾歌川鏍蜂功鐢宠",
+            content: JSON.stringify(checkedBook),
+            state: "WaitAudit",
+            type: "applyForPbook",
+            cmsTypeRefCode: "paperSampleApplication",
+            newDataListRequest: defalutAddress,
+          };
+          this.subloading = true;
+
+          this.MG.ugc.newTopicMessage(data).then((res) => {
+            console.log(this.form, "setUserKey");
+            this.MG.identity
+              .setUserKey({
+                setKeyRequests: [
+                  {
+                    domain: "teachingSituation",
+                    key: this.userInfo.roleId + "",
+                    value: JSON.stringify(this.form),
+                  },
+                ],
+              })
+              .then((res) => {
+                console.log(res);
+              });
+            this.MG.app
+              .useTicket({
+                ticketRefCodeOrGuid: "paperSampleBookapplyNum",
+                roleId: this.userInfo.roleId,
+                refType: "applyEntityBook",
+              })
+              .then((aRes) => {
+                this.subloading = false;
+
+                this.$message({
+                  message: "鐢宠鎴愬姛锛�",
+                  type: "success",
+                });
+                chenckIndex = chenckIndex.reverse();
+                chenckIndex.forEach((item) => {
+                  this.$store.commit("deletePbookList", item);
+                });
+                that.$router.push({
+                  path: "/personalCenter",
+                  query: {
+                    tabsSelected: 6,
+                  },
+                });
+              });
+          });
+        }
+      });
+    },
+
+    //閫夋嫨鍦板潃
+    handleCurrentChange(val) {
+      console.log(val);
+      this.currentAddress = val;
+    },
+
+    //璁剧疆榛樿閫変腑鍦板潃
+    setCurrent(row) {
+      this.$refs.singleTable.setCurrentRow(row);
+    },
+
+    //鑾峰彇鍓╀綑鐢宠娆℃暟
+    getTicketRes() {
+      this.MG.app
+        .getTicketResult({
+          ticketRefCodeOrGuid: "paperSampleBookapplyNum",
+          roleId: this.userInfo.roleId,
+        })
+        .then((res) => {
+          this.totalCount = res.totalCount - res.usedCount;
+        });
+    },
+
+    //鏇存敼榛樿鍦板潃
+    setAddress(row) {
+      this.tableData.forEach((item) => {
+        item.ifdefalut = false;
+      });
+      this.editForm = JSON.parse(JSON.stringify(row));
+      row.ifdefalut = true;
+      this.temp_defalutAddress = true;
+      this.save();
+    },
+
+    //缂栬緫鏀惰揣浜轰俊鎭�
+    handleClick(row) {
+      this.dialogTitle = "缂栬緫鏀惰揣浜轰俊鎭�";
+      this.dialogVisible = true;
+      this.editForm = JSON.parse(JSON.stringify(row));
+      let city = this.editForm.city.split("/");
+      if (city[0] == city[1]) {
+        city[1] = "甯傝緰鍖�";
+      }
+      this.selectedOptions.push(TextToCode[city[0]].code);
+      this.selectedOptions.push(TextToCode[city[0]][city[1]].code);
+      this.selectedOptions.push(TextToCode[city[0]][city[1]][city[2]].code);
+    },
+
+    //鏂板鏀惰揣浜轰俊鎭�
+    addAddress() {
+      this.dialogTitle = "鏂板鏀惰揣浜轰俊鎭�";
+      this.dialogVisible = true;
+      for (let k in this.editForm) {
+        if (k !== "ifdefalut") {
+          this.editForm[k] = "";
+        }
+      }
+      this.selectedOptions = [];
+    },
+
+    // 鑾峰彇鎵�鏈夊湴鍧�
+    getAddress(isAdd) {
+      this.loading = true;
+      this.MG.identity.getCurrentAppUser().then((res) => {
+        this.loading = false;
+        let storeInfoList = res.infoList.find((i) => i.type == "Address");
+        this.tableData = [];
+        if (storeInfoList && storeInfoList.data) {
+          if (!Array.isArray(JSON.parse(storeInfoList.data))) {
+            this.tableData.unshift(JSON.parse(storeInfoList.data));
+          } else {
+            this.tableData = JSON.parse(storeInfoList.data)
+              ? JSON.parse(storeInfoList.data)
+              : [];
+          }
+          this.tableData.forEach((item, index) => {
+            if (item.ifdefalut) {
+              this.setCurrent(item);
+            }
+          });
+          this.tableData = this.tableData.reverse();
+          if (isAdd) {
+            this.setCurrent(this.tableData.at(0));
+          }
+        } else {
+          // 鐢ㄦ埛涓虹涓�娆℃坊鍔犲湴鍧�锛屽垯褰撳墠鎵�閫夊湴鍧�涓洪粯璁ゅ湴鍧�
+          this.addressItem.ifdefalut = true;
+        }
+      });
+    },
+
+    //淇濆瓨鏀惰揣浜哄湴鍧�
+    save() {
+      if (this.temp_defalutAddress) {
+        this.addressSave();
+      } else {
+        this.saveloading = true;
+        this.$refs.addressForm.validate((valid) => {
+          if (valid) {
+            if (this.editForm.id) {
+              this.tableData.forEach((item, index) => {
+                if (item.id == this.editForm.id) {
+                  this.temp_index = index;
+                }
+              });
+              this.tableData[this.temp_index] = { ...this.editForm };
+            } else {
+              this.editForm.id = this.tableData.length + 1;
+              this.tableData.push(this.editForm);
+            }
+          }
+        });
+        this.addressSave();
+      }
+    },
+
+    addressSave() {
+      const userInfo = {
+        requests: [
+          {
+            data: JSON.stringify(this.tableData),
+            name: "鍦板潃绠$悊",
+            type: "Address",
+          },
+        ],
+      };
+      this.MG.identity.setAppUserInfo(userInfo).then((res) => {
+        this.loading = false;
+        if (res) {
+          this.$message({
+            showClose: true,
+            message: "鎴愬姛",
+            type: "success",
+          });
+          this.dialogVisible = false;
+          this.getAddress(true);
+        } else {
+          this.$message({
+            showClose: true,
+            message: "澶辫触锛岃绋嶅悗閲嶈瘯",
+            type: "error",
+          });
+        }
+        this.saveloading = false;
+      });
+    },
+
+    //澶勭悊绾ц仈鏁版嵁
+    handleChange(city) {
+      let cityStr =
+        CodeToText[city[0]] +
+        "/" +
+        CodeToText[city[1]] +
+        "/" +
+        CodeToText[city[2]];
+      let cityArr = cityStr.split("/");
+      if (cityArr[1] == "甯傝緰鍖�") {
+        cityArr[1] = cityArr[0];
+      }
+      this.editForm.city = cityArr.join("/");
+    },
+
+    //鑾峰彇鏍蜂功鍒楄〃
+    getBookList(val) {
+      this.bookList = [];
+      val.forEach((item) => {
+        const templateObj = {
+          id: item.id,
+          title: item.name,
+          icon: item.icon,
+          author: item.caupress_author,
+          defaultSaleMethodId: item.defaultSaleMethodId,
+          isbn: item.caupress_ISBN,
+          price: item.price,
+          checked: item.checked ? item.checked : false,
+          cmsPath: item.rootCmsItemId,
+        };
+        this.bookList.push(templateObj);
+      });
+    },
+
+    //鍒犻櫎鍦板潃
+    // 鍒犻櫎鍦板潃
+    deleteAddress(id) {
+      let that = this;
+      this.$confirm("鏄惁绉婚櫎璇ュ湴鍧�", "鎻愮ず", {
+        type: "warning",
+      })
+        .then(() => {
+          let basicInfo = "";
+          that.tableData.forEach((item) => {
+            if (item.id == id) {
+              basicInfo = item;
+            }
+          });
+          const userInfo = {
+            requests: [
+              {
+                data: JSON.stringify(basicInfo),
+                name: "鍦板潃绠$悊",
+                type: "Address",
+              },
+            ],
+          };
+          this.MG.identity.setAppUserInfo(userInfo).then((res) => {
+            if (res) {
+              this.$message({
+                type: "success",
+                message: "鍦板潃绉婚櫎鎴愬姛",
+              });
+              this.isAdd = false;
+              // 閲嶆柊鑾峰彇鏁版嵁
+              this.getAddress();
+            }
+          });
+        })
+        .catch(() => {});
+    },
+  },
+};
+</script>
+
+<style scoped>
+.classBox {
+  width: 100%;
+  height: 1000px;
+  background-color: #fff;
+  padding: 0 40px;
+  /* display: flex;
+  justify-content: center; */
+  box-sizing: border-box;
+}
+.ruleBox {
+  /* text-align: center; */
+  padding-left: 20px;
+  background-color: #f2f7f4;
+  /* width: 100%; */
+  /* height: 50px; */
+  line-height: 40px;
+  border-radius: 5px;
+  margin: 0 auto;
+}
+.classCondition {
+  display: flex;
+  justify-content: space-between;
+  margin-top: 50px;
+  font-size: 16px;
+  font-weight: 700;
+  height: 50px;
+  line-height: 50px;
+  border-bottom: 1px solid #dbdbdb;
+  color: #333;
+}
+.formBox {
+  margin-top: 30px;
+  padding: 0 100px;
+}
+.tableBox {
+  margin-top: 20px;
+  max-height: 300px;
+  overflow-y: auto;
+}
+.addAddress {
+  font-size: 14px;
+  color: #009341;
+  cursor: pointer;
+}
+.btnBox {
+  margin-top: 30px;
+  float: right;
+}
+</style>
+<style>
+.el-table tbody tr:hover > td {
+  background-color: #e7f3ec !important;
+}
+</style>

--
Gitblit v1.9.1