add.vue 11.3 KB
<template>
  <div class="add-wrap" v-loading="loading">
    <div class="add-container">
      <div class="title">{{ this.channelForm.channelName }}编辑</div>
      <div class="channel-content gl-form-page">
        <el-form ref="ruleForm1" :model="channelForm" label-width="154px" size="small" :rules="rules">
          <el-form-item label="频道名称:" prop="channelName">
            <el-input v-model="channelForm.channelName"   maxlength="6" show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="频道子名称:" prop="channelChildName">
            <el-input  v-model="channelForm.channelChildName"  maxlength="12" show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="频道顺序:" prop="sort">
            <!-- <el-input  v-model="channelForm.sort" show-word-limit></el-input> -->
            <format-input :intDigit="4" :precise="0"  show-word-limit  v-model="channelForm.sort"></format-input>
          </el-form-item>
          <span v-if="channelForm.channelType == 1">
            <el-form-item label="频道主题:" prop="channelStyle">
              <el-col :span="11" class="theme"></el-col>
              <el-col :span="11" class="theme dark"></el-col>
            </el-form-item>
            <el-form-item label="" prop="channelStyle">
              <el-radio-group v-model="channelForm.channelStyle" @input="changeChannelStyle">
                <el-radio :label="1"></el-radio>
                <el-radio :label="2"></el-radio>
              </el-radio-group>
              <div class="theme-label">
                <span>风格1</span>
                <span>风格2</span>
              </div>
            </el-form-item>
          </span>
          <el-form-item label="频道banner:" prop="channelImg" style="margin-top: 15px">
            <glsx-preview :picOptions="picOptions" :imageUrlArr="channelForm.channelImgArr" @change="changeChannelImg"></glsx-preview>
            <div class="el-form-item__error" v-if="channelImgFlag">请上传频道banner</div>
          </el-form-item>
          <div class="text-tip">建议尺寸:750*448</div>
          <template v-if="channelForm.channelType == 6">
            <el-form-item label="门店频道banner图:" prop="storeBannerImg" style="margin-top: 15px">
              <glsx-preview :picOptions="merchantPicOptions" :imageUrlArr="channelForm.storeBannerImgArr" @change="changeChannelImg"></glsx-preview>
              <div class="el-form-item__error" v-if="channelImgFlag">请上传门店频道banner</div>
            </el-form-item>
            <div class="text-tip">建议尺寸:750*264</div>
          </template>
        </el-form>
      </div>
    </div>
    <div class="add-container">
      <div class="title">{{ this.channelForm.channelName }}分享配置</div>
      <div class="channel-content gl-form-page">
        <el-form ref="ruleForm" :model="channelForm" label-width="154px" :rules="rules">
          <el-form-item label="频道分享预览图:" prop="publicityImg">
            <glsx-preview :picOptions="shareOptions" :imageUrlArr="channelForm.publicityImgArr" @change="changeChannelImg"></glsx-preview>
          </el-form-item>
          <div class="text-tip">建议尺寸:520*416</div>
          <el-form-item label="频道分享文案:" prop="promotion">
            <el-input type="textarea" v-model="channelForm.promotion" maxlength="100" show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="频道海报:">
            <glsx-preview :picOptions="posterOptions" :imageUrlArr="channelForm.posterImgArr" @change="changeChannelImg"></glsx-preview>
          </el-form-item>
          <div class="text-tip">建议尺寸:640*1008</div>
        </el-form>
      </div>
    </div>
    <GLFooter>
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleSave">确定</el-button>
    </GLFooter>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      id: this.$route.query.id ? this.$route.query.id : '',
      merchantChannelId: this.$route.query.merchantChannelId ? this.$route.query.merchantChannelId : '',
      channelForm: {
        posterImgArr: [],
        publicityImgArr: [],
        publicityImg: '',
        channelImg: '',
        storeBannerImg: '',
        channelChildName: '',
        sort: '',
        channelImgArr: [],
        storeBannerImgArr: []
      },
      channelImgbgArr: ['banner1', 'banner2'],
      channelOtherImgbgArr: ['membrane', 'crowd', 'activity'],
      channelImgFlag: false,
      picOptions: {
        width: '174px',
        height: '104px',
        key: 'channelImg',
        isClose: true
      },
      merchantPicOptions: {
        width: '174px',
        height: '104px',
        key: 'storeBannerImg',
        isClose: true
      },
      shareOptions: {
        width: '120px',
        height: '90px',
        key: 'publicityImg',
        isClose: true
      },
      posterOptions: {
        width: '104px',
        height: '104px',
        key: 'posterImg',
        isClose: true
      },
      rules: {
        channelName: [{ required: true, message: '请输入频道名称', trigger: 'change' }],
        channelStyle: [{ required: true, message: '请选择频道主题', trigger: 'change' }],
        publicityImg: [{ required: true, message: '请上传频道分享预览图', trigger: 'change' }],
        channelImg: [{ required: true, message: '请上传频道banner', trigger: 'change' }],
        promotion: [{ required: true, message: '请输入频道分享文案', trigger: 'blur' }],
        channelChildName: [{ required: true, message: '请输入频道子名称', trigger: 'change' }],
        sort: [{ required: true, message: '请输入频道顺序', trigger: 'change' }],
        storeBannerImg: [{ required: true,validator: (rule, value, callback) => {
                            if(this.channelForm.channelType == 6 && !this.channelForm.storeBannerImg){
                                callback(new Error('请上传门店频道banner图'))
                            }else{
                                callback()
                            }
                        }, trigger: 'change' }]
      }
    }
  },
  created() {
    if (this.id || this.merchantChannelId) this.getChannelDetail()
  },
  methods: {
    changeChannelStyle() {
      this.diffChannelStyle()
    },
    commonImg(name) {
      return `https://img02.glsx.com.cn/weapp/resource/miniprogram/glsx/discover/${name}.png`
    },
    diffChannelStyle() {
      if (this.channelForm.channelType == 1) {
        this.channelForm.channelImgArr = [this.commonImg(this.channelImgbgArr[this.channelForm.channelStyle - 1])]
        this.channelForm.channelImg = this.commonImg(this.channelImgbgArr[this.channelForm.channelStyle - 1])
      } else {
        this.channelForm.channelImgArr = [this.commonImg(this.channelOtherImgbgArr[this.channelForm.channelType - 2])]
        this.channelForm.channelImg = this.commonImg(this.channelOtherImgbgArr[this.channelForm.channelType - 2])
      }
    },
    getChannelDetail() {
      let apis = this.id ? 'getChannelDetail' : this.merchantChannelId ? 'getMerchantChannelDetail' : ''
      let params = {}
      this.id ? (params.id = this.id) : this.merchantChannelId ? (params.merchantChannelId = this.merchantChannelId) : ''
      this.$apis.channel[apis](params).then(res => {
        if (res.code == 0) {
          this.channelForm = { ...res.data, posterImgArr: [], publicityImgArr: [], channelImgArr: [], storeBannerImgArr:[] }
          this.channelForm.posterImgArr.push(res.data.posterImg) //海报
          this.channelForm.publicityImgArr.push(res.data.publicityImg) //频道分享预览图
          this.channelForm.channelImgArr.push(res.data.channelImg) //频道banner
          this.channelForm.storeBannerImgArr.push(res.data.storeBannerImg) //门店频道banner图
          if (!res.data.channelImg) this.diffChannelStyle()
        }
      })
    },
    handleCancel() {
      this.$router.go(-1)
    },
    changeChannelImg(val) {
      this[val.key + 'Flag'] = false
      this.channelForm[val.key] = val.arr[0]
      this.$refs.ruleForm.clearValidate(val.key)
    },
    handleSave() {
      this.$refs.ruleForm1.validate(valid1 =>{
        if(valid1){
          this.$refs.ruleForm.validate(valid => {
            if (!this.channelForm.channelImg) {
              this.channelImgFlag = true
              return
            }
            if (valid) {
              let params = {
                channelName: this.channelForm.channelName,
                channelChildName: this.channelForm.channelChildName,
                sort: this.channelForm.sort,
                channelType: this.channelForm.channelType,
                channelStyle: this.channelForm.channelStyle,
                channelImg: this.channelForm.channelImg,
                promotion: this.channelForm.promotion,
                publicityImg: this.channelForm.publicityImg,
                posterImg: this.channelForm.posterImg
              }
              if (this.channelForm.channelType == 6) params.storeBannerImg = this.channelForm.storeBannerImg
              if (this.channelForm.channelType == 1) params.channelStyle = this.channelForm.channelStyle
              let apis = this.id ? 'updateChannel' : this.merchantChannelId ? 'updateMerchantChannel' : ''
              this.id ? (params.id = this.id) : this.merchantChannelId ? (params.merchantChannelId = this.merchantChannelId) : ''
              this.loading = true
              this.$apis.channel[apis](params).then(res => {
                if (res.code == 0) {
                  this.loading = false
                  this.$router.go(-1)
                }

                this.$message({
                  message: res.code == '0' ? '编辑成功' : res.message,
                  type: res.code == '0' ? 'success' : 'error'
                })
              }).finally(end=>{
                this.loading = false
              })
            }
          })
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">
.add-wrap {
  .add-container {
    background: #ffffff;
    margin-bottom: 16px;
    .title {
      height: 56px;
      line-height: 56px;
      border-bottom: 1px solid #e5e5e5;
      padding-left: 20px;
      box-sizing: border-box;
      font-size: 16px;
      color: #333333;
      font-weight: 600;
    }
    .channel-content {
      padding: 32px 0;
    }
  }
  .channel-content /deep/ {
    .el-textarea__inner {
      min-height: 79px !important;
    }
    .theme {
      width: 48px;
      height: 48px;
      border-radius: 4px;
      background-color: #f24702;
      margin-right: 44px;
      margin-top: 12px;
    }
    .dark {
      background: #0a0e19;
    }
    .el-form-item__error {
      //   margin-top: 25px;
      //   margin-bottom: 10px;
    }
    .el-radio__input {
      margin-top: -160px;
      margin-left: 33px;
      color: #fff;
    }
    .el-radio__label {
      color: #fff;
    }
  }

  .theme-label {
    font-weight: 400;
    font-size: 14px;
    color: #333333;
    line-height: 20px;
    display: flex;
    justify-content: space-between;
    width: 136px;
    margin-top: -50px;
    span {
      width: 48px;
      text-align: center;
      display: inline-block;
    }
  }
  .text-tip {
    font-weight: 400;
    font-size: 14px;
    color: #999999;
    margin-left: 154px;
    margin-bottom: 32px;
    margin-top: -10px;
  }
}
</style>