Mr.Shi
2023-09-19 02eb974bcf9f85a4a6594540fab97007abef4291
company_admin/src/components/business/selectProduct.vue
@@ -1,36 +1,36 @@
<template>
    <GlobalWindow :title="title" :visible.sync="visible" :confirm-working="isWorking" @confirm="confirm">
      <el-form :model="form" ref="form" :rules="rules">
        <el-form-item label="商品类别" prop="categoryId">
            <el-select v-model="form.categoryId" placeholder="请选择">
                <el-option
                    v-for="item in categoryList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="商品范围" prop="type">
            <el-radio-group v-model="form.type">
                <el-radio :label="0">全部</el-radio>
                <el-radio :label="1">部分</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="加价系数" prop="rate">
          <el-input v-model="form.rate" placeholder="平台采购价*加价系数,作为参考出手价,建议输入大于1的数字" v-trim />
        </el-form-item>
      </el-form>
      <!-- 选择平台商品 -->
      <selectProductItem ref="selectProductItem" @result="result" />
    </GlobalWindow>
  </template>
  <GlobalWindow :title="title" :visible.sync="visible" :confirm-working="isWorking" @confirm="confirm">
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="商品类别" prop="categoryId">
        <el-select v-model="form.categoryId" placeholder="请选择">
          <el-option
            v-for="item in categoryList"
            :key="item.id"
            :label="item.name"
            :value="`${item.platCateId},${item.id}`">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品范围" prop="type">
        <el-radio-group v-model="form.type">
          <el-radio :label="0">全部</el-radio>
          <el-radio :label="1">部分</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="加价系数" prop="rate">
        <el-input v-model="form.rate" placeholder="平台采购价*加价系数,作为参考出手价,建议输入大于1的数字" v-trim />
      </el-form-item>
    </el-form>
    <!-- 选择平台商品 -->
    <selectProductItem ref="selectProductItem" @result="result" />
  </GlobalWindow>
</template>
    
  <script>
<script>
  import BaseOpera from '@/components/base/BaseOpera'
  import GlobalWindow from '@/components/common/GlobalWindow'
  import selectProductItem from '@/components/business/selectProductItem'
  import { baseCategoryList } from '@/api/business/category.js'
  import { list } from '@/api/business/category.js'
  import { createPlat } from '@/api/business/goods'
  export default {
@@ -48,7 +48,7 @@
        },
        // 验证规则
        rules: {
            categoryId: [
          categoryId: [
            { required: true, message: '商品类别不能为空', trigger: 'blur' }
          ],
          type: [
@@ -67,53 +67,56 @@
      })
    },
    methods: {
        result() {
          // this.$emit('success')
          this.$emit('result')
          this.visible = false
        },
        confirm() {
            this.$refs.form.validate((valid) => {
                if (!valid) return
                // 新建
                if (this.form.type == 0) {
                    this.isWorking = true
                    createPlat({
                        categoryId: this.form.categoryId,
                        rate: this.form.rate,
                        type: this.form.type
                    }).then(res => {
                        this.visible = false
                        this.$tip.apiSuccess('操作成功')
                        // this.$emit('success')
                        this.$emit('result')
                    })
                    .catch(e => {
                        this.$tip.apiFailed(e)
                    })
                    .finally(() => {
                        this.isWorking = false
                    })
                } else {
                    this.$refs.selectProductItem.open('选择平台商品', this.form)
                }
      result() {
        // this.$emit('success')
        this.$emit('result')
        this.visible = false
      },
      confirm() {
        this.$refs.form.validate((valid) => {
          if (!valid) return
          // 新建
          if (this.form.type == 0) {
            this.isWorking = true
            createPlat({
              categoryId: this.form.categoryId.split(',')[1],
              rate: this.form.rate,
              type: this.form.type
            }).then(res => {
              this.visible = false
              this.$tip.apiSuccess('操作成功')
              // this.$emit('success')
              this.$emit('result')
            })
        },
        /**
         * 打开窗口
         * @title 窗口标题
         * @target 编辑的对象
         */
        open (title, target) {
            this.title = title
            this.visible = true
            // 获取分类列表
            baseCategoryList({ type: 1 })
              .then(res => {
                this.categoryList = res
              })
        }
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isWorking = false
            })
          } else {
            this.$refs.selectProductItem.open('选择平台商品', this.form)
          }
        })
      },
      /**
       * 打开窗口
       * @title 窗口标题
       * @target 编辑的对象
       */
      open (title, target) {
        this.title = title
        this.visible = true
        this.form.categoryId = ''
        this.form.type = 0
        this.form.rate = ''
        // 获取分类列表
        list({ type: 1 })
          .then(res => {
            this.categoryList = res
          })
      }
    }
  }
  </script>
</script>