<template>
  <div class="subPage">
    <form class="mainForm">
      <!-- <h1 style="font-size:22px;">{{isEdit === 0 ? '新建' : '编辑'}}{{couponInfo.CouponType === 'goods' ? '饮品优惠券' : '课程优惠券'}}</h1> -->
      <ul>
        <li class="flex-h">
          <span>选择案场：<em>*</em></span>
          <div class="flex-item">
            <div style="width:50%">
              <el-select v-model="couponInfo.CaseId" placeholder="请选择" @change="caseChange" :disabled="isEdit">
                <el-option
                  v-for="item in cases"
                  :key="item.CaseId"
                  :label="item.CaseName"
                  :value="item.CaseId">
                </el-option>
              </el-select>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>券图片：<em>*</em></span>
          <div class="flex-item">
            <div>
              <el-upload
                class="avatar-uploader"
                action='string'
                :http-request="toolClass.upload"
                :show-file-list="false"
                :on-success="handleAvatarSuccess">
                <img v-if="couponInfo.Images[0].CouponImageUrl" :src="couponInfo.Images[0].CouponImageUrl" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>券名称：<em>*</em></span>
          <div class="flex-item">
            <div style="width:200px;">
              <el-input
                placeholder="请输入"
                v-model="couponInfo.CouponName"
                clearable>
              </el-input>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>券类型：<em>*</em></span>
          <div class="flex-item">
            <div style="width:50%">
              <el-select v-model="couponInfo.CouponType" placeholder="请选择" @change="couponTypeChange" :disabled="isEdit">
                <el-option
                  v-for="item in TypeList"
                  :key="item.id"
                  :label="item.value"
                  :value="item.id">
                </el-option>
              </el-select>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>券价格：<em>*</em></span>
          <div class="flex-item">
            <div style="width:200px;">
              <el-input
                :disabled="isEdit"
                placeholder="请输入"
                v-model="couponInfo.Price"
                clearable>
              </el-input>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>总张数：<em>*</em></span>
          <div class="flex-item">
            <div style="width:200px;">
              <el-input
                :disabled="isEdit"
                placeholder="请输入"
                v-model="couponInfo.TotalCount"
                clearable>
              </el-input>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>发送类型：<em>*</em></span>
          <div class="flex-item">
            <div>
              <el-radio v-model="couponInfo.SendType" label="channel" :disabled="isEdit">渠道</el-radio>
              <el-radio v-model="couponInfo.SendType" label="case" :disabled="isEdit">案场</el-radio>
              <el-radio v-model="couponInfo.SendType" label="system" :disabled="isEdit">系统</el-radio>
            </div>
          </div>
        </li>
        <li class="flex-h" v-if="couponInfo.SendType === 'channel'">
          <span>选择渠道：<em>*</em></span>
          <div class="flex-item">
            <div style="width:50%">
              <el-select v-model="couponInfo.ChannelId" placeholder="请选择" :disabled="isEdit">
                <el-option
                  v-for="item in channelList"
                  :key="item.ChannelId"
                  :label="item.ChannelName"
                  :value="item.ChannelId">
                </el-option>
              </el-select>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>目标商品：<em>*</em></span>
          <div class="flex-item">
            <div>
              <el-radio v-model="couponInfo.IsAll" :label="1" :disabled="isEdit">全部商品</el-radio>
              <el-radio v-model="couponInfo.IsAll" :label="0" :disabled="isEdit">指定商品</el-radio>
            </div>
          </div>
        </li>
        <li class="flex-h" v-if="couponInfo.IsAll === 0">
          <div class="flex-item">
            <div style="border: 1px solid #eee;">
              <el-table
                :data="couponInfo.Targets"
                stripe
                style="width: 100%">
                <el-table-column
                  prop="TargetName"
                  label="商品">
                </el-table-column>
                <el-table-column
                  prop="TargetType"
                  label="分类">
                  <template slot-scope="scope">
                    {{returnGoodsType(scope.row.TargetType)}}
                  </template>
                </el-table-column>
                <el-table-column label="操作">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="warning"
                      @click="deleteGoodsItem(scope.$index, scope.row)" :disabled="isEdit">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div style="text-align:center;padding:10px 0;">
                <el-button type="success" size="mini" @click="addGoods" :disabled="isEdit">添加商品</el-button>
              </div>
            </div>
          </div>
        </li>
        <li class="flex-h" v-if="couponInfo.CouponType === 'goods'">
          <span>券有效时间：<em>*</em></span>
          <div class="flex-item">
            <div>
              <div class="addLine flex-h" style="align-item:center;margin-bottom:20px;">
                <el-radio v-model="TimeType" :label="1" :disabled="isEdit">固定时间</el-radio>
                <el-date-picker
                  value-format="yyyy-MM-ddT00:00:00+08:00"
                  :disabled="isEdit"
                  v-model="couponInfo.StartDate"
                  :picker-options="pickerOptions"
                  type="date"
                  placeholder="选择起始日期">
                </el-date-picker>
                <span style="line-height:40px;">至</span>
                <el-date-picker
                  value-format="yyyy-MM-ddT23:59:59+08:00"
                  :disabled="isEdit"
                  v-model="couponInfo.EndDate"
                  :picker-options="pickerOptions"
                  type="date"
                  placeholder="选择截止日期">
                </el-date-picker>
              </div>
              <div class="addLine flex-h" style="align-item:center;">
                <el-radio v-model="TimeType" :label="2" :disabled="isEdit">领取后</el-radio>
                <span style="width:100px;">
                  <el-input
                    :disabled="isEdit"
                    placeholder="请输入"
                    v-model="couponInfo.ValidDays"
                    clearable>
                  </el-input>
                </span>
                <span style="line-height:40px;">天</span>
              </div>
            </div>
          </div>
        </li>
        <li class="flex-h" v-if="couponInfo.CouponType === 'course'">
          <span>券有效时间：<em>*</em></span>
          <div class="flex-item">
            <div>
              <el-date-picker
                value-format="yyyy-MM-ddT00:00:00+08:00"
                :disabled="isEdit"
                v-model="couponInfo.StartDate"
                :picker-options="pickerOptions"
                type="date"
                placeholder="选择起始日期">
              </el-date-picker>
              <span style="line-height:40px;">至</span>
              <el-date-picker
                value-format="yyyy-MM-ddT23:59:59+08:00"
                :disabled="isEdit"
                v-model="couponInfo.EndDate"
                :picker-options="pickerOptions"
                type="date"
                placeholder="选择截止日期">
              </el-date-picker>
            </div>
          </div>
        </li>
        <li class="flex-h" v-if="couponInfo.SendType !== 'case' && couponInfo.SendType !== 'system'">
          <span>视频：</span>
          <div class="flex-item">
            <div style="vertical-align: middle;">
              <a style="line-height: 40px;" v-if="videoOff" :href="couponInfo.VideoUrl" target="blank">{{couponInfo.VideoUrl}}</a>
              <el-upload
                class="avatar-uploader"
                action='string'
                :http-request="toolClass.upload"
                :show-file-list="false"
                :on-success="videoSuccess">
                <a style="line-height: 40px;padding: 0 10px;" :disabled="isEdit">{{videoOff ? '更换' : '添加'}}视频</a>
              </el-upload>
              <el-button v-if="videoOff" type="danger" @click="deleteVideo">删除视频</el-button>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>分享描述：<em>*</em></span>
          <div class="flex-item">
            <div>
              <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入"
                v-model="couponInfo.Share.CouponShareInfo">
              </el-input>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>规则描述：<em>*</em></span>
          <div class="flex-item">
            <div>
              <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入"
                v-model="couponInfo.Share.UseRule">
              </el-input>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>使用说明：<em>*</em></span>
          <div class="flex-item">
            <div>
              <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入"
                v-model="couponInfo.Share.UseInstruction">
              </el-input>
            </div>
          </div>
        </li>
        <li style="text-align:center">
          <el-button type="primary" size="mini" @click="submit">保存</el-button>
          <el-button type="danger" size="mini" @click="cancel">取消</el-button>
        </li>
      </ul>
    </form>
    <el-dialog
      title="选择指定商品"
      :visible.sync="centerDialogVisible"
      @close="postData.page=1;total=1"
      width="650px"
      center>
      <div>
        <div v-if="couponInfo.CouponType === 'goods'">
          <el-table
            ref="multipleTable1"
            :data="goodsList"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleGoodsChange">
            <el-table-column
              type="selection">
            </el-table-column>
            <el-table-column
              prop="GoodsName"
              label="商品名称">
            </el-table-column>
            <el-table-column
              prop="TypeId"
              label="类别">
            </el-table-column>
            <el-table-column
              prop="Price"
              label="价格">
            </el-table-column>
          </el-table>
          <el-pagination
            @current-change="handleCurrentChange"
            :current-page.sync="postData.page"
            :page-size="postData.pagesize"
            layout="prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
        <div v-if="couponInfo.CouponType === 'course'">
          <el-table
            ref="multipleTable2"
            :data="courseList"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleCourseChange">
            <el-table-column
              type="selection">
            </el-table-column>
            <el-table-column
              prop="CourseName"
              label="课程名称">
            </el-table-column>
            <el-table-column
              prop="BeginDate"
              label="开始时间">
            </el-table-column>
            <el-table-column
              prop="EndDate"
              label="结束时间">
            </el-table-column>
            <el-table-column
              prop="LocationName"
              label="类别">
            </el-table-column>
            <el-table-column
              prop="Price"
              label="价格">
            </el-table-column>
          </el-table>
          <el-pagination
            @current-change="handleCurrentChange"
            :current-page.sync="postData.page"
            :page-size="postData.pagesize"
            layout="prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sureAddItem">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex'
const { mapActions: mapCouponActions } = createNamespacedHelpers('coupon')
const { mapState: mapChannelState, mapActions: mapChannelActions } = createNamespacedHelpers('channel')
const { mapState: mapGoodsState, mapActions: mapGoodsActions } = createNamespacedHelpers('goods')
const { mapState: mapCourseState, mapActions: mapCourseActions } = createNamespacedHelpers('course')

export default {
  name: '',
  data () {
    return {
      courseList: [],
      goodsList: [],
      videoOff: false,
      total: 0,
      centerDialogVisible: false,
      type: this.$route.query.type || '', // goods、course
      isEdit: !!this.$route.query.id,
      ChannelList: [], // 渠道列表
      TypeList: [{ // 类型列表
        value: '商品券',
        id: 'goods'
      }, {
        value: '课程券',
        id: 'course'
      }],
      currentList: [{
        Name: 'ccc',
        Type: 'xxx'
      }], // 指定商品数据
      TimeType: 1,
      couponInfo: {
        CaseId: '',
        CouponName: '',
        CouponType: '',
        Price: '',
        TotalCount: '',
        SendType: 'system',
        IsAll: 1,
        StartDate: '',
        EndDate: '',
        ValidDays: '',
        VideoUrl: '',
        ChannelId: '',
        Images: [{
          CouponImageUrl: ''
        }],
        Share: {
          CouponShareInfo: '',
          UseRule: '',
          UseInstruction: ''
        },
        Targets: []
      },
      postData: {
        page: 1,
        pagesize: 6,
      },
      currentSelectArr: [],
    }
  },
  mounted () {
    this.$nextTick(function () {
      this.GetChannelListList({
        caseid: this.defaultCaseId,
        page: 1,
        pagesize: 10000
      }).then(() => {
        this.GetGoodTypes({ pagesize: 1000, caseid: this.$route.query.caseid }).then(() => {
          if (this.$route.query.id) {
            this.getCouponById({
              id: this.$route.query.id
            }).then((res) => {
              // console.log(JSON.stringify(res))
              if (res.coupon.CaseId !== '') {
                var aRes = res
                this.GetChannelListList({
                  caseid: res.coupon.CaseId,
                  page: 1,
                  pagesize: 10000
                }).then((res) => {
                  if (aRes.coupon.VideoUrl !== '') {
                    this.videoOff = true
                  }
                  this.couponInfo = aRes.coupon
                  if (aRes.coupon.StartDate === '0001-01-01T00:00:00Z' || aRes.coupon.StartDate === '') {
                    this.couponInfo.StartDate = ''
                    this.TimeType = 2
                  } else {
                    this.TimeType = 1
                  }
                  if (aRes.coupon.EndDate === '0001-01-01T00:00:00Z' || aRes.coupon.EndDate === '') {
                    this.couponInfo.EndDate = ''
                  }
                })
              } else {
                if (res.coupon.VideoUrl !== '') {
                  this.videoOff = true
                }
                this.couponInfo = res.coupon
                if (aRes.coupon.StartDate === '0001-01-01T00:00:00Z' || aRes.coupon.StartDate === '') {
                  this.couponInfo.StartDate = ''
                  this.TimeType = 2
                } else {
                  this.TimeType = 1
                }
                if (aRes.coupon.EndDate === '0001-01-01T00:00:00Z' || aRes.coupon.EndDate === '') {
                  this.couponInfo.EndDate = ''
                }
              }
            })
          }
        })
      })
    })
  },
  computed: {
    ...mapState({
      cases: x => x.app.cases.list,
      defaultCaseId: x => x.app.cases.default
    }),
    ...mapChannelState({
      channelList: x => x.channelList,
    }),
    ...mapGoodsState({
      // goodsList: x => x.goodsList,
      goodsTypes: x => x.goodsTypes.list,
    }),
    ...mapCourseState({
      // courseList: x => x.courseLister,
    }),
    CaseId: {
      get () {
        return this.couponInfo.caseid || this.defaultCaseId
      },
      set (val) {
        this.couponInfo.caseid = val
      }
    },
    pickerOptions () {
      var beginDate = Date.now() - 24 * 60 * 60 * 1000
      return {
        disabledDate (time) {
          return time.getTime() < beginDate
        }
      }
    },
  },
  methods: {
    ...mapGoodsActions([
      'GetGoodsList',
      'GetGoodTypes',
    ]),
    ...mapCouponActions([
      'addCoupon',
      'getCouponById',
      'editCoupon',
    ]),
    ...mapChannelActions([
      'GetChannelListList',
    ]),
    ...mapCourseActions([
      'getCourseLister',
    ]),
    returnGoodsType (val) {
      for (var n = 0; n < this.goodsTypes.length; n++) {
        if (this.goodsTypes[n].TypeId === val) {
          return this.goodsTypes[n].TypeName
        }
      }
    },
    deleteVideo () { // 删除视频
      this.couponInfo.VideoUrl = ''
      this.videoOff = false
    },
    caseChange () { // 选择案场
      this.couponInfo.ChannelId = ''
      this.GetChannelListList({
        caseid: this.couponInfo.CaseId,
        page: 1,
        pagesize: 10000
      })
    },
    sureAddItem () { // 确定添加指定商品
      var bool = true
      this.couponInfo.Targets = this.couponInfo.Targets || []
      if (this.couponInfo.CouponType === 'goods') {
        for (var n = 0; n < this.currentSelectArr.length; n++) {
          if (this.couponInfo.Targets.length) {
            bool = true
            for (var a = 0; a < this.couponInfo.Targets.length; a++) {
              if (this.currentSelectArr[n].GoodsId === this.couponInfo.Targets[a].TargetId) {
                bool = false
              }
            }
            if (bool) {
              this.couponInfo.Targets.push({
                TargetName: this.currentSelectArr[n].GoodsName,
                TargetId: this.currentSelectArr[n].GoodsId,
                TargetType: this.currentSelectArr[n].TypeId
              })
            }
          } else {
            this.couponInfo.Targets.push({
              TargetName: this.currentSelectArr[n].GoodsName,
              TargetId: this.currentSelectArr[n].GoodsId,
              TargetType: this.currentSelectArr[n].TypeId
            })
          }
        }
      } else if (this.couponInfo.CouponType === 'course') {
        for (var x = 0; x < this.currentSelectArr.length; x++) {
          if (this.couponInfo.Targets.length) {
            bool = true
            for (var y = 0; y < this.couponInfo.Targets.length; y++) {
              if (this.currentSelectArr[x].CourseId === this.couponInfo.Targets[y].TargetId) {
                bool = false
              }
            }
            if (bool) {
              this.couponInfo.Targets.push({
                TargetName: this.currentSelectArr[x].CourseName,
                TargetId: this.currentSelectArr[x].CourseId,
                TargetType: this.currentSelectArr[x].CourseType
              })
            }
          } else {
            this.couponInfo.Targets.push({
              TargetName: this.currentSelectArr[x].CourseName,
              TargetId: this.currentSelectArr[x].CourseId,
              TargetType: this.currentSelectArr[x].CourseType
            })
          }
        }
      }
      this.centerDialogVisible = false
    },
    handleGoodsChange (val) {
      this.currentSelectArr = val
    },
    handleCourseChange (val) {
      this.currentSelectArr = val
    },
    couponTypeChange () {
      this.couponInfo.Targets = []
      if (this.couponInfo.CouponType === 'course') {
        this.TimeType = 1
      }
    },
    addGoods () { // 添加指定商品
      if (this.couponInfo.CouponType === 'goods') {
        this.postData.page = 1
        this.total = 1
        this.GetGoodsList({
          ...this.postData,
          caseid: this.couponInfo.CaseId
        }).then((res) => {
          this.goodsList = []
          for (var n = 0; n < res.list.length; n++) {
            this.goodsList.push({ ...res.list[n], TypeId: this.returnGoodsType(res.list[n].TypeId) })
          }
          this.total = res.pagenum
          this.centerDialogVisible = true
        })
      } else if (this.couponInfo.CouponType === 'course') {
        this.postData.page = 1
        this.total = 1
        this.getCourseLister({
          ...this.postData,
          caseid: this.couponInfo.CaseId
        }).then((res) => {
          this.courseList = []
          for (var n = 0; n < (res.list || []).length; n++) {
            this.courseList.push({ ...res.list[n], BeginDate: this.toolClass.dateFormat(res.list[n].BeginDate), EndDate: this.toolClass.dateFormat(res.list[n].EndDate) })
          }
          this.total = res.pagenum
          this.centerDialogVisible = true
          // console.log(JSON.stringify(this.courseList))
        })
      }
    },
    checkInfo () { // 校验表单信息
      if (this.couponInfo.CaseId === '') {
        this.$message({
          type: 'error',
          message: '案场不能为空'
        })
        return false
      }
      if (this.couponInfo.Images[0].CouponImageUrl === '') {
        this.$message({
          type: 'error',
          message: '券图片不能为空'
        })
        return false
      }
      if (this.couponInfo.CouponName === '') {
        this.$message({
          type: 'error',
          message: '券名称不能为空'
        })
        return false
      }
      if (this.couponInfo.CouponType === '') {
        this.$message({
          type: 'error',
          message: '券类型不能为空'
        })
        return false
      }
      if (this.couponInfo.Price === '') {
        this.$message({
          type: 'error',
          message: '券价格不能为空'
        })
        return false
      }
      if (this.couponInfo.TotalCount === '') {
        this.$message({
          type: 'error',
          message: '总张数不能为空'
        })
        return false
      }
      if (this.couponInfo.SendType === '') {
        this.$message({
          type: 'error',
          message: '发送类型不能为空'
        })
        return false
      }
      if (this.couponInfo.SendType === 'channel' && this.couponInfo.ChannelId === '') {
        this.$message({
          type: 'error',
          message: '渠道不能为空'
        })
        return false
      }
      if (!(this.couponInfo.IsAll - 0) && !this.courseList.length && !this.goodsList.length && !this.isEdit) {
        this.$message({
          type: 'error',
          message: '目标商品不能为空'
        })
        return false
      }
      // if (this.couponInfo.SendType === 'channel' && this.couponInfo.VideoUrl === '') {
      //   this.$message({
      //     type: 'error',
      //     message: '视频不能为空'
      //   })
      //   return false
      // }
      if (this.couponInfo.CouponType === 'goods') {
        if (this.TimeType === 1 && this.couponInfo.StartDate === '') {
          this.$message({
            type: 'error',
            message: '开始时间不能为空'
          })
          return false
        } else if (this.TimeType === 1 && this.couponInfo.EndDate === '') {
          this.$message({
            type: 'error',
            message: '截止时间不能为空'
          })
          return false
        } else if (this.TimeType === 2 && this.couponInfo.ValidDays === '') {
          this.$message({
            type: 'error',
            message: '领取后天数不能为空'
          })
          return false
        }
      }
      if (this.couponInfo.Share.CouponShareInfo === '') {
        this.$message({
          type: 'error',
          message: '分享描述不能为空'
        })
        return false
      }
      if (this.couponInfo.Share.UseRule === '') {
        this.$message({
          type: 'error',
          message: '使用规则不能为空'
        })
        return false
      }
      if (this.couponInfo.Share.UseInstruction === '') {
        this.$message({
          type: 'error',
          message: '使用说明不能为空'
        })
        return false
      }
      return true
    },
    submit () { // 保存
      if (this.$route.query.id) {
        if (this.couponInfo.ValidDays) {
          this.couponInfo.StartDate = undefined
          this.couponInfo.EndDate = undefined
        }
        if (!this.checkInfo()) {
          return false
        }
        this.editCoupon({
          ...this.couponInfo,
          IsAll: this.couponInfo.IsAll - 0,
          TotalCount: this.couponInfo.TotalCount - 0,
          ValidDays: this.couponInfo.ValidDays - 0 || 0
        }).then((res) => {
          this.$message({
            type: 'success',
            message: '操作成功'
          })
          this.$router.push({ name: 'couponList' })
        })
      } else {
        if (!this.checkInfo()) {
          return false
        }
        if (this.couponInfo.ValidDays) {
          this.couponInfo.StartDate = undefined
          this.couponInfo.EndDate = undefined
        } else {
          if (this.couponInfo.StartDate === '') {
            this.$message({
              type: 'error',
              message: '开始时间不能为空'
            })
            return false
          }
          if (this.couponInfo.EndDate === '') {
            this.$message({
              type: 'error',
              message: '截止时间不能为空'
            })
            return false
          }
          if (new Date(this.couponInfo.StartDate).getTime() > new Date(this.couponInfo.EndDate).getTime()) {
            this.$message({
              type: 'error',
              message: '开始时间不能大于截止时间'
            })
            return false
          }
        }
        this.addCoupon({
          ...this.couponInfo,
          IsAll: this.couponInfo.IsAll - 0,
          TotalCount: this.couponInfo.TotalCount - 0,
          ValidDays: this.couponInfo.ValidDays - 0 || 0
        }).then((res) => {
          this.$message({
            type: 'success',
            message: '操作成功'
          })
          this.$router.push({ name: 'couponList' })
        })
      }
    },
    cancel () { // 取消
      this.$router.push({ name: 'couponList' })
    },
    deleteGoodsItem (index, row) { // 删除指定商品item
      this.couponInfo.Targets.splice(index, 1)
    },
    handleAvatarSuccess (res, file) {
      this.couponInfo.Images[0].CouponImageUrl = res.result.url
    },
    videoSuccess (res, file) {
      this.videoOff = true
      this.couponInfo.VideoUrl = res.result.url
    },
    handleCurrentChange (val) { // 跳转到分页
      this.postData.page = val
      if (this.couponInfo.CouponType === 'goods') {
        this.GetGoodsList({
          ...this.postData,
          caseid: this.couponInfo.CaseId
        }).then((res) => {
          this.goodsList = []
          for (var n = 0; n < res.list.length; n++) {
            this.goodsList.push({ ...res.list[n], TypeId: this.returnGoodsType(res.list[n].TypeId) })
          }
          this.total = res.pagenum
        })
      } else if (this.couponInfo.CouponType === 'course') {
        this.getCourseLister({
          ...this.postData,
          caseid: this.couponInfo.CaseId
        }).then((res) => {
          this.courseList = []
          for (var n = 0; n < res.list.length; n++) {
            this.courseList.push({ ...res.list[n], BeginDate: this.toolClass.dateFormat(res.list[n].BeginDate), EndDate: this.toolClass.dateFormat(res.list[n].EndDate) })
          }
          this.total = res.pagenum
        })
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.addLine {
  > * {
    margin-right: 10px;
  }
}
.mainForm > ul > li > div > div > button {
  margin-top: 0;
}
</style>
