<template>
  <div class="orderConfirm pagePadding">
    <div style="width: 100%" v-if="powers.some((i) => i == '001')">
      <show-data-table
        style="margin: 0 0 10px 0; padding: 0"
        :sitem="sitem"
        v-if="sitem && status"
        :columns="showColumns"
        border
      >
        <template #status>
          <el-tag :size="'mini'" :type="sitem.status_type" style="margin: auto">{{
            sitem.status_name
          }}</el-tag>
        </template>
        <template #error_msg>
          <span :style="{ color: sitem.error_msg ? 'red' : '' }">{{
            sitem.error_msg ? sitem.error_msg : "--"
          }}</span>
        </template>
      </show-data-table>

      <el-form
        ref="ruleForm"
        :model="ruleForm"
        status-icon
        :size="'mini'"
        :rules="rulesThis"
        label-width="0px"
      >
        <div class="tab-row">
          <div class="tab-item-label">
            <label style="color: transparent">*</label>字段
          </div>
          <div class="tab-item-main">
            <el-row class="tab-title">
              <el-col :span="4">文件导入数据</el-col>
              <el-col :span="9">系统解析数据</el-col>
              <el-col :span="11">确认后的数据</el-col>
            </el-row>
          </div>
        </div>

        <div
          v-if="
            importSitem &&
            importSitem.platform_code &&
            confirmSitem &&
            confirmSitem.platform_code
          "
        >
          <div class="tab-row">
            <div class="tab-item-label">
              <div><label style="color: red">*</label>平台订单号</div>
              <div><label style="color: transparent">*</label>其他单号</div>
            </div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.platform_code }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.po_code }}
                  </div>
                </el-col>
                <el-col :span="9">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.platform_code }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.po_code }}
                  </div>
                </el-col>
                <el-col :span="11" class="nop">
                  <el-row>
                    <el-col :span="12" class="border">
                      <el-form-item prop="platform_code">
                        <el-input
                          v-model="ruleForm.platform_code"
                          maxlength="100"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          placeholder="平台订单号"
                        /> </el-form-item
                    ></el-col>

                    <el-col :span="12" class="border">
                      <el-form-item prop="po_code">
                        <el-input
                          v-model="ruleForm.po_code"
                          maxlength="100"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          placeholder="其他单号"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
            </div>
          </div>
          <div class="tab-row">
            <div class="tab-item-label">
              <div><label style="color: red">*</label>平台订单下单时间</div>
              <div><label style="color: red">*</label>平台商品编号</div>
            </div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.platform_time }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.plat_code }}
                  </div>
                </el-col>
                <el-col :span="9"
                  ><div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.platform_time }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.plat_code }}
                  </div>
                  <div v-if="conGoodData && conGoodData.good_thumb_img">
                    <show-data-table
                      :sitem="conGoodData"
                      :columns="onlineColumns"
                      :border="true"
                    >
                      <template slot="good_name">
                        <img
                          v-viewer
                          style="width: 23px; height: 23px; margin: 0 5px 0 0"
                          class="fl hover"
                          v-if="conGoodData.good_thumb_img"
                          :src="conGoodData.good_thumb_img"
                          alt=""
                        />
                        <span>{{ conGoodData.good_name }}</span>
                        <span
                          v-for="(si, i) in conGoodData.speclist"
                          :key="si.spec_id + i"
                        >
                          <span v-if="i !== 0">-</span>
                          <span v-else>_</span>
                          <span>{{ si.spec_name }}[{{ si.spec_value }}]</span>
                        </span>
                        <el-popover placement="top" width="300" trigger="hover">
                          <ul>
                            <li>
                              <span>上线商品编号：</span
                              ><span>{{ conGoodData.skuCode }}</span>
                            </li>
                            <li
                              v-if="
                                newTime !== '' &&
                                private_field &&
                                private_field.length > 0 &&
                                private_field.some((item) => item == '1')
                              "
                            >
                              <span>商品成本编号：</span
                              ><span>{{ conGoodData.spuCode }}</span>
                            </li>
                            <!-- <li>
                              <span>平台商品编码：</span
                              ><span>{{ conGoodData.platform_code_en }}</span>
                            </li> -->
                          </ul>
                          <i class="el-icon-warning-outline fr" slot="reference"></i>
                        </el-popover>
                      </template>

                      <template slot="company">
                        <span>{{ conGoodData.company }}</span>
                        <el-popover placement="top" width="300" trigger="hover">
                          <ul>
                            <li>
                              <span>业务企业编号：</span
                              ><span>{{ conGoodData.companyNo }}</span>
                            </li>
                          </ul>
                          <i class="el-icon-warning-outline fr" slot="reference"></i>
                        </el-popover>
                      </template>

                      <template slot="cat_info">
                        <span v-for="(si, sii) in conGoodData.cat_info" :key="si + sii"
                          >{{ sii === 0 ? "" : "_" }}{{ si.name }}</span
                        >
                      </template>
                      <template slot="exclusive">
                        <span v-for="(si, sii) in conGoodData.exclusive" :key="si.id">
                          <span v-if="sii !== 0">/</span>
                          <span>{{ si.name }}</span>
                        </span>
                      </template>

                      <template slot="is_stock">
                        <el-tag
                          :size="'mini'"
                          v-text="
                            (
                              options4.find((item) => item.id == conGoodData.is_stock) ||
                              {}
                            ).name || '--'
                          "
                        />
                      </template>
                    </show-data-table>
                  </div>
                </el-col>
                <el-col :span="11" class="nop">
                  <el-row>
                    <el-col :span="12" class="border">
                      <el-form-item prop="platform_time">
                        <el-date-picker
                          type="datetime"
                          placeholder="平台订单下单时间"
                          v-model="ruleForm.platform_time"
                          style="width: 100%"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          :picker-options="pickerOptions"
                          @change="selectTime"
                        >
                        </el-date-picker> </el-form-item
                    ></el-col>
                    <el-col :span="12" class="border">
                      <el-form-item prop="plat_code">
                        <el-input
                          v-model="ruleForm.plat_code"
                          maxlength="100"
                          readonly
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          @focus="showModel = true"
                          placeholder="平台商品编号"
                      /></el-form-item>
                    </el-col>
                    <el-col :span="24" v-if="subGoodData && subGoodData.good_thumb_img">
                      <show-data-table
                        :sitem="subGoodData"
                        :columns="onlineColumns"
                        :border="true"
                      >
                        <template slot="good_name">
                          <img
                            v-viewer
                            style="width: 23px; height: 23px; margin: 0 5px 0 0"
                            class="fl"
                            v-if="subGoodData.good_thumb_img"
                            :src="subGoodData.good_thumb_img"
                            alt=""
                          />
                          <span>{{ subGoodData.good_name }}</span>
                          <span
                            v-for="(si, i) in subGoodData.speclist"
                            :key="si.spec_id + i"
                          >
                            <span v-if="i !== 0">-</span>
                            <span v-else>_</span>
                            <span>{{ si.spec_name }}[{{ si.spec_value }}]</span>
                          </span>
                          <el-popover placement="top" width="300" trigger="hover">
                            <ul>
                              <li>
                                <span>上线商品编号：</span
                                ><span>{{ subGoodData.skuCode }}</span>
                              </li>
                              <li
                                v-if="
                                  newTime !== '' &&
                                  private_field &&
                                  private_field.length > 0 &&
                                  private_field.some((item) => item == '1')
                                "
                              >
                                <span>商品成本编号：</span
                                ><span>{{ subGoodData.spuCode }}</span>
                              </li>
                              <!-- <li>
                                <span>平台商品编码：</span
                                ><span>{{ subGoodData.platform_code_en }}</span>
                              </li> -->
                            </ul>
                            <i class="el-icon-warning-outline fr" slot="reference"></i>
                          </el-popover>
                        </template>

                        <template slot="company">
                          <span>{{ subGoodData.company }}</span>
                          <el-popover placement="top" width="300" trigger="hover">
                            <ul>
                              <li>
                                <span>业务企业编号：</span
                                ><span>{{ subGoodData.companyNo }}</span>
                              </li>
                            </ul>
                            <i class="el-icon-warning-outline fr" slot="reference"></i>
                          </el-popover>
                        </template>
                        <template slot="cat_info">
                          <span v-for="(si, sii) in subGoodData.cat_info" :key="si + sii"
                            >{{ sii === 0 ? "" : "_" }}{{ si.name }}</span
                          >
                        </template>
                        <template slot="exclusive">
                          <span v-for="(si, sii) in subGoodData.exclusive" :key="si.id">
                            <span v-if="sii !== 0">/</span>
                            <span>{{ si.name }}</span>
                          </span>
                        </template>

                        <template slot="is_stock">
                          <el-tag
                            :size="'mini'"
                            v-text="
                              (
                                options4.find(
                                  (item) => item.id == subGoodData.is_stock
                                ) || {}
                              ).name || '--'
                            "
                          />
                        </template>
                      </show-data-table>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
            </div>
          </div>

          <div class="tab-row">
            <div class="tab-item-label">
              <div><label style="color: red">*</label>收费模式</div>
              <div><label style="color: red">*</label>销售渠道</div>
            </div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.mode }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.sale_source }}
                  </div>
                </el-col>
                <el-col :span="9">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.mode }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.sale_source }}
                  </div></el-col
                >
                <el-col :span="11" class="nop">
                  <el-row>
                    <el-col :span="12" class="border">
                      <el-form-item prop="mode">
                        <el-select
                          v-model="ruleForm.mode"
                          style="width: 100%"
                          clearable
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          placeholder="收费模式"
                        >
                          <el-option
                            v-for="item in options"
                            :key="item.label"
                            :label="item.label"
                            :value="item.label"
                          >
                          </el-option> </el-select
                      ></el-form-item>
                    </el-col>

                    <el-col :span="12" class="border">
                      <el-form-item prop="sale_source">
                        <el-select
                          v-model="ruleForm.sale_source"
                          style="width: 100%"
                          clearable
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          placeholder="销售渠道"
                        >
                          <el-option
                            v-for="(item, i) in coptions"
                            :key="item.source + i"
                            :label="item.source"
                            :value="item.source"
                          >
                          </el-option> </el-select></el-form-item></el-col
                  ></el-row>
                </el-col>
              </el-row>
            </div>
          </div>
          <div class="tab-row">
            <div class="tab-item-label">
              <div><label style="color: red">*</label>收货人</div>
              <div><label style="color: red">*</label>收货电话</div>
            </div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.contactor }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.mobile }}
                  </div>
                </el-col>
                <el-col :span="9">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.contactor }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.mobile }}
                  </div></el-col
                >
                <el-col :span="11" class="nop">
                  <el-row>
                    <el-col :span="12" class="border">
                      <el-form-item prop="contactor">
                        <el-input
                          v-model="ruleForm.contactor"
                          maxlength="100"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          placeholder="收货人"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12" class="border">
                      <el-form-item prop="mobile">
                        <el-input
                          v-model="ruleForm.mobile"
                          maxlength="100"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          placeholder="收货电话"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
            </div>
          </div>

          <div class="tab-row">
            <div class="tab-item-label">
              <div><label style="color: red">*</label>省市区</div>
              <div><label style="color: red">*</label>详细地址</div>
            </div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4">
                  <div style="min-height: 26px; word-break: break-all">&nbsp;</div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.addr }}
                  </div></el-col
                >
                <el-col :span="9">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.addr_name }}&nbsp;
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.addr }}
                  </div>
                </el-col>
                <el-col :span="11" class="nop">
                  <el-row>
                    <el-col :span="12" class="border">
                      <el-form-item prop="addr_code">
                        <select-area
                          :value="ruleForm.addr_code"
                          :size="'mini'"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          placeholder="收货省市区"
                          @selectChange="select_area_change($event)"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12" class="border">
                      <el-form-item prop="addr">
                        <el-input
                          v-model="ruleForm.addr"
                          maxlength="100"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          placeholder="详细地址"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
            </div>
          </div>

          <div class="tab-row">
            <div class="tab-item-label"><label style="color: red">*</label>订单备注</div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4" style="min-height: 26px; word-break: break-all">{{
                  importSitem.order_remark
                }}</el-col>
                <el-col :span="9" style="min-height: 26px; word-break: break-all">{{
                  confirmSitem.order_remark
                }}</el-col>
                <el-col :span="11">
                  <el-form-item prop="order_remark">
                    <el-input
                      v-model="ruleForm.order_remark"
                      maxlength="100"
                      :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                      placeholder="订单备注" /></el-form-item
                ></el-col>
              </el-row>
            </div>
          </div>

          <div class="tab-row">
            <div class="tab-item-label">
              <div><label style="color: red">*</label>数量</div>
              <div><label style="color: red">*</label>单价</div>
            </div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.num }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ importSitem.price }}
                  </div>
                </el-col>
                <el-col :span="9">
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.num }}
                  </div>
                  <div style="min-height: 26px; word-break: break-all">
                    {{ confirmSitem.price }}
                  </div>
                </el-col>
                <el-col :span="11" class="nop">
                  <el-row>
                    <el-col :span="12" class="border">
                      <el-form-item prop="num">
                        <digital-input
                          :values="ruleForm.num"
                          :placeholder="'数量'"
                          :min="0"
                          :max="100000000000"
                          :position="'right'"
                          :precision="0"
                          :size="'mini'"
                          :controls="false"
                          :append="''"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          @reschange="number_change($event, 'num')"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12" class="border">
                      <el-form-item prop="price">
                        <digital-input
                          :values="ruleForm.price"
                          :placeholder="'单价'"
                          :min="price_min"
                          :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                          :max="100000000000"
                          :position="'right'"
                          :precision="2"
                          :size="'mini'"
                          :controls="false"
                          :append="'元'"
                          @reschange="number_change($event, 'price')"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
            </div>
          </div>

          <div class="tab-row">
            <div class="tab-item-label">
              <label style="color: transparent">*</label>活动名称
            </div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4" style="min-height: 26px; word-break: break-all">{{
                  importSitem.activity_name
                }}</el-col>
                <el-col :span="9" style="min-height: 26px; word-break: break-all">{{
                  confirmSitem.activity_name
                }}</el-col>
                <el-col :span="11">
                  <el-form-item prop="activity_code">
                    <el-select
                      v-model="ruleForm.activity_code"
                      style="width: 100%"
                      clearable
                      :disabled="!(status === '2' && powers.some((i) => i == '008'))"
                      @change="get_new_price"
                      placeholder="活动名称"
                    >
                      <el-option
                        v-for="(item, i) in actOptions"
                        :key="item.activity_code + i"
                        :label="item.activity_name"
                        :value="item.activity_code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </div>
          <div class="tab-row">
            <div class="tab-item-label">
              <label style="color: transparent">*</label>订单总金额
            </div>
            <div class="tab-item-main">
              <el-row class="tab-title">
                <el-col :span="4" style="min-height: 26px; word-break: break-all">{{
                  importSitem.before_discount_all_price
                }}</el-col>
                <el-col :span="9" style="min-height: 26px; word-break: break-all">{{
                  confirmSitem.before_discount_all_price
                }}</el-col>
                <el-col :span="11" style="min-height: 26px; word-break: break-all">
                  {{ ruleForm.before_discount_all_price }}</el-col
                >
              </el-row>
            </div>
          </div>

          <div class="tab-row" v-if="status === '2' && powers.some((i) => i == '008')">
            <div class="tab-item-label">
              <label style="color: transparent">*</label>
            </div>
            <div class="tab-item-main tr">
              <el-button type="primary" @click="submitForm" :size="'mini'"
                >保 存
              </el-button>
              <!-- <el-button @click="showModelThis = false" :size="'mini'">{{
                isDetail ? "关 闭" : "取 消"
              }}</el-button> -->
            </div>
          </div>
        </div>
      </el-form>
      <search-good-online-modal
        :once="true"
        :sitem="{ platform_code: platform_id }"
        :active="true"
        :show-model="showModel"
        @resultList="resultList"
        @cancel="showModel = false"
      />
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>
<script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/orderEntry/orderConfirm";
import {
  options,
  ruleForm,
  rules,
  options1,
  options2,
  options3,
  options4,
  options5,
  options6,
  options7,
  options8,
  options9,
  onlineColumns,
} from "./columns";
import searchGoodOnlineModal from "@/components/search-good-online-modal";
import { accMul } from "@/utils/validate";
export default {
  name: "orderConfirm",
  mixins: [mixinPage, resToken],
  components: {
    searchGoodOnlineModal,
  },
  computed: {
    powers() {
      const tran =
        this.$store.getters.btnList.find((item) => item.menu_route == "orderConfirm") ||
        {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      statusOptions: [],
      platform_id: "",
      showColumns: [
        {
          prop: "creater",
          label: "导入人",
          span: 6,
        },
        {
          prop: "addtime",
          label: "导入时间",
          span: 6,
        },
        {
          prop: "status",
          label: "状态",
          _slot_: "status",
          span: 6,
        },
        {
          prop: "orderCode",
          label: "订单编号",
          span: 6,
        },
        {
          prop: "updater",
          label: "确认人",
          span: 6,
        },
        {
          prop: "success_date",
          label: "录入成功时间",
          span: 6,
        },

        {
          prop: "platform_name",
          label: "客户名称",
          span: 12,
        },
        {
          prop: "platform_title",
          label: "导入目标平台",
          span: 6,
        },

        {
          prop: "error_msg",
          label: "解析失败原因",
          _slot_: "error_msg",
          span: 18,
        },
      ],

      showModel: false,
      hasdiff: false,
      activeTabs: "1",
      sitem: null,
      isMetal: false,
      finishStatus: "finish",
      pickerOptions: {
        disabledDate: (time) => {
          return time.getTime() > new Date().valueOf();
        },
      },

      activeNames: ["0", "1", "2", "3", "4", "5", "10"],
      importSitem: null,
      confirmSitem: null,
      price_min: "0",
      subSitem: null,
      conGoodData: null,
      subGoodData: null,
      status: "",
      newTime: "",
      loading: false,
      queryId: "",
      rulesThis: {},
      coptions: [],
      options,
      actOptions: [],
      ruleForm: {},
      rules,
      options1,
      options2,
      options3,
      options4,
      options5,
      options6,
      options7,
      options8,
      options9,
      onlineColumns,
      priceLoding: false,
    };
  },
  mounted() {
    this.queryId = this.$route.query.id;
    this.initForm();
  },
  methods: {
    change_good() {},

    statusActive(status) {
      let active = "";
      switch (status) {
        case "1":
          active = "系统验证数据中";
          break;
        case "2":
          active = "待确认订单信息";
          break;
        case "3":
          active = "待处理(待扣减库存)";
          break;
        case "4":
          active = "库存不足";
          break;
        case "5":
          active = "订单录入成功";
          break;
      }
      return active;
    },
    statusActiveTag(status) {
      let active = "";
      switch (status) {
        case "1":
          active = "";
          break;
        case "2":
          active = "info";
          break;
        case "3":
          active = "warning";
          break;
        case "4":
          active = "danger";
          break;
        case "5":
          active = "success";
          break;
      }
      return active;
    },
    async initForm() {
      this.loading = true;
      this.rulesThis = this.rules;
      await this.resetForm();

      await this.initData();
      this.loading = false;
    },

    async againForm(sitem) {
      const {
        platform_code,
        po_code,
        platform_time,
        plat_code,
        sale_source,
        mode,
        contactor,
        mobile,
        price,
        num,
        before_discount_all_price,
        activity_code,
        order_remark,
        addr,
        addr_code,
      } = sitem;
      this.ruleForm = {
        id: this.queryId || "",
        platform_code: platform_code || "", //平台订单号
        po_code: po_code || "", //其他单号
        platform_time: platform_time || "", //平台下单时间
        plat_code: plat_code || "", //平台商品编号
        sale_source: sale_source || "", //销售渠道
        mode: mode || "", //收费模式
        contactor: contactor || "", ///收货人
        mobile: mobile || "", //联系电话
        price: price || "", //单价
        num: num || "", //数量
        before_discount_all_price: before_discount_all_price || "", //优惠前总金额
        activity_code: activity_code || "", //优惠活动名称
        order_remark: order_remark || "", //订单备注
        addr: addr || "", //联系地址
        addr_code: addr_code && addr_code.length > 0 ? addr_code.split(",") : [], //省市区
      };
      this.ruleForm.before_discount_all_price = accMul(
        this.ruleForm.num,
        this.ruleForm.price
      );
      if (plat_code && plat_code !== "") {
        await this.get_goods_active();
      }
      if (this.platform_id) {
        await this.get_source();
      }
    },

    async initData() {
      this.sitem = null;
      this.loading = true;
      const { code, data, message } = await asyncRequest.detail({
        id: this.queryId,
      });
      if (code === 0) {
        const {
          status,
          import: simport,
          confirm,
          user_update,
          orderCode,
          creater,
          addtime,
          updater,
          success_date,
          error_msg,
          platform_name,
          platform_title,
          platform_id,
        } = data;
        this.platform_id = platform_id;
        this.sitem = {
          orderCode,
          status,
          creater,
          addtime,
          updater,
          success_date,
          status_name: this.statusActive(status),
          status_type: this.statusActiveTag(status),
          platform_name,
          platform_title,
          error_msg,
        };
        this.importSitem = simport ? JSON.parse(JSON.stringify(simport)) : null;
        this.confirmSitem = confirm ? JSON.parse(JSON.stringify(confirm)) : null;

        this.status = status;
        if (!(this.status === "3" || this.status === "4" || this.status === "5")) {
          console.log(12345);
          this.subSitem = confirm ? JSON.parse(JSON.stringify(confirm)) : null;
        } else {
          this.subSitem = user_update ? JSON.parse(JSON.stringify(user_update)) : null;
        }
        if (
          this.confirmSitem !== null &&
          this.confirmSitem.plat_code &&
          this.confirmSitem.plat_code !== ""
        ) {
          await this.onlineData(1, this.confirmSitem.plat_code);
        }
        if (this.subSitem !== null) {
          if (this.subSitem.plat_code && this.subSitem.plat_code !== "") {
            await this.onlineData(2, this.subSitem.plat_code);
          }

          await this.againForm(this.subSitem);
        }

        this.getNewTime();
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
      }
      this.loading = false;
    },
    async onlineData(type, good_code) {
      this.loading = true;
      const { code, data, message } = await asyncRequest.good_detail({
        plat_code: good_code,
        platform_id: this.platform_id,
      });
      if (code === 0) {
        if (type === 1) {
          this.conGoodData = data;
        } else {
          this.subGoodData = data;
          const { platform_name } = data;
          if (this.status !== "2") {
            this.sitem.platform_name = platform_name + "客户";
          }
          if (this.platform_id) {
            await this.get_source(this.platform_id);
          }
        }
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
        this.ruleForm.num = "0";
        await this.get_new_price();
      }
      this.loading = false;
    },

    async get_source() {
      this.coptions = [];
      const { code, data, message } = await asyncRequest.sourceList({
        platform_id: this.platform_id,
      });
      if (code === 0) {
        this.coptions = data;
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
      }
      if (this.coptions.length == 0) {
        this.ruleForm.sale_source = "";
        this.$refs.ruleForm.validateField("sale_source");
      }
    },
    async resultList(e) {
      if (e && e.length === 1) {
        const { plat_code } = JSON.parse(JSON.stringify(e[0]));
        this.ruleForm.plat_code = plat_code || "";
        this.$refs.ruleForm.validateField("plat_code");
        if (plat_code) {
          await this.onlineData(2, plat_code);
        } else {
          this.subGoodData = null;
          this.coptions = [];
          this.ruleForm.num = "0";
          this.ruleForm.price = "0";
          this.ruleForm.sale_source = "";
          this.$refs.ruleForm.validateField("num");
          this.$refs.ruleForm.validateField("price");
          this.$refs.ruleForm.validateField("sale_source");
        }
      }
    },
    //省市区选择
    async select_area_change(e) {
      this.ruleForm.addr_code = e;
      this.$refs.ruleForm.validateField("addr_code");
    },
    async number_change(e, key) {
      this.ruleForm[key] = e + "" || "0";
      this.$refs.ruleForm.validateField(key);
      if (key === "num") {
        await this.get_new_price();
      }
      this.ruleForm.before_discount_all_price = accMul(
        this.ruleForm.num,
        this.ruleForm.price
      );
    },

    async get_new_price() {
      const { num, activity_code } = this.ruleForm;

      if (num * 1 === 0) {
        this.price_min = "0";
        this.ruleForm.price = "0";
        return;
      } else {
        const { skuCode: conSkuCode } = this.conGoodData;
        const { skuCode: subSkuCode } = this.subGoodData;

        let model = {
          skuCode:
            this.status === "3" || this.status === "4" || this.status === "5"
              ? subSkuCode
              : conSkuCode,
          sale_num: num,
          is_activity: activity_code ? "1" : "0",
          act_code: activity_code ? activity_code : "",
        };
        if (!this.priceLoding) {
          const { isok, price } = await this.set_salegetprice(model);
          this.price_min = isok ? price : "0";
          if (!isok) {
            this.ruleForm.price = "0";
          } else {
            if (price * 1 >= this.ruleForm.price * 1) this.ruleForm.price = price;
          }
        }
      }
    },
    async get_goods_active() {
      this.actOptions = [];
      const { skuCode, companyNo, platform_code } = this.subGoodData;

      let model = {
        skuCode,
        companyNo,
        platform_id: platform_code,
      };
      const { code, data, message } = await asyncRequest.goods_active(model);
      if (code === 0) {
        const { act } = data;
        this.actOptions = act;
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
      }
      if (this.actOptions.length === 0) {
        this.ruleForm.activity_code = "";
        this.$refs.ruleForm.validateField("activity_code");
      }
    },
    async resetForm() {
      // 重置
      await this.$nextTick(() => {
        if (this.$refs.ruleForm) {
          this.$refs.ruleForm.resetFields();
          this.$refs.ruleForm.clearValidate();
          this.ruleForm = ruleForm;
        }
      });
    },
    async submitForm() {
      await this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          if (this.loading) {
            return;
          }
          this.loading = true;
          let model = JSON.parse(JSON.stringify(this.ruleForm));
          model.platform_id = this.platform_id;
          const { code, data, message } = await asyncRequest.update(model);
          this.loading = false;
          if (code === 0) {
            this.$notify.success({
              title: "提交成功!",
              message: "",
            });
            this.initForm();
          } else if (code >= 100 && code <= 104) {
            await this.logout();
          } else {
            this.$message.warning(message);
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    async set_salegetprice(model) {
      this.priceLoding = true;
      let resModel = {
        isok: true,
        price: "0",
      };
      // console.log(model);
      let { code, message, data } = await asyncRequest.salegetprice(model);
      if (code === 0) {
        const { sale_price } = data;
        resModel.price = sale_price + "";
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
        resModel.isok = false;
      }
      this.priceLoding = false;
      return resModel;
    },
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
  },
};
</script>
<style lang="scss" scoped>
.orderConfirm {
  font-size: 13px;

  color: #909399 !important;
  line-height: 26px;
  .tab-row {
    border-left: 1px solid #ebeef5;
    border-top: 1px solid #ebeef5;
    display: flex;
    align-items: stretch;
    &:last-child {
      border-bottom: 1px solid #ebeef5;
    }
    .tab-item-label {
      padding: 4px 5px;
      width: 125px;
      .red {
        color: red;
        padding: 0 5px 0 0;
      }
    }
    .tab-item-main {
      width: calc(100% - 125px);
      border-left: 1px solid #ebeef5;

      .tab-title {
        display: flex;
        align-items: stretch;
        .el-col {
          padding: 3px 5px;
          border-right: 1px solid #ebeef5;
          &.nop {
            padding: 0;
          }
          &.border {
            border: 0;
          }
        }
      }
    }
  }
}
</style>
