<template>
  <!-- 表单渲染 -->
  <el-dialog append-to-body :close-on-click-modal="false" :before-close="cancelView" :visible="visible" :title="title" width="860px">
    <el-form ref="formViewRef" :model="formData" :rules="rules" :status-icon="true" label-width="240px">
      <el-form-item label="位置：" class="form-cell" prop="xxx">
        <div class="cell-box">
          <el-select v-model="formData.type" placeholder="无" class="cell-select">
            <el-option v-for="item in dict.home_setting" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </div>
      </el-form-item>
      <div v-if="formData.type==='1'">
        <el-form-item label="操作名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="频道名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="链接：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="顺序：" class="form-cell" prop="operatingPeriod">
          <div class="cell-box">
            <el-input v-model.number="formData.index" type="number" placeholder="请输入数字" class="cell-input" />
          </div>
        </el-form-item>
      </div>
      <div v-if="formData.type==='2'">
        <el-form-item label="操作名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="搜索类型：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-select v-model="formData.xx" placeholder="无" class="cell-select">
              <el-option v-for="item in dict.home_setting_2" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="内容：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="顺序：" class="form-cell" prop="operatingPeriod">
          <div class="cell-box">
            <el-input v-model.number="formData.index" type="number" placeholder="请输入数字" class="cell-input" />
          </div>
        </el-form-item>
      </div>
      <div v-if="formData.type==='3'">
        <el-form-item label="操作名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="供应商ID：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="供应商名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="是否设置为钻石供应商：" class="form-cell" prop="supplierLevel">
          <div class="cell-box">
            <el-radio-group v-model="formData.xxx" size="mini">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </div>
        </el-form-item>
        <el-form-item label="是否设置为热门供应商：" class="form-cell" prop="supplierLevel">
          <div class="cell-box">
            <el-radio-group v-model="formData.xxx" size="mini">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </div>
        </el-form-item>
        <el-form-item label="顺序：" class="form-cell" prop="operatingPeriod">
          <div class="cell-box">
            <el-input v-model.number="formData.index" type="number" placeholder="请输入数字" class="cell-input" />
          </div>
        </el-form-item>
      </div>
      <div v-if="formData.type==='4'">
        <el-form-item label="操作名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="产品分类：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-select v-model="formData.xxx" placeholder="无" class="cell-select">
              <el-option v-for="item in dict.product_type" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="产品ID：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="产品运营名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="是否设置为信得过产品：" class="form-cell" prop="supplierLevel">
          <div class="cell-box">
            <el-radio-group v-model="formData.xxx" size="mini">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </div>
        </el-form-item>
        <el-form-item label="是否设置为热门产品：" class="form-cell" prop="supplierLevel">
          <div class="cell-box">
            <el-radio-group v-model="formData.xxx" size="mini">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </div>
        </el-form-item>
        <el-form-item label="顺序：" class="form-cell" prop="operatingPeriod">
          <div class="cell-box">
            <el-input v-model.number="formData.index" type="number" placeholder="请输入数字" class="cell-input" />
          </div>
        </el-form-item>
      </div>
      <div v-if="formData.type==='5'">
        <el-form-item label="操作名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="排行榜类型：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-select v-model="formData.xxx" placeholder="无" class="cell-select">
              <el-option v-for="item in dict.home_setting_5" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </div>
        </el-form-item>
        <el-form-item v-if="formData.xxx==='2'" label="供应商ID：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item v-else label="产品ID：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item v-if="formData.xxx==='2'" label="供应商名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item v-else label="产品运营名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="顺序：" class="form-cell" prop="operatingPeriod">
          <div class="cell-box">
            <el-input v-model.number="formData.index" type="number" placeholder="请输入数字" class="cell-input" />
          </div>
        </el-form-item>
      </div>
      <div v-if="formData.type==='6'">
        <el-form-item label="操作名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="合作伙伴名称名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="合作伙伴LOGO：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-upload
              ref="uploadCom"
              action="/api/bsw/product/uploadProductPic"
              name="productPic"
              list-type="picture-card"
              :headers="uploadHeaders"
              :limit="1"
              :on-exceed="handleExceed"
              :on-success="handleImported"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove"
            >
              <i class="el-icon-plus" />
            </el-upload>
            <el-dialog append-to-body :visible.sync="dialogImageVisible">
              <img width="100%" :src="dialogImageUrl">
            </el-dialog>
          </div>
        </el-form-item>
        <el-form-item label="链接：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="顺序：" class="form-cell" prop="operatingPeriod">
          <div class="cell-box">
            <el-input v-model.number="formData.index" type="number" placeholder="请输入数字" class="cell-input" />
          </div>
        </el-form-item>
      </div>
      <div v-if="formData.type==='7'">
        <el-form-item label="操作名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="链接名称：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="链接：" class="form-cell" prop="xxx">
          <div class="cell-box">
            <el-input v-model="formData.xxx" placeholder="单行输入" class="cell-input" />
          </div>
        </el-form-item>
        <el-form-item label="顺序：" class="form-cell" prop="operatingPeriod">
          <div class="cell-box">
            <el-input v-model.number="formData.index" type="number" placeholder="请输入数字" class="cell-input" />
          </div>
        </el-form-item>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: center">
      <el-button @click="cancelView">关闭</el-button>
      <el-button type="danger" @click="submitForm()">预览</el-button>
      <el-button type="primary" @click="submitForm()">保存</el-button>
      <el-button type="success" @click="submitForm()">发布</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { getToken } from '@/utils/auth'
import { HttpReq } from '@/api/common'

export default {
  dicts: ['home_setting', 'home_setting_2', 'home_setting_5', 'product_type'],
  data() {
    return {
      uploadHeaders: { 'Authorization': getToken() },
      imgSrcStart: process.env.VUE_APP_BASE_API,
      dialogImageUrl: '',
      dialogImageVisible: false,
      visible: false,
      title: '添加首页内容',
      formData: {
        type: '1',
        xxx: '',
        index: 999,
        id: null
      },
      rules: {
        enterpriseName: { required: true, message: '请填写企业名称', trigger: 'blur' },
        businessScopeIntroduction: { required: true, message: '请填写业务范围介绍', trigger: 'blur' }
      }
    }
  },
  mounted() {
    this.$nextTick(() => {

    })
  },
  methods: {
    showView() {
      this.visible = true
    },
    hideView() {
      this.$refs.formViewRef.resetFields()
      this.visible = false
    },
    cancelView() {
      this.hideView()
    },
    submitForm() {
      console.log(this.formData)
      this.$refs.formViewRef.validate((valid, obj) => {
        if (valid) {
          // HttpReq.backstageApi.addCustomer(this.formData).then((res) => {
          //   this.$notify({
          //     title: res.msg,
          //     type: 'success',
          //     duration: 2500
          //   })
          //   if (res.code === 200) {
          //     this.cancelView()
          //     this.$parent.loadData()
          //   }
          // })
        } else {
          this.$message({
            message: '表单信息有误，请核对无误后提交！',
            type: 'error'
          })
        }
      })
    },
    loadData() {

    },
    handleExceed() {
      this.$message({
        message: '超出最大上传数量限制',
        type: 'info'
      })
    },
    handleRemove(file, fileList) {
      HttpReq.backstageApi.deleteProductPic({
        productPic: file.response.productPic
      }).then((res) => {
        this.$notify({
          title: res.msg,
          type: 'success',
          duration: 2500
        })
        const arr = []
        fileList.forEach(item => {
          arr.push(item.response.productPic)
        })
        this.formData.productPic = arr.join(';')
      })
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogImageVisible = true
    },
    handleImported(response, file, fileList) {
      this.$nextTick(() => {
        const arr = this.formData.productPic ? this.formData.productPic.split(';') : []
        arr.push(response.productPic)
        this.formData.productPic = arr.join(';')
        this.$notify({
          title: '上传成功！',
          type: 'success',
          duration: 2500
        })
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.cell-box {
  min-width: 120px;
  .cell-input {
    width: 420px;
  }
  .cell-select {
    width: 220px;
  }
  >>>.el-input__inner {
    border: 1px solid rgba(100, 100, 100, 0.1);
    border-bottom: 1px solid rgba(100, 100, 100, 0.2);
    border-radius: 5px;
  }
  >>>.el-input.is-disabled .el-input__inner {
    border-radius: 0;
    border: 0;
    border-bottom: 1px solid rgba(100, 100, 100, 0.4);
    background: white;
    cursor: text;
  }
  >>>.el-input.is-disabled .el-input__icon {
    cursor: text;
  }
  >>>.el-icon-circle-check {
    color: #13ce66;
  }
  //>>>.el-icon-arrow-up:before {
  //  content: '';
  //}
}
</style>
