<template>
  <div class="add-good-con">
    <Card v-if="loading" class="loading-card">
      <Spin fix size="large" />
    </Card>
    <Card v-else>
      <div class="head">
        <Icon type="md-bookmark" color="#2d8cf0" :size="28" />
        <label>{{ title }}</label>
      </div>
      <base-info :data="form.baseInfo"  :isDraft="isDraft" :isDetail="isDetail" :isEdit="isEdit" :isAgain="isAgain"/>
      <sale-info
        :data="form.saleInfo"
        :isDetail="isDetail"
        :isEdit="isEdit"
        :isAgain="isAgain"
        :isSelf="isSelf"
        :isDraft="isDraft"
        :shopStatus="status"
        :availableNumber="availableNumber"
        v-if="form.baseInfo.type!=6 && form.baseInfo.type!=5"
      />
      <decipt-info :data="form.deciptInfo" :isDetail="isDetail" :isEdit="isEdit" :shopStatus="status"/>
      <info-con title="销售信息：" class="base-info-con">
      <div class="series-info" v-if="(form.baseInfo.type==1||form.baseInfo.type==3)&&form.saleInfo.commodityPass!=0">
        <label class="label">是否允许延后提货：</label>
        <i-switch v-model="form.delayDelivery" :disabled="delayDeliveryDisabled || isDetail || isEdit"/>
      </div>
      <div class="series-info">
        <label class="label">退换货类型：</label>
        <RadioGroup v-model="backType">
          <Radio label="1" :disabled="isDetail || isEdit || isDraft" class="ivu-radio">不支持</Radio>
          <Radio label="2" :disabled="isDetail || isEdit || isDraft" class="ivu-radio">七天无理由退货</Radio>
          <Radio label="3" :disabled="isDetail || isEdit || isDraft" class="ivu-radio">
            自定义
            <Input v-model="customDays" :disabled="isDetail || isEdit || isDraft" style="width: 80px" />
            无理由退款
          </Radio>

        </RadioGroup>
      </div>
      <div class="series-info">
        <label class="label">商品备注：</label>
          <Input v-model="form.note" :readonly="isDetail " type="textarea" placeholder="商品备注(非必填)" style="width: 200px" />
      </div>
      </info-con>
      <info-con title="溯源信息" class="base-info-con">
        <div class="series-info">
        <label class="label">溯源编号：</label>
        <Input v-model="form.traceabilityNumber" :readonly="isDetail" placeholder="请输入溯源系统的商品溯源编号(非必填 100位以内)" style="width: 400px" />
      </div>
      </info-con>
      <div class="submit-bottom">
        <div class="submit-con">
        <Button
          type="primary"
          @click="handleDraft"
          v-if="!isDetail"
          :loading="draftLoading"
          >存为草稿</Button
        >
      </div>
      <div class="submit-con">
        <Button
          type="primary"
          @click="handleSubmit"
          v-if="!isDetail"
          :loading="submitLoading"
          >提交商品信息</Button
        >
      </div>
      </div>

    </Card>
  </div>
</template>

<script>
import BaseInfo from './base-info'
import SaleInfo from './sale-info'
import DeciptInfo from './decpit-info'
import { getPosterFromVideoUrl } from '@/libs/tools'
import { mapMutations } from 'vuex'
import InfoCon from './info-con'
import { formatTime } from '../../../libs/ali-oss'
export default {
  name: 'add_good',
  components: {
    BaseInfo,
    SaleInfo,
    DeciptInfo,
    InfoCon
  },
  computed: {
    title () {
      if (this.routeName === 'update_good') {
        return '编辑商品 - 填写商品信息'
      } else if (this.routeName == 'good_detail') {
        return '商品详情'
        // this.isSelf // : `商品详情（ 品牌商：${this.form.brandName} ）`
      } else if (this.routeName === 'again_good') {
        return '重新发布商品 - 填写商品信息'
      } else {
        return '发布商品 - 填写商品信息'
      }
    },
    isDetail () {
      return this.routeName === 'commodity_good_detail'
    },
    isAdd () {
      return this.routeName === 'commodity_add_good'
    },
    isEdit () {
      return this.routeName === 'commodity_update_good'
    },
    isAgain () {
      return this.routeName === 'commodity_again_good'
    },
    isDraft () {
      return this.routeName === 'commodity_draft_good'
    },
    isSelf () {
      return this.form.brandId === this.$store.state.admin.brandId
    },
    status () {
      return this.form.baseInfo.type
    }
  },
  data () {
    return {
      routeName: '',
      delayDeliveryDisabled: false,
      form: {
        brandId: '',
        brandName: '',
        goodsId: '',

        // templateId: '',
        baseInfo: {
          name: '', // 商品名称
          description: '', // 商品描述
          // prop: [{ name: '', val: '' }], // 商品属性
          prop: [],
          categoryId: [], // 类目选择
          type: '1', // 商品类型
          useNft: '0',
          coinName: ''
        },
        saleInfo: {
          sku: [],
          imgObj: {},
          commodityPass: 3,
          saleStartTime: '',
          saleEndTime: '',
          drawStartTime: '',
          drawEndTime: '',
          fixedProportion: '',
          fixedAmount: '',
          depositType: '',
          price: '',
          startPrice: '',
          buyerDeposit: '',
          priceIncrease: '',
          delayPayTime: '',
          endTime: '',
          stock: '',
          salesType: 1,
          originalPrice: '',
          weight: '',
          nftSalesType: '',
          hash:'',
          purchase_limit:0
          // statu:this.status
        },
        deciptInfo: {
          video: '',
          videoList: [],
          videoThumb: '',
          thumb: '',
          thumbList: [],
          detailPictures: [],
          detailDescribe: '',
          defaultDetailPicture: [],
          defaultVideoList: [],
          defaultThumbList: []
          // statu:this.status
        },
        returnType: '', // 退货类型
        returnReason: '', // 退货理由
        note: '', // 商品备注
        stock: '', // 积分库存
        pnum: '', // 积分数量
        traceabilityNumber: '', // 溯源编号
        delayDelivery: false // 延迟提货
      },
      loading: true,
      expressList: [],
      submitLoading: false,
      draftLoading: false,
      backType: '',
      customDays: '',
      availableNumber: ''
    }
  },
  methods: {
    ...mapMutations(['closeTag']),
    requestOptionData () {
      // 获取快递模板
      this.api({
        apiName: 'templateList',
        success: (res) => {
          this.expressList = res.data
        }
      })
    },
    getDelayDelivery () {
      if (!this.isDetail) {
        this.api({
          apiName: 'merchantDelayDelivery',
          success: (res) => {
            if (res.data == 0) {
              this.delayDeliveryDisabled = true
            }
          }
        })
      }
    },
    getTemplateorshopquery () {
      if (this.isAdd) {
        this.api({
          apiName: 'templateorshopquery',
          success: (res) => {
          }
        })
      }
    },
    requestGoodDetail (id, apiName) {
      this.loading = true
      this.api({
        apiName,
        postdata: { id },
        success: (res) => {
          if (res.data) {
            let {
              brandId,
              brandName,
              // templateId,
              name,
              description,
              prop,
              skus,
              imgList,
              video,
              videoThumb,
              thumb,
              detail,
              type,
              note,
              returnType,
              traceabilityNumber,
              delayDelivery,
              returnReason,
              categoryName,
              categoryIds,
              preSaleVO,
              auctionVO,
              commodityPass,
              useNft,
              salesType,
              goodsId
            } = res.data
            this.form.goodsId = goodsId
            this.form.brandId = brandId
            this.form.brandName = brandName
            // this.form.templateId = templateId
            this.form.note = note
            // this.form.returnType = returnType.toString()
            if (returnType == 0) {
              this.backType = '1'
            } else if (returnType == 7) {
              this.backType = '2'
            } else {
              this.backType = '3'
              this.customDays = returnType
            // form.returnType = this.customDays
            }
            this.form.returnReason = returnReason
            this.form.traceabilityNumber = traceabilityNumber
            if (delayDelivery == 0) {
              this.form.delayDelivery = false
            } else {
              this.form.delayDelivery = true
            }
            if (auctionVO) {
              this.form.saleInfo.buyerDeposit = auctionVO.buyerDeposit
              this.form.saleInfo.startPrice = auctionVO.startPrice
              this.form.saleInfo.priceIncrease = auctionVO.priceIncrease
              this.form.saleInfo.delayPayTime = auctionVO.delayPayTime
              this.form.saleInfo.endTime = auctionVO.endTime ? formatTime(auctionVO.endTime) : ''
            // this.form.saleInfo.name = auctionVO.name
            }
            this.form.baseInfo = {
              name,
              description,
              coinName: skus[0].coinName,
              prop: JSON.parse(prop),
              type: type.toString(),
              categoryId: (this.isDraft || this.isAdd) ? JSON.parse(categoryIds) : categoryName,
              useNft: useNft.toString()
            }
            if(res.data.skus&&res.data.skus.length>0){
              this.skuId=res.data.skus[0].skuId
            }
            this.commodityPassId = skus[0].commodityPassId
            // console.log('1234', skus[0].coinName)
            // console.log('123', this.form.baseInfo.coinName)
            this.form.saleInfo = {
              originalPrice: skus[0].originalPrice,
              weight: skus[0].weight,
              nftSalesType: skus[0].nftSalesType,
              stock: skus[0].stock,
              hash: skus[0].hash,
              purchase_limit:0
            }
            this.availableNumber = skus[0].availableNumber
            this.form.saleInfo.commodityPass = commodityPass
            this.form.saleInfo.salesType = salesType
            this.form.deciptInfo = {
              video,
              videoList: [video],
              videoThumb,
              thumb,
              thumbList: thumb ? [thumb] : [],
              detailPictures: JSON.parse(imgList),
              detailDescribe: detail,

              defaultDetailPicture: JSON.parse(imgList),
              defaultVideoList: [video],
              defaultThumbList: thumb ? [thumb] : []
            }
            if (!video) {
              this.form.deciptInfo.video = ''
              this.form.deciptInfo.defaultVideoList = []
            }
            if (salesType == 2) {
              this.form.saleInfo.depositType = preSaleVO.depositType.toString()
              if (this.form.saleInfo.depositType == 1) {
                this.form.saleInfo.fixedProportion = preSaleVO.deposit
              } else if (this.form.saleInfo.depositType == 2) {
                this.form.saleInfo.fixedAmount = preSaleVO.deposit
              }
              // this.form.deposit = preSaleVO.deposit
              this.form.saleInfo.drawEndTime = preSaleVO.drawEndTime ? formatTime(preSaleVO.drawEndTime) : ''
              this.form.saleInfo.drawStartTime = preSaleVO.drawStartTime ? formatTime(preSaleVO.drawStartTime) : ''
              this.form.saleInfo.saleEndTime = preSaleVO.saleEndTime ? formatTime(preSaleVO.saleEndTime) : ''
              this.form.saleInfo.saleStartTime = preSaleVO.saleStartTime ? formatTime(preSaleVO.saleStartTime) : ''
            }
          }
        },
        complete: () => {
          this.loading = false
        }
      })
    },
    initData () {
      let routeName = this.$route.name
      let { goodsId, labelName, commodityPassId, availableNumber } = this.$route.query
      // console.log(this.$route)
      this.form.baseInfo.coinName = labelName
      this.commodityPassId = commodityPassId
      this.availableNumber = availableNumber
      this.form.goodsId = goodsId
      this.routeName = routeName
      if (routeName == 'commodity_update_good' || routeName == 'commodity_good_detail' || routeName == 'commodity_again_good' || routeName == 'commodity_draft_good') {
        // console.log('13567')
        this.requestGoodDetail(goodsId, 'getGoodDetail')
      } else if (routeName == 'commodity_add_good') {
        this.requestGoodDetail(commodityPassId, 'getGoodDetailforouttoken')
      } else {
        this.loading = false
      }
    },
    checkForm () {
      let errMsg = ''
      let form = {
        auctionDTO: {},
        pointsExchangeDTO: {},
        preSaleDTO: {},
        skuList: [{
          coinName: '',
          originalPrice: '',
          nftSalesType: '',
          propertyList: [{
            propKey: '',
            propVal: ''
          }],
          republish: '',
          skuId: '',
          stock: '',
          weight: '',
          skuName: '',
          commodityPassId: '',
          hash:''
        }],
        packageDTO: {}
        // nftdto: {}
      }
      let {
        goodsId,
        // templateId,
        baseInfo,
        saleInfo,
        deciptInfo,
        // returnType,
        // returnReason,
        note,
        deposit,
        pnum,
        traceabilityNumber,
        delayDelivery
      } = this.form
      form.goodsId = goodsId
      if(baseInfo.type==4){
        form.purchaseLimit=1
      }else{
        form.purchaseLimit=saleInfo.purchaseLimit
      }
      if (!baseInfo) {
        return { errMsg: '请完善基本信息！' }
      }
      if (!baseInfo.name) {
        return { errMsg: '请填写 基本信息 - 商品名称！' }
      }
      if (!baseInfo.type) {
        return { errMsg: '请填写 基本信息 - 商品类型！' }
      }
      if (!baseInfo.description) {
        return { errMsg: '请填写 基本信息 - 商品描述！' }
      }
      // if (
      //   (!baseInfo.prop ||
      //   baseInfo.prop.length === 0 ||
      //   !baseInfo.prop[0].name ||
      //   !baseInfo.prop[0].val)
      // ) {
      //   return { errMsg: '请填写 基本信息 - 商品属性！' }
      // }
      if (
        (!baseInfo.categoryId ||
        baseInfo.categoryId.length === 0)
      ) {
        return { errMsg: '请选择 基本信息 - 所属类目！' }
      }
      if (!baseInfo.useNft) {
        return { errMsg: '请填写 基本信息 - 是否应用NFT！' }
      }
      form = { ...form, ...baseInfo }
      // 销售信息

      if (!saleInfo.salesType) {
        return { errMsg: '请选择商品类型' }
      }
      form.salesType = saleInfo.salesType
      if (!saleInfo.depositType && saleInfo.salesType == 2) {
        return { errMsg: '请选择预售定金类型' }
      }
      form.preSaleDTO.depositType = saleInfo.depositType
      // 首付比例
      if (saleInfo.salesType == 2) {
        if (saleInfo.depositType == 1) {
          deposit = saleInfo.fixedProportion
        } else {
          deposit = saleInfo.fixedAmount
        }
      }
      if (!deposit && saleInfo.salesType == 2) {
        return { errMsg: '请填写首付比例' }
      }
      form.preSaleDTO.deposit = deposit
      // 预计提货开始时间
      if (!saleInfo.drawStartTime && saleInfo.salesType == 2) {
        return { errMsg: '请填写预计提货开始时间' }
      }
      form.preSaleDTO.drawStartTime = saleInfo.drawStartTime
      // 预计提货结束时间
      if (!saleInfo.drawEndTime && saleInfo.salesType == 2) {
        return { errMsg: '请填写预计提货结束时间' }
      }
      form.preSaleDTO.drawEndTime = saleInfo.drawEndTime
      // 预售开始时间
      if (!saleInfo.saleStartTime && saleInfo.salesType == 2) {
        return { errMsg: '请填写预售开始时间' }
      }
      form.preSaleDTO.saleStartTime = saleInfo.saleStartTime
      // 预售结束时间
      if (!saleInfo.saleEndTime && saleInfo.salesType == 2) {
        return { errMsg: '请填写预售结束时间' }
      }
      form.preSaleDTO.saleEndTime = saleInfo.saleEndTime
      //    买家起拍价
      if (!saleInfo.startPrice && saleInfo.salesType == 3) {
        return { errMsg: '请填写起拍价' }
      }
      // if ((saleInfo.startPrice < 0 || !/^\d+$/.test(saleInfo.startPrice)) && saleInfo.salesType == 3) {
      //   return { errMsg: '起拍价格式输入有误！' }
      // }
      if (saleInfo.startPrice < 0 && saleInfo.salesType == 3) {
        return { errMsg: '拍卖起拍价不能小于0！' }
      }
      form.auctionDTO.startPrice = saleInfo.startPrice
      // console.log('333', saleInfo.buyerDeposit)
      //    买家保证金
      if (!saleInfo.buyerDeposit && saleInfo.salesType == 3) {
        return { errMsg: '请填写拍卖保证金' }
      }
      // if ((saleInfo.buyerDeposit < 0 || !/^\d+$/.test(saleInfo.buyerDeposit)) && saleInfo.salesType == 3) {
      //   return { errMsg: '拍卖保证金格式输入有误！' }
      // }
      if (saleInfo.buyerDeposit < 0 && saleInfo.salesType == 3) {
        return { errMsg: '拍卖保证金不能小于0！' }
      }
      if (saleInfo.buyerDeposit > saleInfo.startPrice && saleInfo.salesType == 3) {
        return { errMsg: '请填写拍卖保证金不能大于起拍价' }
      }
      form.auctionDTO.buyerDeposit = saleInfo.buyerDeposit
      // 出价最小增幅
      if (!saleInfo.priceIncrease && saleInfo.salesType == 3) {
        return { errMsg: '请填写出价最小增幅' }
      }
      // if ((saleInfo.priceIncrease < 0 || !/^\d+$/.test(saleInfo.priceIncrease)) && saleInfo.salesType == 3) {
      //   return { errMsg: '出价最小增幅格式输入有误！' }
      // }
      if (saleInfo.priceIncrease < 0 && saleInfo.salesType == 3) {
        return { errMsg: '最小增幅不能小于0！' }
      }
      form.auctionDTO.priceIncrease = saleInfo.priceIncrease
      if (!saleInfo.endTime && saleInfo.salesType == 3) {
        return { errMsg: '请填写拍卖结束时间' }
      }
      form.auctionDTO.endTime = saleInfo.endTime
      if (!saleInfo.delayPayTime && saleInfo.salesType == 3) {
        return { errMsg: '请填写延后天数' }
      }
      // console.log('1111', saleInfo.delayPayTime)
      form.auctionDTO.delayPayTime = saleInfo.delayPayTime
      if (!saleInfo.originalPrice && saleInfo.salesType == 1) {
        return { errMsg: '请填写销售价格！' }
      }
      if (!saleInfo.weight && baseInfo.type != 2) {
        return { errMsg: '请填写商品重量！' }
      }
      if (!saleInfo.nftSalesType) {
        return { errMsg: '请选择NFT销售方式！' }
      }
      if (!saleInfo.stock && saleInfo.nftSalesType == 2) {
        return { errMsg: '请填写拷贝数量！' }
      }
      if (saleInfo.stock > 100000 && saleInfo.nftSalesType == 2) {
        return { errMsg: '请填写拷贝不能超过10万' }
      }
      if (!saleInfo.hash) {
        return { errMsg: '请填写溯源哈希' }
      }
      form.commodityPass = saleInfo.commodityPass
      // 图文信息
      if (!deciptInfo) {
        return { errMsg: '请完善图文描述！' }
      }
      if (!deciptInfo.detailPictures ||
        deciptInfo.detailPictures.length === 0) {
        return { errMsg: '请上传 图文描述 - 商品图片！' }
      }
      // if (!deciptInfo.videoList || deciptInfo.videoList.length === 0) {
      //   return { errMsg: '请上传 图文描述 - 商品视频！' }
      // }
      if (!deciptInfo.thumbList || deciptInfo.thumbList.length === 0) {
        return { errMsg: '请上传 图文描述 - 缩略图！' }
      }
      if (deciptInfo.detailDescribe.length > 18000) {
        return { errMsg: '图文描述 - 详情描述 内容长度过长！' }
      }
      if (deciptInfo.detailDescribe.length == 0) {
        return { errMsg: '图文描述 - 请输入详情描述！' }
      }
      // form = { ...form, ...deciptInfo }
      form.thumb = deciptInfo.thumbList[0]
      form.imgList = JSON.stringify(deciptInfo.detailPictures)
      form.detail = deciptInfo.detailDescribe
      if (deciptInfo.videoList && deciptInfo.videoList.length !== 0) {
        form.video = deciptInfo.videoList[0]
        form.videoPoster = getPosterFromVideoUrl(form.video)
      }
      // console.log('form',form)
      // 快递模板
      // if (!templateId) {
      //   return { errMsg: '请选择快递模板！' }
      // }
      // form.templateId = templateId
      // 退货类型
      if (!this.backType) {
        return { errMsg: '请选择退货类型' }
      }
      if (this.customDays == '' && this.backType == 3) {
        return { errMsg: '请自定义多少天可以退货' }
      }
      if (this.backType == 1) {
        form.returnType = 0
      } else if (this.backType == 2) {
        form.returnType = 7
      } else if (this.backType == 3) {
        if(parseInt(this.customDays)>15){
          return { errMsg: '请自定义最多15天！' }
        }
        form.returnType = this.customDays
      }
      // 商品备注
      // if (!note) {
      //   return { errMsg: '请填写商品备注' }
      // }
      form.note = note
      // 积分库存
      // if (!stock && baseInfo.type == 4) {
      //   return { errMsg: '请填写库存' }
      // }
      // form.pointsExchangeDTO.stock = stock
      // // 积分数量
      // if (!pnum && baseInfo.type == 4) {
      //   return { errMsg: '请填写积分数量' }
      // }
      form.pointsExchangeDTO.pnum = pnum
      if (traceabilityNumber.length > 100) {
        return { errMsg: '溯源系统的商品溯源编号不能大于100位' }
      }
      form.traceabilityNumber = traceabilityNumber
      form.delayDelivery = delayDelivery == true ? '1' : '0'
      return { errMsg, form }
    },
    handleSubmit () {
      let { errMsg, form } = this.checkForm()
      if (errMsg) {
        return this.$Notice.warning({ title: errMsg })
      }
      if (form.preSaleDTO.drawStartTime > form.preSaleDTO.drawEndTime) {
        return this.$Notice.warning('提货开始时间不能大于结束时间')
      }
      if (form.preSaleDTO.saleStartTime > form.preSaleDTO.saleEndTime) {
        return this.$Notice.warning('预售开始时间不能大于结束时间')
      }

      if (!errMsg) {
        form.categoryId = JSON.stringify(form.categoryId)
        // console.log('145', form.prop)
        form.prop = JSON.stringify(form.prop)
        form.type = JSON.parse(form.type)
      }
      if (!errMsg) {
        form.returnType = JSON.parse(form.returnType)
        form.preSaleDTO.drawStartTime = new Date(form.preSaleDTO.drawStartTime).getTime()
        form.preSaleDTO.drawEndTime = new Date(form.preSaleDTO.drawEndTime).getTime() + 86399000
        form.preSaleDTO.saleStartTime = new Date(form.preSaleDTO.saleStartTime).getTime()
        form.preSaleDTO.saleEndTime = new Date(form.preSaleDTO.saleEndTime).getTime() + 86399000
        form.auctionDTO.endTime = new Date(form.auctionDTO.endTime).getTime() + 86399000
      }
      if (!errMsg) {
        console.log(this.skuId)
        form.skuList.forEach(item => {
          item.originalPrice = this.form.saleInfo.originalPrice
          item.coinName = this.form.baseInfo.coinName
          item.propertyList = [{ propKey: '规格', propVal: '默认' }]
          item.image = form.thumb
          item.nftSalesType = this.form.saleInfo.nftSalesType
          item.weight = this.form.saleInfo.weight
          item.commodityPassId = this.commodityPassId
          item.skuId = this.skuId
          item.stock = item.nftSalesType == 1 ? this.availableNumber : this.form.saleInfo.stock
          item.hash = this.form.saleInfo.hash
        })
      }
      // form.detail
      var regex1 = new RegExp("(i?)(\<p)(?!(.*?style=['\"](.*)['\"])[^\>]+\>)", 'gmi')
      form.detail = form.detail.replace(regex1, '$2 style="padding:0 10px"$3')
      console.log('form', form)
      let apiName = (this.isAdd || this.isDraft) ? 'addGood' : 'updateGood'
      let title = this.isAdd ? '添加成功！' : '编辑成功！'
      this.submitLoading = true
      this.api({
        apiName,
        postdata: form,
        success: (res) => {
          // 关闭当前标签页
          let route = this.$route
          let toRouteName = 'product_list'
          this.closeTag({ route, toRouteName })
          this.$Notice.success({ title })
        },
        complete: () => {
          this.submitLoading = false
        }
      })
    },
    handleDraft () {
      let form = {
        auctionDTO: {},
        pointsExchangeDTO: {},
        preSaleDTO: {},
        skuList: [{
          coinName: '',
          originalPrice: '',
          propertyList: [{
            propKey: '',
            propVal: ''
          }],
          republish: '',
          skuId: '',
          stock: '',
          skuName: '',
          weight: ''
        }],
        packageDTO: {}
        // nftdto: {}
      }
      let {
        goodsId,
        // templateId,
        baseInfo,
        saleInfo,
        deciptInfo,
        // returnType,
        // returnReason,
        note,
        deposit,
        pnum,
        traceabilityNumber,
        delayDelivery
      } = this.form
      form.goodsId = goodsId
      if (!baseInfo.name) {
        return { errMsg: '请填写 基本信息 - 商品名称！' }
      }
      form = { ...form, ...baseInfo }
      // 销售信息
      form.salesType = saleInfo.salesType
      form.preSaleDTO.depositType = saleInfo.depositType
      // 首付比例
      if (saleInfo.salesType == 2) {
        if (saleInfo.depositType == 1) {
          deposit = saleInfo.fixedProportion
        } else {
          deposit = saleInfo.fixedAmount
        }
      }
      form.preSaleDTO.deposit = deposit
      // 预计提货开始时间
      form.preSaleDTO.drawStartTime = saleInfo.drawStartTime
      // 预计提货结束时间
      form.preSaleDTO.drawEndTime = saleInfo.drawEndTime
      // 预售开始时间
      form.preSaleDTO.saleStartTime = saleInfo.saleStartTime
      // 预售结束时间
      form.preSaleDTO.saleEndTime = saleInfo.saleEndTime
      //    买家起拍价
      form.auctionDTO.startPrice = saleInfo.startPrice
      //    买家保证金
      form.auctionDTO.buyerDeposit = saleInfo.buyerDeposit
      // 出价最小增幅
      form.auctionDTO.priceIncrease = saleInfo.priceIncrease
      form.auctionDTO.endTime = saleInfo.endTime
      // console.log('1111', saleInfo.delayPayTime)
      form.auctionDTO.delayPayTime = saleInfo.delayPayTime
      form.commodityPass = saleInfo.commodityPass
      // 图文信息
      form.thumb = deciptInfo.thumbList[0]
      form.imgList = JSON.stringify(deciptInfo.detailPictures)
      form.detail = deciptInfo.detailDescribe
      if (deciptInfo.videoList && deciptInfo.videoList.length !== 0) {
        form.video = deciptInfo.videoList[0]
        form.videoPoster = getPosterFromVideoUrl(form.video)
      }
      if (this.backType == 1) {
        form.returnType = 0
      } else if (this.backType == 2) {
        form.returnType = 7
      } else if (this.backType == 3) {
        form.returnType = this.customDays
      }
      form.note = note
      form.pointsExchangeDTO.pnum = pnum
      if (traceabilityNumber.length > 100) {
        return { errMsg: '溯源系统的商品溯源编号不能大于100位' }
      }
      form.traceabilityNumber = traceabilityNumber
      form.delayDelivery = delayDelivery == true ? '1' : '0'
      form.categoryId = JSON.stringify(form.categoryId)
      form.prop = JSON.stringify(form.prop)
      form.type = JSON.parse(form.type)
      // form.returnType = form.returnType ? JSON.parse(form.returnType) : ''
      form.preSaleDTO.drawStartTime = new Date(form.preSaleDTO.drawStartTime).getTime()
      form.preSaleDTO.drawEndTime = new Date(form.preSaleDTO.drawEndTime).getTime() + 86399000
      form.preSaleDTO.saleStartTime = new Date(form.preSaleDTO.saleStartTime).getTime()
      form.preSaleDTO.saleEndTime = new Date(form.preSaleDTO.saleEndTime).getTime() + 86399000
      form.auctionDTO.endTime = new Date(form.auctionDTO.endTime).getTime() + 86399000
      form.skuList.forEach(item => {
        item.originalPrice = this.form.saleInfo.originalPrice
        item.coinName = this.form.baseInfo.coinName
        item.propertyList = [{ propKey: '规格', propVal: '默认' }]
        item.image = form.thumb
        item.nftSalesType = this.form.saleInfo.nftSalesType
        item.weight = this.form.saleInfo.weight
        item.commodityPassId = this.commodityPassId
        item.skuId = this.skuId
        console.log(this.skuId)
        item.stock = item.nftSalesType == 1 ? this.availableNumber : this.form.saleInfo.stock
        item.hash = this.form.saleInfo.hash
      })

      this.draftLoading = true
      this.api({
        apiName: 'draftGood',
        postdata: form,
        success: (res) => {
          // 关闭当前标签页
          let route = this.$route
          let toRouteName = 'product_list'
          this.closeTag({ route, toRouteName })
          this.$Notice.success({ title: '保存成功！' })
        },
        complete: () => {
          this.draftLoading = false
        }
      })
    }

  },
  mounted () {
    this.requestOptionData()
    this.initData()
    this.getDelayDelivery()
    this.getTemplateorshopquery()
    // console.log('base', this.form.baseInfo)
  }
}
</script>

<style lang="less" scoped>
.add-good-con {
  height: 100%;
  .loading-card {
    height: 100%;
  }
  .head {
    color: #17233d;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    i {
      margin-right: 10px;
    }
  }
  .series-info {
    padding: 5px 36px;
    // border: 1px solid #dcdee2;
    // border-radius: 5px;
    margin-bottom: 10px;
    .label {
      // color: #17233d;
      font-size: 12px;
      // font-weight: bold;
    }
    .ivu-radio{
      width: 200px;
    }
    .ivu-select {
      width: 200px;
    }
  }
  .series-time{
    padding: 5px 36px;
    margin-bottom: 10px;
    display: flex;
    flex: 1;
    .label {
      padding: 5px;
      font-size: 12px;
    }
    .time{
      display: flex;
      justify-content: space-around;
    }
  }
  .submit-bottom{
    margin: 0 auto;
    width: 50%;
    display: flex;
    justify-content: space-around;
    .submit-con {
      // text-align: center;
    }
  }
  // .submit-con {
  //   text-align: center;
  // }
  .package-resources{
    padding: 5px 36px;
    margin-bottom: 10px;
    align-items: center;
    display: flex;
    .label {
      // color: #17233d;
      text-align: right;
      font-size: 12px;
      // font-weight: bold;
    }
    .property-con{
      border: 1px solid #dcdee2;
      border-radius: 5px;
      padding: 20px;
      align-items: center;
      .property-item{

        // display: flex;
        // justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        padding-right: 30px;
        .del-con {
          // float: left;
          margin-left: 5px;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
