<template>
  <el-form :model="form" ref="form" :rules="rules" label-width="160px" :disabled="$route.query.type == 'show'">
    <el-form-item label="图片" prop="cover">
      <imageUpload v-model="form.cover" :limit="1" v-if="$route.query.type != 'show'" :isShowTip="$route.query.type != 'show'"/>
      <imagePreview v-if="form.cover && $route.query.type == 'show'" :src="form.cover" width="100px" height="100px" />
    </el-form-item>
    <el-form-item label="商品编码" prop="code">
      <el-input
        v-model="form.code"
        placeholder="请输入商品编码"
        style="width: 400px"
      ></el-input>
    </el-form-item>
    <el-form-item label="成本价价格" prop="costPrice">
      <el-input-number
        v-model="form.costPrice"
        placeholder="请输入成本价价格"
        controls-position="right"
        :precision="2"
        :min="0"
        style="width: 400px"
      ></el-input-number>
    </el-form-item>
    <el-form-item label="市场价格" prop="marketPrice">
      <el-input-number
        v-model="form.marketPrice"
        placeholder="请输入市场价格"
        controls-position="right"
        :precision="2"
        :min="0"
        style="width: 400px"
      ></el-input-number>
    </el-form-item>

    <el-form-item label="销售价格" prop="salePrice">
      <el-input-number
        v-model="form.salePrice"
        placeholder="请输入销售价格"
        controls-position="right"
        :precision="2"
        :min="0"
        style="width: 400px"
      ></el-input-number>
    </el-form-item>
    <el-form-item label="兑换积分" prop="exchangePoint" v-if="productPaymentMode == '1'">
      <el-input-number
        v-model="form.exchangePoint"
        placeholder="请输入兑换积分"
        controls-position="right"
        :precision="0"
        :min="0"
        style="width: 400px"
      ></el-input-number>
    </el-form-item>

    <el-form-item label="重量(KG)" prop="weight">
      <el-input-number
        v-model="form.weight"
        placeholder="请输入重量"
        controls-position="right"
        :min="0"
        style="width: 400px"
      ></el-input-number>
    </el-form-item>

    <el-form-item label="体积(M3)" prop="volume">
      <el-input-number
        v-model="form.volume"
        placeholder="请输入体积"
        controls-position="right"
        :min="0"
        style="width: 400px"
      ></el-input-number>
    </el-form-item>

    <el-form-item label="库存" prop="stock">
      <el-input-number
        v-model="form.stock"
        controls-position="right"
        :precision="0"
        :min="0"
        placeholder="请输入库存"
        style="width: 400px"
      ></el-input-number>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  props: {
    productPaymentMode: {
      type: [String, Number],
      default: "0"
    }
  },
  data() {
    return {
      form: {},
      rules: {
        marketPrice: [
          { required: true, message: "请输入市场价格", trigger: "blur" },
        ],
        salePrice: [
          { required: true, message: "请输入销售价格", trigger: "blur" },
        ],
        exchangePoint: [
          { required: true, message: "请输入兑换积分", trigger: "blur" },
        ],
        weight: [{ required: true, message: "请输入重量", trigger: "blur" }],
        volume: [{ required: true, message: "请输入体积", trigger: "blur" }],
        stock: [{ required: true, message: "请输入库存", trigger: "blur" }],
        costPrice: [
          { required: true, message: "请输入成本价价格", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    setEditData(form) {
      this.form = { ...form };
    },
    validate() {
      return new Promise((resolve) => {
        this.$refs.form.validate((valid) => {
          if (valid) {
            resolve({
              valid: true,
              value: {
                skuTable: [],
                productSkuSetList: [this.form],
              },
            });
          }
        });
      });
    },
  },
};
</script>
<style scoped lang="scss"></style>
