wolyshaw 4 年 前
コミット
0a9d38c10a

+ 16 - 0
src/api/buildTeam.js

@@ -1297,3 +1297,19 @@ export function getSubjectGoodsAndInfo(data) {
     params: data
   })
 }
+
+export function subjectChangeAdd (data) {
+  return request({
+    url: api + '/subjectChange/add',
+    method: 'post',
+    data
+  })
+}
+
+export function subjectChangeCancel (data) {
+  return request({
+    url: api + '/subjectChange/cancel',
+    method: 'post',
+    data
+  })
+}

+ 129 - 0
src/views/teamBuild/modals/accessories.vue

@@ -0,0 +1,129 @@
+<template>
+  <div>
+    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
+    <el-checkbox-group class="options" v-if="groupOptions.length" v-model="checkeds" @change="optionChange">
+      <el-checkbox class="option" v-for="item in groupOptions" :label="item.id" :key="item.id">
+        <strong>
+          <span>{{item.name}}</span>
+          <span>{{item.price}}元</span>
+        </strong>
+        <p v-for="sub in item.subs" :key="sub">{{sub}}</p>
+      </el-checkbox>
+    </el-checkbox-group>
+    <el-checkbox-group class="options" v-else v-model="checkeds" @change="optionChange">
+      <el-checkbox class="option" v-for="item in list" :label="item.id" :key="item.id">
+        <strong>
+          <span>{{item.name}}</span>
+          <span>{{item.groupPurchasePrice > 0 ? item.groupPurchasePrice + ' 元' : '免费'}}</span>
+        </strong>
+      </el-checkbox>
+    </el-checkbox-group>
+  </div>
+</template>
+<script>
+  export default {
+    props: ['list', 'groupList'],
+    data() {
+      return {
+        type: 'list',
+        checkAll: false,
+        checkeds: [],
+        accessoriesByid: {},
+        groupListById: {},
+        selectMoney: 0,
+        isIndeterminate: false
+      };
+    },
+    watch: {
+      checkeds(vals) {
+        const optionsById = this.type === 'list' ? this.accessoriesByid : this.groupListById
+        let selectMoney = 0
+        if (this.type === 'list') {
+          for (const item of vals) {
+            const activeItem = this.accessoriesByid[item]
+            if (activeItem) {
+              selectMoney += parseFloat(activeItem.groupPurchasePrice)
+            }
+          }
+        } else {
+          for (const item of vals) {
+            const activeItem = this.groupListById[item]
+            if (activeItem) {
+              selectMoney += parseFloat(activeItem.price)
+            }
+          }
+        }
+        this.selectMoney = selectMoney
+        this.$listeners.change(vals, selectMoney)
+      }
+    },
+    mounted() {
+      this.$nextTick(() => {
+        const accessoriesByid = {}
+        for (const item of this.list) {
+          accessoriesByid[item.id] = item
+        }
+        const groupListById = {}
+        for (const item of this.groupList) {
+          groupListById[item.id] = item
+        }
+        this.accessoriesByid = accessoriesByid
+        this.groupListById = groupListById
+      })
+    },
+    computed: {
+      groupOptions() {
+        console.log(this.groupList)
+        const options = this.groupList.map(item => ({
+          name: item.name,
+          price:item.price,
+          id: item.id,
+          subs: item.goodsList ? item.goodsList.map(sub => sub.name) : []
+        }))
+        if (options.length) {
+          this.type = 'group'
+        }
+        return options
+      }
+    },
+    methods: {
+      handleCheckAllChange(val) {
+        const options = this.type === 'list' ? this.list : this.groupOptions
+        const allids = options.map(item => item.id)
+        this.checkeds = val ? allids : [];
+        this.isIndeterminate = false;
+      },
+      optionChange(value) {
+        const options = this.type === 'list' ? this.list : this.groupOptions
+        const checkedCount = value.length;
+        this.checkAll = checkedCount === options.length;
+        this.isIndeterminate = checkedCount > 0 && checkedCount < options.length;
+      }
+    }
+  };
+</script>
+<style lang="less" scoped>
+  .options {
+    display: block;
+    .option{
+      display: flex;
+      width: 100%;
+      margin-top: 10px;
+      /deep/ .el-checkbox__label{
+        flex: 1;
+        >strong{
+          display: flex;
+          justify-content: space-between;
+          align-items: center;
+          >span:last-child{
+            color: red;
+          }
+        }
+        >p{
+          line-height: 1.8;
+          color: #606266;
+        }
+      }
+    }
+  }
+</style>

+ 165 - 196
src/views/teamBuild/modals/change-voice.vue

@@ -7,19 +7,9 @@
       <el-form-item label="原教辅" prop="name">
         <span>{{originalAccessoriesGoods}}</span>
       </el-form-item>
-      <!-- <el-form-item label="缴费时间" prop="name">
-        <el-date-picker
-          style="width: 100%"
-          v-model="form.time"
-          type="daterange"
-          range-separator="至"
-          start-placeholder="开始日期"
-          end-placeholder="结束日期">
-        </el-date-picker>
-      </el-form-item> -->
       <el-form-item label="更改声部" prop="name">
         <el-select
-          style="width: 100%"
+          style="width: 100%!important"
           v-model="form.subjectId"
           clearable
           @change="subjectChange"
@@ -34,7 +24,13 @@
         </el-select>
       </el-form-item>
       <el-form-item label="更改乐器" prop="name">
-        <el-select style="width: 100%" v-model="form.musicalGoods" clearable placeholder="请选择乐器">
+        <el-select
+          style="width: 100%!important"
+          v-model="form.musicalGoods"
+          clearable
+          @change="musicalGoodsChange"
+          placeholder="请选择乐器"
+        >
           <el-option
             v-for="item in musicalGoods"
             :key="item.id"
@@ -43,18 +39,23 @@
           </el-option>
         </el-select>
       </el-form-item>
-      <el-form-item label="更换教辅" prop="name">
-        <el-select style="width: 100%" v-model="form.accessories" clearable placeholder="请选择教辅">
+      <el-form-item v-if="activeAccessories.length || groupList.length" label="更换教辅" prop="name">
+        <accessories
+          :list.sync="activeAccessories"
+          :groupList.sync="groupList"
+          @change="accessoriesChange"
+        />
+        <!-- <el-select style="width: 100%" v-model="form.accessories" clearable placeholder="请选择教辅">
           <el-option
             v-for="item in accessories"
             :key="item.id"
             :label="item.name"
             :value="item.id">
           </el-option>
-        </el-select>
+        </el-select> -->
       </el-form-item>
       <el-form-item label="支付差价" prop="name">
-        <span style="color: red;">0元</span>
+        <span style="color: red;">{{ spread }}元</span>
       </el-form-item>
     </el-form>
     <div
@@ -68,6 +69,7 @@
       <el-button
         @click="cancel"
         type="danger"
+        v-if="detail.subjectChange"
       >取消订单</el-button>
       <el-button
         type="primary"
@@ -77,201 +79,94 @@
   </div>
 </template>
 <script>
-import { getStudentOriginal, getSubjectGoodsAndInfo } from '@/api/buildTeam'
+import { getStudentOriginal, getSubjectGoodsAndInfo, subjectChangeAdd, subjectChangeCancel } from '@/api/buildTeam'
+import accessories from './accessories'
 
-const formatCourseScheduleInfo = courseScheduleInfo => {
-  let tempCheck = {},
-    tempCourse = {}
-  if (courseScheduleInfo) {
-    for (const i in courseScheduleInfo) {
-      if (courseScheduleInfo.hasOwnProperty(i)) {
-        const item = courseScheduleInfo[i];
-        if (item.isNew === 1) {
-          item.isStatus = true
-          tempCheck[i] = {...item}
-        } else {
-          tempCourse[i] = {...item}
-        }
+const formatAllGoods = (data, kitGroupPurchaseType) => {
+
+  const accessories = []
+  const accessoriesById = {}
+  const musicalGoods = []
+  const musicalGoodsById = {}
+  const groupList = []
+  const groupListById = {}
+
+  const accessoriesByGoods = {}
+
+  if (data) {
+    const { musicGroupSubjectGoodsGroupList } = data
+
+    const types = {}
+
+    for (const item of musicGroupSubjectGoodsGroupList) {
+      if (!types[item.type]) {
+        types[item.type] = []
       }
+      types[item.type].push(item)
     }
-  }
-  return {
-    tempCheck,
-    tempCourse,
-  }
-}
 
-const setInstrumentResultAllFalse = instrumentResult => {
-  const list = [...setInstrumentResultAllFalse(instrumentResult)]
-  list.forEach(instrRes => {
-    instrRes.checked = false
-  })
-  return list
-}
-
-const formatMusicGroupSubjectGoodsGroupList = goodsGroupList => {
-  let instrumentInfo = {}
-  let instrumentResult = []
-  const accessOries = []
-  const otherResult = []
+    const typesKeys = Object.keys(types)
 
-  for (const item of goodsGroupList) {
-    if (item.type === 'INSTRUMENT') {
-      let KGPTJ = item.kitGroupPurchaseTypeJson ? JSON.parse(item.kitGroupPurchaseTypeJson) : {}
-      for (const key in KGPTJ) {
-        let tempItem = {...item}
-        tempItem.marketPrice = tempItem.goodsList[0].marketPrice
-        tempItem.kitType = key
-        tempItem.coupon = KGPTJ[key]
-        if (instrumentInfo.id) {
-          tempItem.checked = false
-          if (key === 'GROUP') {
-            if (
-              (instrumentInfo.kitType == 'GROUP' && instrumentInfo.price < tempItem.price) ||
-              instrumentInfo.kitType == 'LEASE' ||
-              instrumentInfo.kitType == 'FREE'
-            ) {
-              instrumentResult.forEach(instrRes => {
-                instrRes.checked = false
-              })
-              tempItem.checked = true
-              instrumentInfo = {
-                id: tempItem.id,
-                price: tempItem.price,
-                kitType: key
-              }
-            }
-          } else if(key == 'LEASE') {
-            if(instrumentInfo.kitType == 'LEASE' && instrumentInfo.price < tempItem.price) {
-                instrumentResult.forEach(instrRes => {
-                  instrRes.checked = false
-                })
-                tempItem.checked = true
-                instrumentInfo = {
-                id: tempItem.id,
-                price: tempItem.price,
-                kitType: key
-              }
+    for (const key of typesKeys) {
+      for (const item of types[key]) {
+        if (key === 'INSTRUMENT') {
+          let json = {}
+          try {
+            json = JSON.parse(item.kitGroupPurchaseTypeJson)
+          } catch (error) {}
+          const _item = {
+            ...item,
+            kitGroupPurchaseTypePrice: json[kitGroupPurchaseType]
+          }
+          musicalGoods.push(_item)
+          musicalGoodsById[item.id] = _item
+          if (!types.ACCESSORIES) {
+            if (!accessoriesByGoods[item.id]) {
+              accessoriesByGoods[item.id] = []
             }
-          } else if(key == 'FREE') {
-              if(instrumentInfo.kitType == 'FREE' && instrumentInfo.price < tempItem.price) {
-              instrumentResult.forEach(instrRes => {
-                instrRes.checked = false
-              })
-              tempItem.checked = true
-              instrumentInfo = {
-                id: tempItem.id,
-                price: tempItem.price,
-                kitType: key
-              }
+            const acs = item.goodsList[0].goodsList ? item.goodsList[0].goodsList : []
+            for (const goods of acs) {
+              accessoriesByGoods[item.id].push(goods)
+              accessoriesById[goods.id] = goods
             }
           }
-        } else {
-          tempItem.checked = true
-          instrumentInfo = {
-            id: tempItem.id,
-            price: tempItem.price,
-            kitType: key
-          }
+        } else if (item.type === 'ACCESSORIES') {
+          groupList.push(item)
+          groupListById[item.id] = item
         }
-        instrumentResult.push(tempItem)
-        let goodsList = item.goodsList[0].goodsList ? item.goodsList[0].goodsList : []
-        const accessGoods = []
-        goodsList.forEach(i => {
-          i.checked = true
-          accessGoods.push(i)
-        })
-      }
-    } else if(item.type === 'ACCESSORIES') {
-      item.checked = true
-      accessOries.push(item)
-    } else if(item.type === 'OTHER') {
-      otherResult.push(item)
-    }
-  }
-  if(instrumentResult.length > 0) {
-    instrumentResult.push({
-      id: -1,
-      kitType: 'owned',
-      name: '自备',
-      price: 0,
-      marketPrice: 0,
-      checked: false
-    })
-  }
-
-  return {
-    instrumentInfo,
-    instrumentResult,
-    accessOries,
-    otherResult,
-  }
-
-  // if(accessOries.length > 0) { // 判断打包,有没有辅件
-    // if(tempInstrument) {
-    //   accessOries.forEach(item => {
-    //     if(tempInstrument[item.id] && tempInstrument[item.id] === 'ACCESSORIES') {
-    //       item.checked = true
-    //     } else {
-    //       item.checked = false
-    //     }
-    //   })
-    // }
-  // } else {
-    // let accessIds = querys.goodsIds ? querys.goodsIds.split(',') : null
-    // if(accessIds) {
-    //   this.accessGoods.forEach(item => {
-    //     if(accessIds.indexOf(String(item.id)) >= 0) {
-    //       item.checked = true
-    //     } else {
-    //       item.checked = false
-    //     }
-    //   })
-    // }
-  // }
-}
-
-const formatGoods = data => {
-  const { courseScheduleInfo, musicGroupSubjectGoodsGroupList, musicGroupSubjectPlan, otherGoods, studentGoods } = data
-  console.log(formatMusicGroupSubjectGoodsGroupList(musicGroupSubjectGoodsGroupList))
-}
-
-const formatAllGoods = (data, kitGroupPurchaseType) => {
-  const { musicGroupSubjectGoodsGroupList } = data
-  const accessories = []
-  const accessoriesById = {}
-  const musicalGoods = []
-  const musicalGoodsById = {}
-
-  for (const item of musicGroupSubjectGoodsGroupList) {
-    if (item.type === 'INSTRUMENT') {
-      let json = {}
-      try {
-        json = JSON.parse(item.kitGroupPurchaseTypeJson)
-      } catch (error) {}
-      const _item = {
-        ...item,
-        kitGroupPurchaseTypePrice: json[kitGroupPurchaseType]
       }
-      musicalGoods.push(item)
-      musicalGoodsById[item.id] = item
     }
   }
 
   return {
     accessories,
-    musicalGoods
+    accessoriesById,
+    musicalGoods,
+    musicalGoodsById,
+    groupList,
+    groupListById,
+    accessoriesByGoods
   }
 }
 
 export default {
   props: ['detail', 'musicGroupId', 'voiceList'],
+  components: {
+    accessories
+  },
   data() {
     return {
+      oldAllMoney: 0,
       accessories: [],
       accessoriesByid: {},
       musicalGoods: [],
       musicalGoodsById: {},
+      groupList: [],
+      groupListById: {},
+      accessoriesByGoods: {},
+      selectAccessories: [],
+      selectAccessoriesMoney: 0,
+      kitGroupPurchaseTypePrice: 0,
       form: {
         subjectId: '',
         accessories: '',
@@ -281,6 +176,11 @@ export default {
       item: {},
       originalMusicalGoods: '',
       originalAccessoriesGoods: '',
+      originalAccessoriesPrice: 0,
+      originalMusicalPrice: 0,
+      originalCourseFee: 0,
+      musicGroupSubjectPlanFee: 0,
+      musicalPrice: 0,
     }
   },
   watch: {
@@ -289,7 +189,23 @@ export default {
         this.fetchDetail()
       }
     },
-
+  },
+  computed: {
+    activeAccessories() {
+      const { musicalGoods } = this.form
+      return musicalGoods ? this.accessoriesByGoods[musicalGoods] || [] : []
+    },
+    spread() {
+      return (
+        this.musicalPrice +
+        this.selectAccessoriesMoney +
+        this.musicGroupSubjectPlanFee -
+        this.originalAccessoriesPrice -
+        this.originalMusicalPrice -
+        this.originalCourseFee -
+        this.kitGroupPurchaseTypePrice
+      )
+    }
   },
   mounted() {
     console.log(this.detail, this.voiceList)
@@ -306,25 +222,73 @@ export default {
       .then(res => {
         const { data } = res
         this.item = data
-        this.originalMusicalGoods = data.originalMusicalGoods.name
-        this.originalAccessoriesGoods = (data.originalAccessoriesGoods || []).map(item => item.name).join()
+        if (data) {
+          this.originalAccessoriesPrice = data.originalAccessoriesPrice
+          this.originalMusicalPrice = data.originalMusicalPrice
+          this.originalCourseFee = data.originalCourseFee
+          this.originalMusicalGoods = data.originalMusicalGoods.name
+          this.originalAccessoriesGoods = (data.originalAccessoriesGoods || []).map(item => item.name).join()
+        }
       })
     },
     subjectChange(id) {
+      this.$set(this.form, 'musicalGoods', '')
       getSubjectGoodsAndInfo({
         musicGroupId: this.musicGroupId,
         subjectId: id,
       })
       .then(res => {
-        const { accessories, musicalGoods, accessoriesById, musicalGoodsById } = formatAllGoods(res.data, this.item.kitGroupPurchaseType)
-        this.accessories = [...accessories]
-        this.accessoriesById = {...accessoriesById}
-        this.musicalGoods = [...musicalGoods]
-        this.musicalGoodsById = {...musicalGoodsById}
+        this.musicGroupSubjectPlanFee = res.data.musicGroupSubjectPlan.fee
+        const items = formatAllGoods(res.data, this.item.kitGroupPurchaseType)
+        for (const key in items) {
+          if (items.hasOwnProperty(key)) {
+            const item = items[key]
+            this[key] = item
+          }
+        }
       })
     },
+    musicalGoodsChange(val) {
+      const item = this.musicalGoodsById[val]
+      console.log(item)
+      this.musicalPrice = this.numFormat(item.price)
+      this.kitGroupPurchaseTypePrice = this.numFormat(item.kitGroupPurchaseTypePrice)
+    },
+    accessoriesChange(ids, money) {
+      console.log(ids, money)
+      this.selectAccessories = ids
+      this.selectAccessoriesMoney = money
+    },
+    numFormat(num) {
+      let _num = parseFloat(num)
+      if (isNaN(_num)) {
+        _num = 0
+      }
+      return Math.floor(_num * 100) / 100
+    },
     submit() {
+      subjectChangeAdd({
+        changeCourseFee: this.numFormat(this.musicGroupSubjectPlanFee),
+        changeAccessories: this.selectAccessories.join(','),
+        changeAccessoriesPrice: this.numFormat(this.selectAccessoriesMoney),
+        changeMusicalPrice: this.numFormat(this.musicalPrice - this.kitGroupPurchaseTypePrice),
+        originalCourseFee: this.originalCourseFee,
+        originalMusicalPrice: this.originalMusicalPrice,
+        originalMusical: this.item.originalMusical,
+        originalAccessories: this.item.originalAccessories,
+        originalAccessoriesPrice: this.originalAccessoriesPrice,
+        cooperationOrganId: this.item.cooperationOrganId,
+        kitGroupPurchaseType: this.item.kitGroupPurchaseType,
+        musicGroupId: this.musicGroupId,
+        studentId: this.detail.studentId,
+        changeMusical: this.form.musicalGoods,
+        originalCost: this.item.originalCost,
+      })
       this.$listeners.close()
+      this.$message({
+        type: 'success',
+        message: '提交成功!'
+      })
     },
     cancel() {
       this.$confirm('是否确认取消订单?', '提示', {
@@ -333,9 +297,14 @@ export default {
         type: 'warning'
       })
       .then(() => {
-        this.$message({
-          type: 'success',
-          message: '取消成功!'
+        subjectChangeCancel({
+          id: this.item.id
+        })
+        .then(() => {
+          this.$message({
+            type: 'success',
+            message: '取消成功!'
+          })
         })
       })
     }

+ 3 - 4
src/views/teamBuild/signupList.vue

@@ -517,7 +517,7 @@
       <changeVoice
         @close="closeChangeVoice"
         @submited="closeChangeVoice"
-        :detail="rowDetail"
+        :detail.sync="rowDetail"
         :musicGroupId="id"
         :voiceList="leftList"
       />
@@ -1099,19 +1099,18 @@ export default {
       // row.typeVisible = false;
     },
     addVisit (row) {
-      console.log(row)
       this.visitForm.studentName = row.studentName;
       this.visitForm.musicGroupId = this.teamid
       this.visitForm.studentId = row.studentId
       this.visitVisiable = true;
     },
     openChangeVoice(row) {
+      this.rowDetail = {...row}
       this.changeVoiceVisible = true
-      this.rowDetail = row
     },
     closeChangeVoice() {
       this.changeVoiceVisible = false
-      this.rowDetail = null
+      // this.rowDetail = null
     },
     handleChange (val) {
       this.visitForm.type = val[0]