<template>
  <el-form
    ref="ruleForm"
    v-loading="loading"
    :model="ruleForm"
    :rules="rulesThis"
    label-width="95px"
    class="demo-ruleForm clearfix"
  >
    <el-row :gutter="10">
      <el-col :span="12">
        <el-form-item label="公司名称" prop="name">
          <el-select
            v-model="ruleForm.name"
            multiple
            filterable
            :disabled="isDetail !== '003'"
            remote
            :multiple-limit="1"
            reserve-keyword
            placeholder="请输入关键词搜索"
            :remote-method="remoteMethod"
            :loading="selectLoading"
            @change="selectChange"
            class="setWidth"
          >
            <el-option
              v-for="item in activeOptions"
              :key="item.code"
              :label="item.name + '-----' + item.contector"
              :value="item.code"
            >
              <span style="float: left">{{ item.name }}</span>
              <span
                style="
                  float: right;
                  color: #8492a6;
                  font-size: 13px;
                  padding: 0 0 25px 0;
                "
                >{{ item.contector }}</span
              >
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="账期" prop="account">
          <el-cascader
            :disabled="
              !(isDetail === '003' || (isDetail === '005' && pdisabled))
            "
            class="setWidth"
            v-model="ruleForm.account"
            :options="accountList"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
      </el-col>
      <el-col :span="24" v-if="show">
        <el-form-item
          label="自定义比例"
          prop="scale"
          required
          style="margin: 0 0 5px 0"
        >
          <el-row>
            <el-col
              :span="isDetail === '003' ? 21 : 24"
              :style="{
                width: !(
                  isDetail === '003' ||
                  (isDetail === '005' && pdisabled)
                )
                  ? '100%'
                  : '733px',
              }"
            >
              <ul class="clearfix scale">
                <li
                  class="fl"
                  v-for="(v, i) in ruleForm.scale"
                  :key="v.num + '' + i"
                  style="margin: 0 0 10px 0"
                >
                  <div class="Addend fl">
                    <i class="el-icon-plus fuhao-i fl" v-if="i != 0"></i>
                    <el-input-number
                      :disabled="
                        !(
                          isDetail === '003' ||
                          (isDetail === '005' && pdisabled)
                        )
                      "
                      @change="scaleChange"
                      step-strictly
                      class="fl"
                      controls-position="right"
                      style="width: 210px"
                      v-model="v.num"
                      :precision="2"
                      :step="0.01"
                      :min="0"
                      :max="99999999"
                    ></el-input-number>
                  </div>
                </li>

                <li class="fl fuhao dengyu" style="margin: 0 0 10px 0">
                  <i class="el-icon-sort fl"></i>
                </li>
                <li class="fl" style="margin: 0 0 10px 0">
                  <el-input
                    class="fl"
                    style="width: 193px"
                    disabled
                    v-model="scaleTotal"
                  >
                    <template slot="append">元</template>
                  </el-input>
                </li>
              </ul>
            </el-col>
            <el-col
              v-if="isDetail === '003' || (isDetail === '005' && pdisabled)"
              :span="3"
              style="width: 120px"
            >
              <div class="clearfix">
                <el-button-group class="fr">
                  <el-button
                    type="primary"
                    :disabled="ruleForm.scale.length >= 5"
                    @click="Addend"
                    icon="el-icon-circle-plus-outline"
                  ></el-button>
                  <el-button
                    type="danger"
                    :disabled="ruleForm.scale.length <= 1"
                    @click="del"
                    icon="el-icon-delete"
                  ></el-button>
                </el-button-group>
              </div> </el-col
          ></el-row>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="商品税率" prop="inv_rate">
          <el-select
            v-model="ruleForm.inv_rate"
            style="width: 100%"
            :disabled="!(isDetail === '003' || isDetail === '005')"
            placeholder="请选择商品税率"
            @change="inv_rateChange"
          >
            <el-option
              v-for="item in ratelist"
              :key="item.id"
              :disabled="item.status !== '1'"
              :label="item.rateName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-tag type="warning" style="margin: 0 0 0 95px"
          >批量修改采购单商品税率</el-tag
        >
      </el-col>
      <el-col :span="24">
        <el-form-item label="采购单商品" :size="'mini'" prop="goodList">
          <el-row style="margin: 0 0 5px 0">
            <el-col :span="18" style="padding: 0 0 5px 0">
              <el-tag type="warning" :size="'mini'"
                >共计：<span>{{ ruleForm.goodList.length }}</span
                >个订单。</el-tag
              >
            </el-col>

            <el-col :span="6">
              <el-button
                v-if="isDetail === '003' || (isDetail === '005' && pdisabled)"
                class="fr"
                type="primary"
                :size="'mini'"
                style="margin: 0 0 0 10px"
                @click="addGoods"
                >添加采购单</el-button
              >
              <el-button
                class="fr"
                type="primary"
                @click="download"
                :disabled="downLoading"
              >
                <i class="el-icon-loading" v-if="downLoading"></i>
                <span>明细下载</span>
              </el-button>
            </el-col>
            <el-col :span="24">
              <el-table
                :data="ruleForm.goodList"
                tooltip-effect="dark"
                ref="multipleTable"
                :size="'mini'"
                stripe
                border
                row-key="index"
                max-height="320"
                style="width: 100%"
              >
                <el-table-column
                  prop="cgdNO"
                  label="采购单编号"
                  width="135"
                  fixed="left"
                  show-overflow-tooltip
                />
                <el-table-column label="采购单信息" align="center">
                  <el-table-column
                    prop="purchasePrice"
                    label="货款"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="name"
                    label="供货商"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="contector"
                    label="联系人"
                    width="65"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="ownerName"
                    label="采购员"
                    show-overflow-tooltip
                    width="65"
                  />
                  <el-table-column label="发货状态" width="85">
                    <template slot-scope="scope">
                      <el-tag
                        size="mini"
                        :type="
                          scope.row.send_info == '3'
                            ? 'success'
                            : scope.row.send_info == '2'
                            ? 'warning'
                            : 'danger'
                        "
                        v-text="
                          (
                            send_status_list.find(
                              (item) => item.value == scope.row.send_info
                            ) || {}
                          ).label || '--'
                        "
                      ></el-tag>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="inv_company"
                    label="开票编号"
                    width="170px"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="inv_company_name"
                    label="开票公司"
                    show-overflow-tooltip
                    width="170px"
                  />
                  <el-table-column
                    prop="DownTime"
                    label="下单时间"
                    show-overflow-tooltip
                  />
                </el-table-column>
                <el-table-column label="商品基础信息" align="center">
                  <el-table-column
                    label="商品编号"
                    prop="goodNo"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    label="名称"
                    prop="goodName"
                    show-overflow-tooltip
                  />

                  <el-table-column
                    prop="goodUnit"
                    label="单位"
                    show-overflow-tooltip
                    width="50"
                  />
                  <el-table-column
                    prop="isDiff"
                    label="含有工差"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="workDay"
                    label="工期"
                    show-overflow-tooltip
                  />
                </el-table-column>
                <el-table-column label="商品费用信息" align="center">
                  <el-table-column
                    prop="pay_price"
                    label="成本合计"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="pay_fee"
                    label="已付款"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="wait_fee"
                    label="待付款"
                    show-overflow-tooltip
                  />

                  <el-table-column
                    prop="nakedPrice"
                    label="成本裸价"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="markPrice"
                    label="加标费"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="packPrice"
                    label="包装费"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="certPrice"
                    label="证书费"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="openPrice"
                    label="开模费"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="craftPrice"
                    label="工艺费"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="postPrice"
                    label="物流费"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="diff_fee"
                    label="工差金额"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="diff_info"
                    label="工差"
                    show-overflow-tooltip
                  />
                </el-table-column>
                <el-table-column label="商品属性" align="center">
                  <el-table-column
                    label="类型"
                    prop="goodType"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    label="品牌"
                    prop="goodBank"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    label="型号"
                    prop="goodModel"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    label="材质"
                    prop="goodMaterial"
                    show-overflow-tooltip
                  />

                  <el-table-column
                    label="颜色"
                    prop="goodColor"
                    show-overflow-tooltip
                  />

                  <el-table-column
                    prop="goodDesc"
                    label="描述"
                    show-overflow-tooltip
                  />
                </el-table-column>
                <el-table-column label="贵金属属性" align="center">
                  <el-table-column
                    prop="goodCat"
                    label="种类"
                    show-overflow-tooltip
                  />

                  <el-table-column
                    prop="weight"
                    label="重量"
                    show-overflow-tooltip
                  />
                  <el-table-column
                    prop="price"
                    label="实时价格"
                    show-overflow-tooltip
                  />
                </el-table-column>
                <el-table-column
                  prop="taxPoint"
                  label="原税率"
                  fixed="right"
                  width="60"
                  show-overflow-tooltip
                />
                <el-table-column
                  prop="taxPoint1"
                  label="新税率"
                  fixed="right"
                  width="60"
                  show-overflow-tooltip
                />
                <el-table-column
                  v-if="isDetail === '003' || (isDetail === '005' && pdisabled)"
                  fixed="right"
                  show-overflow-tooltip
                  label="操作"
                  width="60"
                >
                  <template slot-scope="scope">
                    <el-button
                      @click="delGoods(scope.$index)"
                      type="text"
                      size="small"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
              <!-- 弹窗 新增/修改 -->
              <order-change
                :id="changeModelId"
                :companyNoCode="companyNoCode"
                :companyNoName="companyNoName"
                :show-model="changeModel"
                @refresh="goodsReshList"
                @cancel="changeModel = false"
              />
            </el-col>
          </el-row>
        </el-form-item>
      </el-col>
      <el-col
        :span="24"
        v-if="ruleForm.return_img && ruleForm.return_img.length > 0"
      >
        <el-form-item label="回执图片" :size="'mini'" class="clear return_img">
          <ul class="fl">
            <li class="fl" v-for="img in ruleForm.return_img" :key="img">
              <img
                v-viewer
                class="fl"
                :src="img"
                alt=""
                style="
                  width: 80px;
                  height: 52px;
                  border: 1px solid rgb(220, 223, 230);
                "
              />
            </li>
          </ul> </el-form-item
      ></el-col>
      <el-col :span="24" style="text-align: right">
        <el-button
          v-if="isDetail === '003' || isDetail === '005'"
          type="primary"
          @click="submitForm"
          >保 存
        </el-button>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import asyncRequest from "@/apis/service/purchase/orderRecord";
import orderChange from "./orderChange";
import accountList from "@/assets/js/accountList";
import { timestampToTime } from "@/utils/validate";
import { formatJson } from "@/utils/publicMethods";
import resToken from "@/mixins/resToken";
export default {
  name: "orderRecord",
  props: [
    "dstatus",
    "showModel",
    "id",
    "isDetail",
    "newTime",
    "payNo",
    "companyNo",
    "pay_status",
  ],
  components: {
    orderChange,
  },
  mixins: [resToken],
  data() {
    return {
      send_status_list: [
        {
          value: "1",
          label: "未发货",
        },
        {
          value: "2",
          label: "部分发货",
        },
        {
          value: "3",
          label: "全部发货",
        },
      ],
      pdisabled: false,
      companyNoCode: "",
      companyNoName: "",
      supplierNo: [],
      ratelist: [],
      downLoading: false,
      spread: false,
      selectLoading: false,
      changeModelId: 0,
      changeModel: false,
      accountList: accountList,
      loading: false,
      ruleForm: {
        id: this.id,
        account: ["X", "1"],
        name: [],
        inv_rate: "",
        scale: [
          {
            num: 0,
          },
          {
            num: 0,
          },
        ],
        goodList: [],
        return_img: [],
      },
      rulesThis: this.rules,
      rules: {
        name: [
          {
            type: "array",
            required: true,
            message: "请选择公司名称",
            trigger: "change",
          },
        ],
        inv_rate: [
          {
            required: true,
            message: "请选择商品税率",
            trigger: "change",
          },
        ],
        account: [
          {
            type: "array",
            required: true,
            message: "请选择账期",
            trigger: "change",
          },
        ],
        goodList: [
          {
            type: "array",
            required: true,
            message: "请选择采购单商品",
            trigger: "change",
          },
        ],
      },

      activeOptions: [],
      parmValue: {
        name: "", // 账户
        page: 1, // 页码
        size: 30, // 每页显示条数
      },
      scaleTotal: 0,
      show: false,
    };
  },

  watch: {
    newTime: function (old, val) {
      if (old !== val) {
        this.initForm();
      }
    },
  },
  mounted() {
    this.initForm();
  },
  methods: {
    async initForm() {
      this.loading = true;
      // console.log(this.pay_status);
      this.pdisabled =
        parseInt(this.pay_status) === 0 && parseInt(this.dstatus) === 0;
      if (this.isDetail === "003" || this.isDetail === "007") {
        this.spread = true;
      } else {
        this.spread = false;
      }
      await this.getratelist();
      if (this.isDetail === "003") {
        this.rulesThis = this.rules;
        await this.resetForm();
      } else if (this.isDetail === "005") {
        this.rulesThis = this.rules;
        await this.resetForm();
        await this.initData();
      } else {
        this.rulesThis = {};
        await this.initData();
      }

      this.loading = false;
    },
    async getratelist() {
      const res = await asyncRequest.ratelist({});
      if (res && res.code === 0 && res.data && res.data.length > 0) {
        this.ratelist = res.data;
        this.ratelist.map((v1) => {
          v1.rateName = v1.rate + "%";
          return v1;
        });
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.ratelist = [];
      }
    },
    inv_rateChange() {
      let index = this.ratelist.findIndex(
        (v1) => v1.id === this.ruleForm.inv_rate
      );
      let key = "";
      if (index !== -1) {
        key = this.ratelist[index].rateName;
      }
      if (
        this.ruleForm &&
        this.ruleForm.goodList &&
        this.ruleForm.goodList.length > 0
      ) {
        this.ruleForm.goodList.forEach((v2, i2) => {
          v2.taxPoint1 = key;
          this.$set(this.ruleForm.goodList, i2, v2);
        });
      }
    },
    selectChange(val) {
      if (val) {
        this.supplierNo = val;
      } else {
        this.supplierNo = [];
      }

      if (
        this.ruleForm.name.length !== 0 &&
        this.ruleForm.name[0] &&
        this.changeModelId &&
        this.changeModelId !== 0
      ) {
        this.ruleForm.goodList = [];
      }
    },
    openChange() {
      console.log(this.spread);
      this.spread = !this.spread;
    },
    addGoods() {
      // console.log(this.supplierNo);
      if (this.supplierNo.length === 1) {
        this.changeModelId = this.supplierNo[0];
        if (this.ruleForm.goodList && this.ruleForm.goodList.length > 0) {
          this.companyNoCode = this.ruleForm.goodList[0].inv_company;
          this.companyNoName = this.ruleForm.goodList[0].inv_company_name;
        } else {
          this.companyNoCode = "";
          this.companyNoName = "";
        }
        this.changeModel = true;
      } else {
        this.$message.warning("请选择公司名称");
      }
    },
    Addend() {
      this.ruleForm.scale.push({ num: 0 });
      this.scaleChange();
    },
    del() {
      this.ruleForm.scale.splice(this.ruleForm.scale.length - 1, 1);
      this.scaleChange();
    },
    scaleChange() {
      let str = 0;
      this.ruleForm.scale.forEach((v1) => {
        str += v1.num;
      });
      this.scaleTotal = parseFloat(parseFloat(str + "").toFixed(2));
      //.toFixed(2);
    },
    async goodsReshList(e) {
      let oldList = JSON.parse(JSON.stringify(this.ruleForm.goodList)),
        addList = JSON.parse(JSON.stringify(e)),
        newList = [].concat(...oldList);
      addList.forEach((v1, index) => {
        let oldindex = oldList.findIndex((v2) => v1.cgdNO === v2.cgdNO);
        if (oldindex === -1) {
          newList.push(addList[index]);
        }
        console.log(index, oldindex);
      });
      newList.sort((a, b) => {
        if (a.cgdNO != b.cgdNO) {
          return a.cgdNO - b.cgdNO;
        }
        return a.goodNo - b.goodNo;
      });

      this.ruleForm.goodList = [].concat(...newList);

      this.formatGoodList();

      this.inv_rateChange();
    },
    formatGoodList() {
      this.ruleForm.goodList.map((v1) => {
        v1.taxPoint1 = v1.taxPoint1 ? v1.taxPoint1 : "";
        v1.purchasePrice = v1.purchasePrice
          ? parseFloat(v1.purchasePrice + "").toFixed(2)
          : "-";
        v1.totalPrice = v1.totalPrice
          ? parseFloat(v1.totalPrice + "").toFixed(2)
          : "-";

        v1.pay_fee = v1.pay_fee ? parseFloat(v1.pay_fee + "").toFixed(2) : "-";
        v1.wait_fee = v1.wait_fee
          ? parseFloat(v1.wait_fee + "").toFixed(2)
          : "-";

        v1.nakedPrice = v1.nakedPrice
          ? parseFloat(v1.nakedPrice + "").toFixed(2)
          : "-";
        v1.markPrice = v1.markPrice
          ? parseFloat(v1.markPrice + "").toFixed(2)
          : "-";

        v1.packPrice = v1.packPrice
          ? parseFloat(v1.packPrice + "").toFixed(2)
          : "-";
        v1.certPrice = v1.certPrice
          ? parseFloat(v1.certPrice + "").toFixed(2)
          : "-";

        v1.openPrice = v1.openPrice
          ? parseFloat(v1.openPrice + "").toFixed(2)
          : "-";
        v1.craftPrice = v1.certPrice
          ? parseFloat(v1.craftPrice + "").toFixed(2)
          : "-";

        v1.postPrice = v1.postPrice
          ? parseFloat(v1.postPrice + "").toFixed(2)
          : "-";
        v1.weight = v1.weight ? parseFloat(v1.weight + "").toFixed(2) : "-";

        v1.diff_fee = v1.diff_fee
          ? parseFloat(v1.diff_fee + "").toFixed(2)
          : "-";
        v1.price = v1.price ? parseFloat(v1.price + "").toFixed(2) : "-";

        return v1;
      });
    },
    /**
     *  批量导出
     */
    download() {
      if (!this.downLoading) {
        if (
          this.ruleForm &&
          this.ruleForm.goodList &&
          this.ruleForm.goodList.length < 1
        ) {
          this.$message.warning("暂无采购单商品！");
        } else {
          this.downLoading = true;
          let data = JSON.parse(JSON.stringify(this.ruleForm.goodList));

          let list = [];
          data.forEach((item, index) => {
            let model = Object.assign({}, item);
            model.names = item.name + item.department;
            list.push(model);
          });
          const xlsName = `采购应付账款导出-${timestampToTime(
            new Date().valueOf()
          )}`;
          import("@/vendor/Export2Excel").then((excel) => {
            const tHeader = [
              "采购单编号",
              "商品名称",
              "g/个",

              "金属种类",
              "物流费",

              "数量",
              "下单日期",
              "客户名称",

              "货款总额",
              "付款金额",
              "成本金额",
            ];
            const filterVal = [
              "cgdNO",
              "goodName",
              "weight",

              "goodCat",
              "postPrice",

              "orderNum",
              "DownTime",
              "names",

              "purchasePrice",
              "wait_fee",
              "pay_price",
            ];
            const data = formatJson(filterVal, list);
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: `${xlsName}`,
            });
            this.$message.success("采购应付账款导出成功！");
            setTimeout(() => {
              this.downLoading = false;
            }, 750);
          });
        }
      }
    },
    async initData() {
      const res = await asyncRequest.detail({ sid: this.id });
      if (res && res.code === 0) {
        const {
          name,
          contector,
          pay_method,
          list,
          inv_rate,
          return_img,
          supplierNo,
          pay_rate,
        } = res.data;
        let reastr = pay_rate;
        let reaList = reastr.split(",");
        let lista = [];
        reaList.forEach((v1) => {
          v1 = v1.replace(/\[/g, "");
          v1 = v1.replace(/\]/g, "");
          let item = {
            num: parseFloat(v1),
          };
          lista.push(item);
        });
        this.ruleForm = {
          id: this.id,
          name: [name + "-----" + contector],
          account: [
            pay_method === "1" || pay_method === "2" ? "X" : "Y",
            pay_method,
          ],
          scale: lista,
          goodList: list,
          inv_rate: inv_rate,
          return_img: Array.isArray(return_img) ? return_img : [],
        };
        this.supplierNo = [supplierNo];
        this.handleChange(this.ruleForm.account);
        this.formatGoodList();
        this.inv_rateChange();
        this.$refs.ruleForm.clearValidate();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
    async resetForm() {
      // 重置
      await this.$nextTick(() => {
        if (this.$refs.ruleForm) {
          this.$refs.ruleForm.resetFields();
          this.$refs.ruleForm.clearValidate();
          this.ruleForm = {
            id: this.id,
            account: ["X", "1"],
            name: [],
            scale: [
              {
                num: 0,
              },
            ],
            goodList: [],
            return_img: [],
          };
          this.handleChange(this.ruleForm.account);
        }
      });
    },
    handleChange(value) {
      if (value[1] === "2") {
        this.show = true;
        if (this.ruleForm.scale.length === 1) {
          this.ruleForm.scale.push({
            num: 0,
          });
        }
        this.scaleChange();
      } else {
        this.show = false;
      }
      // console.log(value);
    },
    delGoods(index) {
      this.ruleForm.goodList.splice(index, 1);
    },
    setNum(s) {
      return s ? parseFloat(s + "").toFixed(2) : "-";
    },
    async submitForm() {
      await this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          let listTotal = 0;
          this.ruleForm.goodList.forEach((v1) => {
            // console.log(v1.purchasePrice);
            // console.log(v1.purchasePrice * 1);
            listTotal += v1.wait_fee * 1;
            listTotal =
              listTotal === 0 ? 0 : parseFloat(this.setNum(listTotal));
          });
          // console.log(this.scaleTotal, listTotal);
          // console.log(listTotal);
          const obj = JSON.parse(JSON.stringify(this.ruleForm));
          if (obj.account[obj.account.length - 1] !== "2") {
            this.scaleTotal = listTotal;
            obj.scale = [{ num: listTotal }];
          }
          if (
            obj.account[obj.account.length - 1] === "2" &&
            this.scaleTotal !== listTotal
          ) {
            this.$message.warning("自定义金额比例总数与货款总数不一致！");
            return;
          }
          // if (this.scaleTotal !== 100) {
          //   this.$message.error("自定义比例和必须为100%！");
          //   return;
          // }

          let isok = true;
          obj.scale.forEach((v1) => {
            if (v1.num === 0) {
              isok = false;
            }
          });
          if (!isok && obj.account[obj.account.length - 1] === "2") {
            this.$message.error("自定义比例不能出现0！");
            return;
          }
          this.loading = true;
          let scale = [];
          obj.scale.forEach((v1) => {
            console.log(v1);
            scale.push(v1.num);
          });
          let model = {
            cids: "",
            supplierNo: this.supplierNo[0],
            pay_method: obj.account[obj.account.length - 1],
            pay_rate: scale,
            inv_rate: obj.inv_rate,
          };
          console.log(obj.goodList);
          obj.goodList.forEach((v1, i1) => {
            if (i1 === 0) {
              model.cids += v1.id;
            } else {
              model.cids += "," + v1.id;
            }
          });
          if (this.id !== "add") {
            model.payNo = this.payNo;
          }
          console.log(model);
          let res = {};
          if (this.id === "add") {
            res = await asyncRequest.add(model);
          } else {
            res = await asyncRequest.save(model);
          }
          this.loading = false;
          if (res && res.code === 0) {
            const title = this.id === "add" ? "添加成功" : "修改成功";
            this.$notify.success({
              title,
              message: "",
            });
            // 刷新
            this.$emit("refreshAll");
          } else if (res && res.code >= 100 && res.code <= 104) {
            await this.logout();
          } else {
            this.$message.warning(res.message);
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    async remoteMethod(query) {
      this.selectLoading = true;
      if (query !== "") {
        this.activeOptions = [];
        this.parmValue.name = query;
        const res = await asyncRequest.supplierlist(this.parmValue);
        if (res && res.code === 0 && res.data && res.data.list) {
          this.activeOptions = res.data.list;
        } else if (res && res.code >= 100 && res.code <= 104) {
          await this.logout();
        } else {
          this.$message.warning(res.message);
        }
      } else {
        this.options = [];
      }
      this.selectLoading = false;
    },
  },
};
</script>

   <style lang="scss" scoped>
.orderRecord {
  .setWidth {
    width: 100% !important;
    // display: flex;
    // display: block !important;
    // .el-input__inner {
    //   display: flex;
    //   width: 1000px !important;
    //   display: block !important;
    // }
  }
  .return_img {
    vertical-align: top;
    ul {
      vertical-align: top;
      li {
        img {
          &:hover {
            cursor: pointer;
          }
        }
      }
    }
  }
  .scale {
    li {
      height: 40px;
      line-height: 40px;
      &.fuhao {
        width: 40px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        i {
          width: 40px;
          height: 40px;
          text-align: center;
          line-height: 40px;
          color: #97a8be;
          font-size: 20px;
        }

        &.dengyu {
          i {
            // font-size: 26px;
            transform: rotate(90deg);
            -ms-transform: rotate(90deg); /* IE 9 */
            -moz-transform: rotate(90deg); /* Firefox */
            -webkit-transform: rotate(90deg); /* Safari 和 Chrome */
            -o-transform: rotate(90deg);
          }
        }
      }
      .Addend {
        i.fuhao-i {
          width: 40px;
          height: 40px;
          text-align: center;
          line-height: 40px;
          color: #97a8be;
          font-size: 20px;
        }
      }
    }
  }
}
</style>
