<template>
  <el-dialog
    v-loading="loading"
    :title="title"
    :center="true"
    align="left"
    top="8vh"
    width="1040px"
    :close-on-click-modal="false"
    :visible.sync="showModelThis"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
    @close="showModelThis = false"
    append-to-body
  >
    <el-card style="margin: -20px 0 0 0">
      <el-row :gutter="10">
        <el-col :span="24">
          <el-form
            ref="ruleForm"
            :model="ruleForm"
            status-icon
            :size="'mini'"
            :rules="rulesThis"
            label-width="90px"
            class="demo-ruleForm"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="到货日期" prop="arrival_time">
                  <el-date-picker
                    v-model="ruleForm.arrival_time"
                    type="date"
                    style="width: 100%"
                    :disabled="ruleForm.p_arrtime"
                    value-format="yyyy-MM-dd"
                    :picker-options="pickerOptions"
                    placeholder="到货日期"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="是否多地" prop="is_addrs">
                  <el-select
                    v-model="ruleForm.is_addrs"
                    placeholder="是否多地"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in is_addrs_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="预算单价" prop="budget_price">
                  <digital-input
                    :values="ruleForm.budget_price"
                    :placeholder="'预算单价'"
                    :min="0"
                    :max="100000000000"
                    :position="'right'"
                    :precision="2"
                    :size="'mini'"
                    :disabled="ruleForm.p_budget_price"
                    :controls="false"
                    :append="'元'"
                    @reschange="num_change($event, 'budget_price')"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="数量" prop="num" label-width="60px">
                  <digital-input
                    :values="ruleForm.num"
                    :placeholder="'数量'"
                    :min="0"
                    :max="100000000000"
                    :position="'right'"
                    :precision="0"
                    :size="'mini'"
                    :disabled="ruleForm.p_num"
                    :controls="false"
                    :append="''"
                    @reschange="num_change($event, 'num')"
                  />
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="品牌" prop="brand_id">
                  <search-brand
                    :value="ruleForm.brand_id"
                    :size="'mini'"
                    :isDetail="listindex !== '-1'"
                    :names="ruleForm.brand_name"
                    :placeholder="'品牌'"
                    @searchChange="brand_id_searchChange"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="是否定制" prop="is_custom">
                  <el-select
                    v-model="ruleForm.is_custom"
                    placeholder="是否定制"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in is_custom_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="6">
                <el-form-item label="重量" prop="total_weight">
                  <digital-input
                    :values="ruleForm.total_weight"
                    :placeholder="'重量'"
                    :min="0"
                    :max="100000000000"
                    :position="'right'"
                    :precision="3"
                    :controls="false"
                    :size="'mini'"
                    :append="'g'"
                    @reschange="num_change($event, 'total_weight')"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="单位" prop="unit" label-width="60px">
                  <search-unit
                    :value="ruleForm.unit"
                    :size="'mini'"
                    :isDetail="listindex !== '-1'"
                    :names="ruleForm.unit_name"
                    :placeholder="'单位'"
                    @searchChange="unitsearchChange"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="商品分类" prop="cat_id">
                  <search-sort
                    :value="ruleForm.cat_id"
                    :placeholder="'商品分类'"
                    :disabled="false"
                    :size="'mini'"
                    :names="ruleForm.cat_id_name"
                    :isDetail="listindex !== '-1'"
                    @searchChange="goods_class_change"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="商品名称" prop="good_name">
                  <el-input
                    v-model="ruleForm.good_name"
                    :disabled="false"
                    placeholder="商品名称"
                    maxlength="100"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="工艺说明" prop="cost_desc">
                  <el-input
                    v-model="ruleForm.cost_desc"
                    placeholder="工艺说明"
                    maxlength="500"
                  />
                </el-form-item>
                <el-form-item label="产品用途" prop="use_desc">
                  <el-input
                    v-model="ruleForm.use_desc"
                    placeholder="产品用途"
                    maxlength="500"
                  />
                </el-form-item>
                <el-form-item label="商品备注" prop="remark">
                  <el-input
                    v-model="ruleForm.remark"
                    placeholder="商品备注"
                    maxlength="500"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12" style="padding: 0 0 0 15px">
                <el-table
                  :data="spec_tableData"
                  :size="'mini'"
                  border
                  style="width: 100%"
                  height="120px"
                >
                  <el-table-column prop="spec_name" label="规格类型" />
                  <el-table-column prop="spec_value_name" label="规格值" />
                  <el-table-column fixed="right" width="88px">
                    <template slot="header" slot-scope="scope">
                      <span>操作</span>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="添加规格类型"
                        placement="top"
                      >
                        <i
                          class="el-icon-circle-plus-outline fr"
                          style="font-size: 18px; margin-top: 2px"
                          @click="openEdit('-1', {})"
                        />
                      </el-tooltip>
                    </template>
                    <template slot-scope="scope">
                      <el-tooltip effect="dark" content="修改" placement="top">
                        <i
                          class="el-icon-edit tb-icon"
                          @click="openEdit(scope.$index, scope.row)"
                        ></i>
                      </el-tooltip>
                      <el-tooltip effect="dark" content="删除" placement="top">
                        <i
                          class="el-icon-delete tb-icon"
                          @click="openDelete(scope.$index)"
                        ></i>
                      </el-tooltip>
                    </template>
                  </el-table-column>
                </el-table>
                <!-- 弹窗 新增/修改 -->
                <base-form-add-edit
                  :index="modelIndex"
                  :show-model="showOtherModel"
                  :sitem="modelSitem"
                  @refresh="refreshEdit"
                  @cancel="showOtherModel = false"
                />
              </el-col>
              <el-col :span="24">
                <el-row>
                  <el-col :span="12" v-if="is_noble">
                    <el-form-item label="配置要求" prop="config">
                      <el-select
                        v-model="ruleForm.config"
                        multiple
                        style="width: 100%"
                        placeholder="配置要求"
                      >
                        <el-option
                          v-for="(item, index) in config_options"
                          :key="item + index"
                          :label="item"
                          :value="item"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6" v-if="is_noble">
                    <el-form-item label="金属克重" prop="specs_weight">
                      <digital-input
                        :values="ruleForm.specs_weight"
                        :placeholder="'金属克重'"
                        :min="0"
                        :max="100000000000"
                        :position="'right'"
                        :precision="3"
                        :controls="false"
                        :size="'mini'"
                        :append="'g'"
                        @reschange="num_change($event, 'specs_weight')"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6" v-if="is_noble">
                    <el-form-item label="启用金价" prop="is_gold_price">
                      <el-select
                        v-model="ruleForm.is_gold_price"
                        placeholder="启用金价"
                        style="width: 100%"
                      >
                        <el-option
                          v-for="item in is_gold_price_options"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-col>

              <el-col :span="24" style="text-align: right">
                <el-row>
                  <el-col :span="8" class="clear">
                    <el-form-item
                      label="商品图片"
                      prop="good_img"
                      class="activity-upload"
                    >
                      <div class="btnupload" style="position: relative">
                        <img
                          v-if="ruleForm.good_img"
                          :src="ruleForm.good_img"
                          class="avatar"
                        />
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        <file-upload
                          class="Upload"
                          :disabled="false"
                          :accept="'.jpg,.png,.jpeg'"
                          :multiple="true"
                          :uploadcondition="beforeAvatarUpload"
                          @UploadErrorEvent="UploadErrorEvent"
                          @UploadSuccessEvent="UploadSuccessEvent"
                        ></file-upload>
                      </div>
                      <div class="txt-tips fl">
                        <p>小于1Mb</p>
                      </div>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" class="clear">
                    <el-form-item
                      label="附件"
                      prop="enclosure_file"
                      class="activity-upload"
                    >
                      <div v-if="ruleForm && ruleForm.enclosure_file" class="clearfix tl">
                        <a :href="ruleForm.enclosure_file" download="附件" class="fl"
                          >点击下载</a
                        >

                        <el-link
                          :underline="false"
                          @click="deleteUrl()"
                          type="warning"
                          style="margin: 0 0 0 16px"
                          class="fr"
                          >删除</el-link
                        >
                      </div>

                      <div class="activity-upload" v-else>
                        <div class="btnupload" style="position: relative">
                          <i class="el-icon-plus avatar-uploader-icon"></i>

                          <file-upload-pdf
                            class="Upload"
                            :accept="'.zip,.rar,.7z,.doc,.docx,.xlsx,.xls,.pdf'"
                            :multiple="false"
                            :uploadcondition="beforeOtherUpload"
                            @UploadErrorEvent="UploadErrorOtherenclosure_file"
                            @UploadSuccessEvent="UploadSuccessOtherenclosure_file"
                          />
                        </div>
                        <div class="txt-tips fl">
                          <p>建议大小：小于5MB</p>
                          <p>文件格式：.zip,.rar,.7z</p>
                          <p>.doc,.docx,.xlsx,.xls,.pdf</p>
                        </div>
                      </div>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" v-if="is_noble">
                    <el-form-item label="金属种类" prop="metal_id">
                      <search-metal-kind
                        :value="ruleForm.metal_id"
                        :size="'mini'"
                        :isDetail="listindex !== '-1'"
                        :placeholder="'贵金属种类'"
                        @searchChange="noble_metalsearchChange"
                      />
                    </el-form-item>
                    <el-form-item
                      v-if="ruleForm.is_gold_price === '1'"
                      label="当前金价"
                      prop="gold_price"
                      style="margin: 0 0 0 0"
                    >
                      <el-input
                        v-model="ruleForm.gold_price"
                        disabled
                        placeholder="当前金价"
                        maxlength="500"
                      >
                        <template slot="append">元</template></el-input
                      >
                    </el-form-item>
                  </el-col>
                  <el-col :span="16" v-if="is_noble">
                    <el-form-item
                      label="其他配置要求"
                      prop="other_config"
                      label-width="120px"
                    >
                      <el-input
                        v-model="ruleForm.other_config"
                        type="textarea"
                        :rows="2"
                        placeholder="其他配置要求"
                        maxlength="250"
                        show-word-limit
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" class="fr" style="padding: 18px 0 0 0">
                    <div class="lsac">
                      竞价单总额：
                      {{
                        priceAccMul(
                          ruleForm && ruleForm.budget_price ? ruleForm.budget_price : "0",
                          ruleForm && ruleForm.num ? ruleForm.num : "0"
                        )
                      }}

                      (元)
                    </div>
                    <el-button
                      v-if="id !== '007'"
                      type="primary"
                      :size="'mini'"
                      @click="submitForm"
                      >保 存
                    </el-button>
                    <el-button :size="'mini'" @click="showModelThis = false">{{
                      id == "007" ? "关 闭" : "取 消"
                    }}</el-button></el-col
                  >
                </el-row>
              </el-col>
            </el-row>
          </el-form>
        </el-col>
      </el-row>
    </el-card>
  </el-dialog>
</template>
<script>
import asyncRequest from "@/apis/service/sellOut/zixunOrder";
import resToken from "@/mixins/resToken";
import { rules } from "../columns";
import baseFormAddEdit from "./baseFormAddEdit";
import { accMul } from "@/utils/validate";
export default {
  name: "brand",
  props: ["showModel", "id", "sitem"],
  mixins: [resToken],
  components: {
    baseFormAddEdit,
  },
  data() {
    return {
      modelIndex: "",
      modelSitem: {},
      showOtherModel: false,
      spec_tableData: [],
      loading: false,
      is_noble: false,
      is_addrs_options: [
        { value: "0", label: "一地" },
        { value: "1", label: "多地" },
      ],
      is_custom_options: [
        { value: "0", label: "非定制" },
        { value: "1", label: "定制" },
      ],
      is_gold_price_options: [
        { value: "0", label: "不启用" },
        { value: "1", label: "启用" },
      ],
      config_options: ["证书", "包装盒", "绒布袋", "标签", "其他"],
      title: "添加竞价商品",
      showModelThis: this.showModel,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() <= Date.now();
        },
      },
      ruleForm: {
        p_cat_info: [],
        p_cat_id: "",
        p_budget_price: "",
        p_pgNo: "",
        p_num: "",
        p_good_type: "",
        p_good_name: "",
        p_good_img: "",
        pgNo: "",
        arrival_time: "",
        budget_price: "0.00",
        num: "0",
        brand_id: [],
        cat_id: [],
        unit: [],
        good_img: "",
        good_name: "",
        total_weight: "0.000",
        is_addrs: "",
        is_custom: "",
        is_gold_price: "",
        config: [],
        specs_weight: "0.000",
        other_config: "",
        cost_desc: "",
        use_desc: "",
        remark: "",
        metal_id: "",
        gold_price: "0",
        enclosure_file: "",
      },
      rulesThis: this.rules,
      rules: rules,
      listindex: "-1",
    };
  },
  watch: {
    showModel: function (val) {
      this.showModelThis = val;
      if (val) {
        this.initForm();
      }
    },
    showModelThis(val) {
      if (!val) {
        this.$emit("cancel");
      }
    },
  },
  methods: {
    async initForm() {
      this.loading = true;
      const { index } = this.sitem;
      this.listindex = index + "";
      if (this.listindex === "-1") {
        this.title = "添加竞价商品";
      } else {
        this.title = "修改竞价商品";
      }
      this.rulesThis = this.rules;
      await this.resetForm();
      this.loading = false;
    },
    openEdit(index, sitem) {
      this.modelIndex = index;
      this.modelSitem = sitem;
      this.showOtherModel = true;
    },
    openDelete(index) {
      this.spec_tableData.splice(index, 1);
    },
    priceAccMul(a, b) {
      return accMul(a, b);
    },
    //规格编辑修改结果
    refreshEdit(e) {
      let item = JSON.parse(JSON.stringify(e));
      const { index, id, specid, spec_name, spec_value_id, spec_value_name } = item;
      if (index + "" === "-1") {
        this.spec_tableData.push(item);
      } else {
        this.spec_tableData.forEach((i, findex) => {
          if (i.spec_id === spec_id) {
            this.spec_tableData[findex].id = id;
            this.spec_tableData[findex].specid = specid;
            this.spec_tableData[findex].spec_name = spec_name;
            this.spec_tableData[findex].spec_value_id = spec_value_id;
            this.spec_tableData[findex].spec_value_name = spec_value_name;
          }
        });
      }
      this.showOtherModel = false;
    },
    async resetForm() {
      this.spec_tableData = [];
      // 重置
      await this.$nextTick(() => {
        if (this.$refs.ruleForm) {
          this.$refs.ruleForm.resetFields();
          this.$refs.ruleForm.clearValidate();
          const { index } = this.sitem;
          let fi = index ? index + "" : "";
          const {
            pgNo,
            arrival_time,
            budget_price,
            num,
            brand_id,
            cat_id,
            good_img,
            good_name,

            total_weight,
            is_addrs,
            is_custom,
            is_gold_price,
            config,
            specs_weight,
            other_config,
            cost_desc,
            use_desc,
            remark,
            metal_id,
            gold_price,
            unit,
            unit_name,
            p_cat_info,
            p_cat_id,
            p_budget_price,
            p_pgNo,
            p_num,
            p_good_type,
            p_good_name,
            p_good_img,
            p_arrtime,
            brand_name,
            specinfo,
            cat_id_name,
            cat_arr_id,
            enclosure_file,
          } = this.sitem;
          console.log(this.sitem);
          // console.log(p_cat_info);
          let asd = [];
          if (p_cat_info && p_cat_info.length > 0) {
            p_cat_info.forEach((sd) => {
              asd.push(sd.id);
            });
          }
          if (specinfo && specinfo.length > 0) {
            this.spec_tableData = JSON.parse(JSON.stringify(specinfo));
          } else {
            this.spec_tableData = [];
          }
          this.ruleForm = {
            p_cat_info: p_cat_info,
            p_cat_id: p_cat_id,
            p_cat_arr_id: asd,
            p_budget_price: p_budget_price,
            p_pgNo: p_pgNo,
            p_num: p_num,
            p_good_type: p_good_type,
            p_good_name: p_good_name,
            p_good_img: p_good_img,
            p_arrtime: p_arrtime,

            pgNo: fi === "-1" && p_pgNo ? p_pgNo : pgNo || "",
            arrival_time: fi === "-1" && p_pgNo ? p_arrtime : arrival_time || "",
            budget_price: fi === "-1" && p_pgNo ? p_budget_price : budget_price || "0.00",
            num: fi === "-1" && p_pgNo ? p_num : num || "0",
            brand_id: brand_id ? brand_id : [],
            brand_name: brand_name ? brand_name : "",
            cat_id: cat_id ? cat_id : [],
            cat_arr_id: cat_arr_id ? cat_arr_id : [],
            cat_id_name: cat_id_name ? cat_id_name : "",
            good_img: fi === "-1" && p_pgNo ? p_good_img : good_img || "",
            good_name: fi === "-1" && p_pgNo ? p_good_name : good_name || "",
            total_weight: total_weight || "0",
            is_addrs: is_addrs || "0",
            is_custom: is_custom || "0",
            is_gold_price: is_gold_price || "0",
            config: config ? config : [],
            specs_weight: specs_weight || "0.000",
            other_config: other_config || "",
            cost_desc: cost_desc || "",
            use_desc: use_desc || "",
            remark: remark || "",
            metal_id: metal_id || "",
            gold_price: gold_price || "0",
            unit: unit ? unit : [],
            unit_name: unit_name ? unit_name : "",
            enclosure_file: enclosure_file || "",
          };
          this.is_noble = false;
          if (cat_arr_id && cat_arr_id.length > 0) {
            cat_arr_id.forEach((e) => {
              if (e === "6") {
                this.is_noble = true;
              }
            });
          }
        }
      });
    },
    //商品分类选择
    async goods_class_change(e) {
      const { code, pid, id, label, item } = e;
      this.ruleForm.cat_id = id ? [id] : [];
      this.ruleForm.cat_id_name = label ? label : "";
      this.ruleForm.cat_arr_id = item;
      this.$refs.ruleForm.validateField("cat_id");
      this.is_noble = pid === "6";
    },

    //单位选择
    unitsearchChange(e) {
      const { code, label } = e;
      this.ruleForm.unit = code ? [code] : [];
      this.ruleForm.unit_name = label ? label : "";
      this.$refs.ruleForm.validateField("unit");
    },
    //购买数量
    num_change(e, key) {
      this.ruleForm[key] = e + "";
      this.$refs.ruleForm.validateField(key);
    },
    //品牌选择
    brand_id_searchChange(e) {
      const { id, label } = e;
      this.ruleForm.brand_id = id ? [id] : [];
      this.ruleForm.brand_name = label ? label : "";
      this.$refs.ruleForm.validateField("brand_id");
    },
    //贵金属种类选择
    async noble_metalsearchChange(e) {
      const { id, price } = e;
      this.ruleForm.metal_id = id ? id : "";
      this.$refs.ruleForm.validateField("metal_id");
      console.log("change_metal_id");
      await this.get_golpricelast();
      // this.ruleForm.gold_price = price ? price : "0";
    },
    async get_golpricelast() {
      const { metal_id } = this.ruleForm;
      if (metal_id) {
        let model = {
          type: metal_id,
        };
        const { code, data, message } = await asyncRequest.golpricelast(model);
        if (code === 0) {
          data.forEach((e) => {
            if (e.type) {
              this.ruleForm.gold_price = e.price;
            }
          });
        } else if (code >= 100 && code <= 104) {
          await this.logout();
        } else {
          this.$message.warning(message);
        }
      } else {
        this.ruleForm.gold_price = "0";
      }
      this.$refs.ruleForm.validateField("gold_price");
    },
    async submitForm() {
      await this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          if (this.loading) {
            return;
          }
          this.loading = true;
          if (this.spec_tableData.length === 0) {
            this.$message.warning("请选择商品规格！");
            this.loading = false;
            return;
          }
          let model = JSON.parse(JSON.stringify(this.ruleForm));
          console.log(model.cat_arr_id);
          const { cat_arr_id } = model;
          const { total_weight, specs_weight, p_cat_info } = model;
          if (p_cat_info && p_cat_info.length > 0) {
            let length = p_cat_info.length;
            let car_name = "";
            p_cat_info.forEach((e, ei) => {
              car_name += `${ei !== 0 ? "_" : ""}${e.name}`;
            });
            let isok = true;
            for (let i = 0; i < length; i++) {
              if (p_cat_info[i].id !== cat_arr_id[i]) {
                isok = false;
              }
            }
            if (!isok) {
              this.$message.warning(
                `商品分类不符合项目商品要求，商品要求中的分类为:${car_name}！`
              );
              this.loading = false;
              return;
            }
          }
          console.log(p_cat_info);
          if (total_weight * 1000 < specs_weight * 1000 && this.is_noble) {
            this.$message.warning("商品总重量不能小于贵金属重量！");
            this.loading = false;
            return;
          }
          model.index = this.listindex;
          model.specinfo = JSON.parse(JSON.stringify(this.spec_tableData));
          this.loading = false;
          this.showModelThis = false;
          // 刷新
          this.$emit("refresh", model);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //判断图片规格
    beforeAvatarUpload(file) {
      let isJPG = false,
        isLt2M = false;
      if (file) {
        if (
          file.type === "image/jpg" ||
          file.type === "image/png" ||
          file.type === "image/jpeg"
        ) {
          isJPG = true;
        }
        isLt2M = file.size / 1024 / 1024 < 1;
        if (!isJPG) {
          this.$message.error("图片格式不正确！");
        }
        if (!isLt2M) {
          this.$message.error("图片大小不能超过 1MB!");
        }
      }

      return isJPG && isLt2M;
    },
    //图片上传失败
    UploadErrorEvent(res) {
      if (res !== "break") {
        this.$message.error("图片上传失败!");
        this.ruleForm.good_img = "";
        this.$refs.ruleForm.validateField("good_img");
      }
    },
    //图片上传成功
    async UploadSuccessEvent(data) {
      const { url } = data;
      if (url === "noToken") {
        await this.logout();
      } else {
        this.ruleForm.good_img = url;
        this.$message.success("图片上传成功!");
        this.$refs.ruleForm.validateField("good_img");
      }
    },
    //其他文件上传失败
    UploadErrorOtherenclosure_file(res) {
      if (res !== "break") {
        this.$refs.ruleForm.validateField("enclosure_file");
      }
    },

    //判断其他文件规格
    beforeOtherUpload(file) {
      console.log(file.type);
      let isJPG = false;
      if (
        file.type === "application/msword" ||
        file.type ===
          "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
        file.type === "application/vnd.ms-excel" ||
        file.type ===
          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
        file.type === "application/pdf" ||
        file.type === "application/x-zip-compressed"
      ) {
        isJPG = true;
      }
      let name = file.name;
      let list = name.split(".");
      if (list[list.length - 1] === "rar" || list[list.length - 1] === "7z") {
        isJPG = true;
      }

      const isLt2M = file.size / 1024 / 1024 < 5;
      if (!isJPG) {
        this.$message.error("文件格式不正确！");
      }
      if (!isLt2M) {
        this.$message.error("文件大小不能超过 5MB!");
      }
      return isJPG && isLt2M;
    },

    deleteUrl() {
      this.ruleForm.enclosure_file = "";
      this.$refs.ruleForm.validateField("enclosure_file");
    },
    // 其他文件上传成功
    async UploadSuccessOtherenclosure_file(data) {
      const { url } = data;
      console.log(url);
      if (url === "noToken") {
        await this.logout();
      } else {
        this.ruleForm.enclosure_file = url;
        this.$message.success("附件上传成功!");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.brand {
}
.lsac {
  font-weight: bold;
  font-size: 14px;
  color: #777;
}
</style>
