<template>
  <div class="content">
    <el-dialog
      :title="Obj.DialogTitle"
      :visible.sync="dialogVisible"
      width="60%"
      top="50px"
      :before-close="close"
      :close-on-click-modal="false"
      class="abow_dialog"
    >
      <span v-show="Obj ? (Obj.show == 0 ? false : true) : true">
        <span v-if="Obj.DialogTitle == '添加销售'" style="display: flex">
          <el-radio-group
            v-model="ruleForm.is_sales_accessories"
            @change="radio_change"
          >
            <el-radio-button :label="0">手机销售</el-radio-button>
            <el-radio-button :label="1">配件销售</el-radio-button>
          </el-radio-group>
        </span>
      </span>

      <span style="font-size: 16px">销售信息</span>
      <!-- instorage_type2是寄卖 代卖  3是新代卖 1是采购 -->
      <span
        v-if="!!ruleForm['pay_amount'] && rowDetails.instorage_type == 2"
        :style="
          (
            Number(ruleForm['pay_amount']) - Number(ruleForm['purchase_price'])
          ).toFixed(2) > 0
            ? 'color:red;font-size:16px;'
            : 'color:green;font-size:16px;'
        "
        >利润:
        {{
          (
            Number(ruleForm["pay_amount"]) - Number(ruleForm["purchase_price"])
          ).toFixed(2)
        }}</span
      >
      <span
        v-if="!!ruleForm['pay_amount'] && rowDetails.instorage_type != 2"
        :style="
          (
            Number(ruleForm['pay_amount']) - Number(rowDetails['total_cost'])
          ).toFixed(2) > 0
            ? 'color:red;font-size:16px;'
            : 'color:green;font-size:16px;'
        "
        >利润:{{
          (
            Number(ruleForm["pay_amount"]) - Number(rowDetails.total_cost)
          ).toFixed(2)
        }}</span
      >
      <!-- <span v-if="!!ruleForm['pay_amount']&&rowDetails.instorage_type==2" :style="(Number(ruleForm['pay_amount']) - Number(ruleForm['purchase_price'])).toFixed(2)>0 ? 'color:red;font-size:16px;' :'color:green;font-size:16px;' ">成本: {{(Number(ruleForm['pay_amount']) - Number(ruleForm['purchase_price'])).toFixed(2)}}</span> -->
      <span
        v-if="!!ruleForm['pay_amount'] && rowDetails.instorage_type != 2"
        style="color: black; font-size: 16px"
        >成本:{{ Number(rowDetails.total_cost).toFixed(2) }}</span
      >
      <el-form
        ref="ruleForm"
        label-position="top"
        :model="ruleForm"
        label-width="100px"
        size="mini"
      >
        <el-row :gutter="0">
          <el-col v-for="(item, index) in Input" :key="index" :span="item.span">
            <el-form-item
              v-if="item.Typeshow"
              :prop="item.prop"
              :rules="{
                required: item.required,
                message: item.placeholder,
                trigger: ['blur', 'change'],
              }"
              :label="item.label"
              :disabled="item.disabled"
            >
              <template slot="label">
                <div
                  v-if="Obj.DialogTitle == '添加销售' && item.label == '条形码'"
                  style="display: flex; align-items: center"
                >
                  <div>条形码</div>
                  <div
                    v-if="(imei.zljshow || sloading) && !kehu"
                    style="margin-left: 20px"
                  >
                    <div
                      v-if="loadinglist.codeloading == 1 || sloading"
                      style="display: flex; align-items: center; color: #9aafc0"
                    >
                      <i
                        class="el-icon-loading"
                        style="color: orange; font-size: 20px"
                      />
                      <span>自动查询中</span>
                    </div>

                    <div
                      v-else-if="
                        (loadinglist.codeloading == 3 || sloading) && !kehu
                      "
                      style="display: flex; align-items: center"
                    >
                      <!-- <i class="el-icon-error" style="color:#F56C6C;font-size:20px"></i>
                      <span style="color:#F56C6C">查询失败</span> -->
                      <a
                        style="display: flex; align-items: center"
                        @click="getcode('code')"
                      >
                        <i
                          class="el-icon-refresh-right"
                          style="
                            color: #9aafc0;
                            margin-left: 15px;
                            font-size: 20px;
                          "
                        />
                        <span style="color: #9aafc0">重新获取</span>
                      </a>
                    </div>

                    <div
                      v-else-if="
                        (loadinglist.codeloading == 2 || sloading) && !kehu
                      "
                      style="display: flex; align-items: center; color: #9aafc0"
                    >
                      <!-- <i class="el-icon-success" style="color:#67C23A;font-size:20px"></i>
                      <span style="color:#67C23A">查询成功</span> -->
                      <span style="margin-left: 5px">状态:</span>
                      <span>
                        <span
                          :style="
                            loadinglist.state_name == '上架中'
                              ? 'color:green'
                              : 'color:red'
                          "
                          >{{ loadinglist.state_name }}
                        </span>
                        <span
                          v-if="!!loadinglist.sold_time"
                          style="margin-left: 2px"
                          >售出{{
                            loadinglist.sold_time | dateformat("YYYY-MM-DD")
                          }}</span
                        >
                        <span v-else style="margin-left: 2px"
                          >供货{{
                            loadinglist.order_time | dateformat("YYYY-MM-DD")
                          }}</span
                        >
                      </span>
                      <el-popover placement="bottom" trigger="click">
                        <el-table :data="loadinglist.gridData">
                          <el-table-column
                            type="index"
                            width="50"
                            label="编号"
                            align="center"
                          />
                          <el-table-column
                            width="150"
                            property="imei"
                            label="IMEI"
                            align="center"
                          />
                          <el-table-column
                            width="120"
                            property="qc_code"
                            label="质检码/商品Id"
                            align="center"
                          />
                          <el-table-column
                            width="100"
                            property="state_name"
                            label="状态"
                            align="center"
                          />
                          <el-table-column
                            width="150"
                            property="order_time"
                            label="供货时间"
                            align="center"
                          >
                            <template slot-scope="scope">
                              {{
                                scope.row["order_time"]
                                  | dateformat("YYYY-MM-DD HH:mm:ss")
                              }}
                            </template>
                          </el-table-column>
                          <el-table-column
                            width="150"
                            property="sold_time"
                            label="售出时间"
                            align="center"
                          >
                            <template slot-scope="scope">
                              <span v-if="!!scope.row['sold_time']">{{
                                scope.row["sold_time"]
                                  | dateformat("YYYY-MM-DD HH:mm:ss")
                              }}</span>
                              <span v-else>-</span>
                            </template>
                          </el-table-column>
                        </el-table>
                        <i
                          slot="reference"
                          class="el-icon-info"
                          style="font-size: 15px; cursor: pointer"
                        />
                      </el-popover>
                    </div>
                  </div>
                  <div
                    v-if="kehu.length != 0 && issale"
                    style="margin-left: 5px"
                  >
                    <span>{{ sends }}</span>
                    <el-popover placement="bottom" trigger="hover">
                      <el-table :data="tcbdatas">
                        <el-table-column
                          type="index"
                          width="50"
                          label="编号"
                          align="center"
                        />
                        <el-table-column
                          width="150"
                          property="imei"
                          label="IMEI"
                          align="center"
                        />
                        <el-table-column
                          width="120"
                          property="qc_code"
                          label="质检码"
                          align="center"
                        />
                        <el-table-column
                          width="100"
                          property="flag_name"
                          label="状态"
                          align="center"
                        />
                        <el-table-column
                          width="150"
                          property="pay_amount"
                          label="闲鱼定价"
                          align="center"
                        >
                          <!-- <template slot-scope="scope">
                              {{ scope.row['order_time'] | dateformat("YYYY-MM-DD HH:mm:ss") }}
                            </template> -->
                        </el-table-column>
                        <!-- <el-table-column width="150" property="sold_time" label="售出时间" align="center">
                            <template slot-scope="scope">
                              <span v-if="!!scope.row['sold_time']">{{ scope.row['sold_time'] | dateformat("YYYY-MM-DD HH:mm:ss") }}</span>
                              <span v-else>-</span>
                            </template>
                          </el-table-column> -->
                      </el-table>
                      <i
                        slot="reference"
                        class="el-icon-info"
                        style="font-size: 15px; cursor: pointer"
                      />
                    </el-popover>
                  </div>
                </div>
                <div
                  v-if="
                    Obj.DialogTitle == '添加销售' && item.label == '销售价格'
                  "
                  style="
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    width: 100%;
                  "
                >
                  <div>销售价格</div>
                  <div
                    v-if="
                      !ruleForm['pay_amount'] &&
                      ruleForm.is_sales_accessories == 0
                    "
                    style="margin-left: 20px"
                  >
                    <div
                      style="display: flex; align-items: center; color: #9aafc0"
                    >
                      <span
                        v-show="Obj ? (Obj.show == 0 ? false : true) : true"
                      >
                        <el-checkbox v-model="newcheck" @change="newcheckchange"
                          >预售</el-checkbox
                        >
                      </span>

                      <span
                        v-show="Obj ? (Obj.show == 0 ? false : true) : true"
                      >
                        <el-popover
                          placement="bottom"
                          trigger="click"
                          width="220"
                        >
                          <div>
                            <i
                              class="iconfont icontuihuanhuo"
                              style="
                                color: #009432;
                                font-size: 20px;
                                font-weight: bold;
                                margin-right: 5px;
                              "
                            />
                            <span>预售=无价格销售机器</span>
                          </div>
                          <span>
                            有价格后可手动回填价格，默认为系统自动回填价格</span
                          >
                          <i
                            slot="reference"
                            class="el-icon-info"
                            style="font-size: 15px; cursor: pointer"
                          />
                        </el-popover>
                      </span>
                    </div>
                  </div>
                </div>
                <div
                  v-if="
                    Obj.DialogTitle == '添加销售' &&
                    item.label == '采购回填价格'
                  "
                  style="
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    width: 100%;
                  "
                >
                  <div>采购回填价格</div>
                  <div>
                    <span>
                      采购参考价{{ rowDetails.consignment_reference_price }}
                    </span>
                  </div>
                </div>
                <div
                  v-if="
                    Obj.DialogTitle == '添加销售' && item.label == '快递单号'
                  "
                  style="
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                  "
                >
                  <div>快递单号</div>
                  <div
                    v-if="imei.zljshow || sloading"
                    style="margin-left: 20px"
                  >
                    {{ sloading }}
                    <div
                      v-if="loadinglist.codeloading2 == 1 || sloading"
                      style="display: flex; align-items: center; color: #9aafc0"
                    >
                      <i
                        class="el-icon-loading"
                        style="color: orange; font-size: 20px"
                      />
                      <span>自动查询中</span>
                    </div>
                    <div
                      v-else-if="
                        loadinglist.codeloading2 == 3 ||
                        loadinglist.codeloading2 == 2
                      "
                      style="display: flex; align-items: center"
                    >
                      <a
                        style="display: flex; align-items: center"
                        @click="getcode('kd')"
                      >
                        <i
                          class="el-icon-refresh-right"
                          style="
                            color: #9aafc0;
                            margin-left: 15px;
                            font-size: 20px;
                          "
                        />
                        <span style="color: #9aafc0">重新获取</span>
                      </a>
                    </div>
                  </div>
                </div>
                <div
                  v-if="
                    Obj.DialogTitle == '添加销售' &&
                    item.label == '第三方销售订单号'
                  "
                  style="
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                  "
                >
                  <div>第三方销售订单号</div>
                  <div
                    v-if="imei.zljshow || sloading"
                    style="margin-left: 20px"
                  >
                    <div
                      v-if="sloading"
                      style="display: flex; align-items: center; color: #9aafc0"
                    >
                      <i
                        class="el-icon-loading"
                        style="color: orange; font-size: 20px"
                      />
                      <span>自动查询中</span>
                    </div>
                    <!-- <div v-else-if="sloading" style="display:flex;align-items: center;">
                      <a style="display:flex;align-items: center;" @click="getcode('kd')">
                        <i class="el-icon-refresh-right" style="color:#9AAFC0;margin-left:15px;font-size:20px" />
                        <span style="color:#9AAFC0">重新获取</span>
                      </a>
                    </div> -->
                  </div>
                  <div
                    v-if="kehu.length != 0 && issale"
                    style="margin-left: 5px"
                  >
                    <span>{{ send }}</span>
                    <el-popover placement="bottom" trigger="hover">
                      <el-table :data="tcbdata">
                        <el-table-column
                          type="index"
                          width="50"
                          label="编号"
                          align="center"
                        />
                        <el-table-column
                          width="150"
                          property="imei"
                          label="IMEI"
                          align="center"
                        />
                        <el-table-column
                          width="120"
                          property="bizOrderId"
                          label="第三方条码"
                          align="center"
                        />
                        <el-table-column
                          width="100"
                          property="orderStatusName"
                          label="状态"
                          align="center"
                        />
                        <el-table-column
                          width="150"
                          property="payTime"
                          label="支付时间"
                          align="center"
                        >
                          <!-- <template slot-scope="scope">
                              {{ scope.row['order_time'] | dateformat("YYYY-MM-DD HH:mm:ss") }}
                            </template> -->
                        </el-table-column>
                        <!-- <el-table-column width="150" property="sold_time" label="售出时间" align="center">
                            <template slot-scope="scope">
                              <span v-if="!!scope.row['sold_time']">{{ scope.row['sold_time'] | dateformat("YYYY-MM-DD HH:mm:ss") }}</span>
                              <span v-else>-</span>
                            </template>
                          </el-table-column> -->
                      </el-table>
                      <i
                        slot="reference"
                        class="el-icon-info"
                        style="font-size: 15px; cursor: pointer"
                      />
                    </el-popover>
                  </div>
                </div>
              </template>
              <div style="display: flex">
                <el-input
                  v-if="
                    item.label == '销售价格' ||
                    item.label == '采购价格' ||
                    item.label == '支付金额' ||
                    item.label == '采购回填价格'
                  "
                  v-model="ruleForm[item.enName]"
                  :style="item.width"
                  :clearable="true"
                  :props="item.props"
                  :placeholder="item.placeholder"
                  :disabled="item.disabled"
                  :value="item.value"
                  @input="someinput(item)"
                  @blur="inputover(ruleForm)"
                />
                <div
                  :is="item.type"
                  v-else
                  v-model="ruleForm[item.enName]"
                  :placeholder="item.placeholder"
                  :value="item.value"
                  :style="item.width"
                  :format="item.format"
                  :type="item.TimeType"
                  :value-format="item.valueformat"
                  :clearable="true"
                  :filterable="item.filterable"
                  :disabled="item.disabled"
                  :allow-create="item.allowcreate"
                  :picker-options="item.pickerOptions"
                  :default-first-option="item.defaultfirstoption"
                  :multiple="item.multiple"
                  :props="item.props"
                  :name="item.name"
                  @change="
                    change(
                      item.enName,
                      ruleForm[item.enName],
                      Obj.DialogTitle,
                      item.label,
                      item.options,
                      item
                    )
                  "
                  @remove-tag="removetag"
                  @input="someinput(item)"
                >
                  <template
                    v-if="item.label === '条形码' && loadinglist.gridData"
                    slot="append"
                    >{{ loadinglist.gridData[0].degree_id_name }}</template
                  >
                  {{ item.name == "is_accessories" ? "" : item.name }}
                  <el-option
                    v-for="items in item.options"
                    :key="items.value"
                    :label="items.label"
                    :value="items.value"
                  >
                    <span v-if="item.label == '颜色'">
                      <span style="float: left">{{ items.label }}</span>
                      <el-popover placement="right" width="200" trigger="hover">
                        <img
                          v-if="items.img"
                          style="height: 200px"
                          :src="items.img"
                        />
                        <img
                          v-if="items.img"
                          slot="reference"
                          style="float: right; height: 34px"
                          :src="items.img"
                        />
                      </el-popover>
                    </span>
                  </el-option>
                </div>
              </div>
            </el-form-item>
          </el-col>
          <el-col>
            <el-row
              v-if="
                Obj.DialogTitle == '添加销售' &&
                (ruleForm.sales_type == 1 || ruleForm.sales_type == 3) &&
                ruleForm.is_sales_accessories == 0
              "
              style="margin-bottom: 5px"
              :gutter="10"
            >
              <span style="font-size: 16px">出库信息</span>
              <div>
                <el-col
                  v-for="(item, index) in outinput"
                  :key="index"
                  :span="item.span"
                >
                  <el-form-item
                    v-if="item.Typeshow"
                    :prop="item.prop"
                    :rules="{
                      required: item.required,
                      message: item.placeholder,
                      trigger: ['blur', 'change'],
                    }"
                    :label="item.label"
                  >
                    <template slot="label">
                      <span
                        v-if="
                          Obj.DialogTitle == '添加销售' &&
                          item.label == '快递单号'
                        "
                        style="
                          display: flex;
                          align-items: center;
                          justify-content: space-between;
                          width: 100%;
                        "
                      >
                        <div>快递单号</div>
                        <div
                          v-if="imei.zljshow || sloading"
                          style="margin-left: 20px"
                        >
                          <div
                            v-if="loadinglist.codeloading2 == 1 || sloading"
                            style="
                              display: flex;
                              align-items: center;
                              color: #9aafc0;
                            "
                          >
                            <i
                              class="el-icon-loading"
                              style="color: orange; font-size: 20px"
                            />
                            <span>自动查询中</span>
                          </div>
                          <div
                            v-else-if="
                              loadinglist.codeloading2 == 3 ||
                              loadinglist.codeloading2 == 2
                            "
                            style="display: flex; align-items: center"
                          >
                            <a
                              style="display: flex; align-items: center"
                              @click="getcode('kd')"
                            >
                              <i
                                class="el-icon-refresh-right"
                                style="
                                  color: #9aafc0;
                                  margin-left: 15px;
                                  font-size: 20px;
                                "
                              />
                              <span style="color: #9aafc0">重新获取</span>
                            </a>
                          </div>
                        </div>
                      </span>
                    </template>
                    <div
                      :is="item.type"
                      v-model="ruleForm[item.enName]"
                      :placeholder="item.placeholder"
                      :value="item.value"
                      :style="item.width"
                      :format="item.format"
                      :type="item.TimeType"
                      :value-format="item.valueformat"
                      :clearable="true"
                      :filterable="item.filterable"
                      :disabled="item.disabled"
                      :allow-create="item.allowcreate"
                      :picker-options="item.pickerOptions"
                      :default-first-option="item.defaultfirstoption"
                      :multiple="item.multiple"
                      :props="item.props"
                      :name="item.name"
                      @change="
                        change(
                          item.enName,
                          ruleForm[item.enName],
                          Obj.DialogTitle,
                          item.label,
                          item.options,
                          item.value
                        )
                      "
                      @remove-tag="removetag"
                    >
                      {{ item.name == "is_accessories" ? "" : item.name }}
                      <el-option
                        v-for="items in item.options"
                        :key="items.value"
                        :label="items.label"
                        :value="items.value"
                      />
                    </div>
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-col>
        </el-row>
        <span
          v-if="
            Obj.DialogTitle == '添加销售' &&
            ruleForm.sales_type == 1 &&
            ruleForm.is_sales_accessories == 0
          "
          style=""
        >
          <span style="font-size: 16px">赠送配件信息</span>
          <div class="accessclass">
            <el-form
              :inline="true"
              style="display: flex; width: 100%; justify-content: space-between"
              :model="accessform"
              label-width="70px"
            >
              <el-form-item label="搜索配件">
                <el-select
                  v-model="accessform.accessories"
                  size="mini"
                  :multiple="false"
                  filterable
                  remote
                  clearable
                  collapse-tags
                  placeholder="请输入关键词"
                  :remote-method="remoteMethod"
                  value-key="id"
                  @change="accesschange()"
                >
                  <el-option
                    v-for="(item, index) in accessform.accessoriesoptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="在库配件">
                <!-- <el-cascader
                  ref="refHandle"
                  v-model="accessform.phone_brand"
                  :options="searchoptions"
                  :props="searchprops"
                  size="mini"
                  style="width: 220px"
                  placeholder="请选择在库配件"
                  filterable
                  clearable
                  @change="jilianchange()"
                /> -->
                     <el-input size="mini"
                      style="width:220px"
                      @focus="accPopoverVisible = true"
                      :disabled="accPopoverVisible"
                      placeholder="查找在库配件"></el-input>

                   <AccPopover v-if="accPopoverVisible"
                        :accVisible="accPopoverVisible"
                        @setAccessor="setAccessorList"
                        @close="handclose" />
              </el-form-item>
            </el-form>
            <el-divider />
            <div>
              <div style="display: flex; justify-content: space-between">
                <label style="font-size: 12px; font-weight: 700"
                  >赠送配件列表</label
                >
                <label
                  style="
                    font-size: 12px;
                    font-weight: 700;
                    color: #2980b9;
                    cursor: pointer;
                  "
                  @click="addrepier()"
                  >+添加即购配件</label
                >
              </div>
              <el-row v-if="addrepiershow">
                <el-col
                  v-for="(r, i) in repair_customer"
                  :key="i"
                  :span="r.span"
                >
                  <el-col
                    v-for="(val, key, index) in r"
                    :key="index"
                    :span="val.span"
                    :class="val.class"
                  >
                    <el-form-item
                      :label="val.label"
                      :prop="val.prop"
                      :rules="{
                        required: val.required,
                        message: val.placeholder,
                        trigger: ['blur', 'change'],
                      }"
                    >
                      <div style="display: flex">
                        <div
                          :is="val.type"
                          v-model="temporaryObj[i][val.enName]"
                          :style="val.width"
                          :filterable="val.filterable"
                          :height="val.height"
                          :size="val.size"
                          clearable
                          :placeholder="val.placeholder"
                          @input="
                            val.enName == 'pay_amount'
                              ? (temporaryObj[i][val.enName] = AmountInput(
                                  temporaryObj[i][val.enName],
                                  2,
                                  'exceed'
                                ))
                              : () => {}
                          "
                        >
                          <el-option
                            v-for="(items, index) in val.options"
                            :key="index"
                            :label="items.label"
                            :value="items.value"
                            :res_id="items.value"
                          />
                        </div>
                        <i
                          style="font-size: 18px"
                          :class="val.Icon"
                          @click="operation(r, i, val.name)"
                        />
                      </div>
                    </el-form-item>
                  </el-col>
                </el-col>
              </el-row>
              <div>
                <!-- 配件表格 -->
                <el-table
                  :data="accessdata"
                  show-summary
                  :summary-method="getSummaries"
                >
                  <el-table-column
                    v-for="(items, index) in datalabel"
                    :key="index"
                    align="center"
                    :prop="items.prop"
                    :label="items.label"
                    :min-width="items.width"
                  >
                    <template slot-scope="scope">
                      <span v-if="items.label == '操作'">
                        <el-button
                          type="text"
                          size="small"
                          @click.native.prevent="
                            deleteRow(scope.$index, items.data)
                          "
                        >
                          移除
                        </el-button>
                      </span>
                      <span v-else-if="items.label == '数量'">
                        <el-input-number
                          v-model="scope.row.number"
                          style="width: 100px"
                          size="mini"
                          :min="1"
                          :max="scope.row.total"
                          @change="inputchange(scope.$index, scope.row)"
                        />
                      </span>
                      <span v-else> {{ scope.row[items.prop] }}</span>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
        </span>
        <el-form-item style="margin-top: 12px">
          <el-button @click="resetForm('ruleForm')">取消</el-button>
          <!-- <el-button @click="fromc">取1消</el-button> -->
          <el-button
            type="primary"
            :loading="loading"
            plain
            @click="submitForm('ruleForm', Obj.Button, Obj.DialogTitle)"
            >不清空确定</el-button
          >
          <el-button
            type="primary"
            :loading="loading"
            @click="submitForm('ruleForm', Obj.Button, Obj.DialogTitle, 1)"
            >{{ Obj.Button }}</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { save_User } from "@/api/Suppliermanagement";
import { get_xy_price_qc_code, third_party_sale_info } from "@/api/console";
import { get_xy_order_info } from "@/api/xy";
import { save } from "@/api/salesman";
import { purchase_back_amount } from "@/api/Jiqidetails";
import uploadImg from "@/components/Upload";
import AccPopover from "@/components/accessorySelection/accPopover";
import { zz_new_status, rollback_get_tracking } from "@/api/machineList"; // 获取列表信息接口
import {
  cate_brand_list_in_stock,
  search_accessories,
  accessories,
  res_advanced_search,
} from "@/api/Jiqidetails"; // 获取列表信息接口
import { get_accessories_cate_list } from "@/api/Warehousing"; // 获取客户信息接口
import Decimal from "decimal.js";
// import { AsyncLocalStorage } from 'async_hooks'
export default {
  components: {
    uploadImg,
    AccPopover
  },
  props: {
    p_user_id: {
      type: [Number, String],
      default: () => {
        return null;
      },
    },
    rowDetails: {
      type: Object,
      default: () => {
        return {};
      },
    },
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    loading: {
      type: Boolean,
      default: false,
    },
    list: {
      type: Array,
      default: () => {
        return [];
      },
    },
    tcblist: {
      type: Array,
      default: () => {
        return [];
      },
    },
    original: {
      type: Object,
      default: () => {
        return {};
      },
    },
    Obj: {
      type: Object,
      default: () => {
        return {};
      },
    },
    Obj_money: {
      type: Object,
      default: () => {
        return {};
      },
    },
    Input: {
      type: [Array, Object],
      default: () => {
        return [];
      },
    },
    imei: {
      type: Object,
      default: () => {
        return {};
      },
    },
    ruleForm: {
      type: Object,
      default: () => {
        return {};
      },
    },
    amount_money: {
      type: [Number, String],
      default: () => {
        return 0;
      },
    },
    Settlement_amount: {
      type: [Number, String],
      default: () => {
        return 0;
      },
    },
    pay_customer: {
      type: [Number, String],
      default: () => {
        return 0;
      },
    },
    /* 用户信息 二维码 银行卡*/
    user_info: {
      type: Object,
      default: () => {
        return {};
      },
    },
    res_advanced_search: {
      type: [String, Object, Array],
    },
  },
  data() {
    const that = this;
    return {
      is_interface: "",
      sloading: false,
      kehu: "",
      i: 0,
      account_class_code: null, // 客户类型
      newcheck: false,
      addrepiershow: false,
      outcheck: false,
      checked: false,
      tabPosition: "不使用预付款",
      radio1: "手机销售",
      outerVisible: false,
      innerVisible: false,
      outinput: [
        {
          label: "选择出库",
          enName: "is_outstorage",
          span: 6,
          width: "width:100%",
          Typeshow: true,
          type: "el-select",
          placeholder: "请选择出库",
          size: "mini",
          prop: "is_outstorage",
          required: true,
          filterable: true,
          options: [
            { label: "待出库", value: 1 },
            { label: "出库", value: 2 },
          ],
        },
        {
          label: "实际出库人",
          enName: "outstorage_user_id",
          span: 6,
          width: "width:100%",
          Typeshow: true,
          type: "el-select",
          placeholder: "请选择实际出库人",
          size: "mini",
          prop: "outstorage_user_id",
          required: false,
          filterable: true,
          options: [],
        },
        {
          label: "送货方式",
          enName: "shipping_method",
          span: 6,
          width: "width:100%",
          Typeshow: true,
          type: "el-select",
          placeholder: "请选择送货方式",
          size: "mini",
          prop: "shipping_method",
          required: false,
          filterable: true,
          options: [
            { label: "快递单", value: 1 },
            { label: "无需物流", value: 2 },
          ],
        },
        {
          label: "快递单号",
          enName: "tracking_num",
          span: 6,
          prop: "tracking_num",
          prop: "tracking_num",
          required: false,
          clearable: "clearable",
          Typeshow: true,
          type: "el-input",
          placeholder: "请填写快递单号",
          size: "mini",
          filterable: true,
        },
      ],
      actionUrl: "https://aiguovip2020.oss-cn-shenzhen.aliyuncs.com",
      Sales: {}, // 营业员对象
      DiaButton: { DialogTitle: "", Button: "" },
      // 临时数组
      temporaryObj: [
        {
          name: "",
          cate_name: "",
          is_original: "",
          pay_amount: "",
          number: "",
        },
      ],
      repair_customer: [
        {
          accessoriescustomers: {
            enName: "name",
            span: 4,
            disabled: false,
            Typeshow: true,
            prop: "name",
            width: "width:100%",
            clearable: "clearable",
            show: true,
            type: "el-select",
            placeholder: "选择客户",
            size: "mini",
            filterable: true,
            options: [],
          },
          accessoriesclassification: {
            enName: "cate_name",
            span: 4,
            disabled: false,
            prop: "cate_name",
            width: "width:100%",
            clearable: "clearable",
            show: true,
            type: "el-select",
            placeholder: "配件分类",
            size: "mini",
            filterable: true,
            options: [],
          },
          is_original: {
            enName: "is_original",
            span: 4,
            disabled: false,
            prop: "is_original",
            width: "width:100%",
            clearable: "clearable",
            show: true,
            type: "el-select",
            placeholder: "是否原厂",
            size: "mini",
            filterable: true,
            options: [
              { label: "原厂", value: 1 },
              { label: "非原厂", value: 2 },
            ],
          },
          accessoriesprice: {
            enName: "pay_amount",
            span: 4,
            disabled: false,
            prop: "pay_amount",
            width: "width:100%",
            clearable: "clearable",
            type: "el-input",
            placeholder: "配件价格",
            size: "mini",
            options: [],
          },
          number: {
            enName: "number",
            span: 4,
            disabled: false,
            prop: "number",
            width: "width:100%",
            clearable: "clearable",
            type: "el-input",
            placeholder: "配件数量",
            size: "mini",
          },
          add: {
            Icon: "el-icon-circle-check",
            span: 2,
            class: "IconClass",
            name: "add",
          },
          del: {
            Icon: "el-icon-circle-close",
            span: 2,
            class: "IconClass",
            name: "del",
          },
        },
      ],
      accessform: { accessories: "", accessoriesoptions: [] },
      accessdata: [],
      datalabel: [
        { label: "商品编号", prop: "serial_number" },
        { label: "供应商", prop: "name" },
        { label: "配件分类", prop: "cate_name" },
        { label: "是否原装", prop: "is_original" },
        { label: "价格", prop: "pay_amount" },
        { label: "数量", prop: "total", width: 120 },
        { label: "操作" },
      ],
      searchoptions: [],
      searchprops: {
        lazy: true,
        // checkStrictly:true,
        lazyLoad(node, resolve) {
          if (node.level == 0) {
            cate_brand_list_in_stock({
              p_user_id: that.p_user_id,
              is_accessories: 1,
            }).then((res) => {
              this.searchoptions = res.datas.map((res) => {
                return {
                  label: res.label,
                  value: res.value,
                  leaf: false,
                };
              });
              resolve(this.searchoptions);
            });
          } else if (node.level == 1) {
            cate_brand_list_in_stock({
              p_user_id: that.p_user_id,
              cate_id: node.value,
              is_accessories: 1,
            }).then((res) => {
              const ArrayData = res.datas.map((r) => {
                return {
                  label: r.label,
                  value: r.value,
                  leaf: false,
                };
              });
              resolve(ArrayData);
            });
          } else if (node.level == 2) {
            cate_brand_list_in_stock({
              p_user_id: that.p_user_id,
              cate_id: node.path[0],
              is_accessories: 1,
              brand_id: node.value,
            }).then((res) => {
              const ArrayData = res.datas.map((r) => {
                return {
                  label: r.label,
                  value: r.value,
                  leaf: false,
                };
              });
              resolve(ArrayData);
            });
          } else {
            accessories({
              p_user_id: that.p_user_id,
              cate_id: node.path[0],
              brand_id: node.parent.data.value,
              model_id: node.value,
            }).then((res) => {
              const ArrayData = res.datas.map((r) => {
                return {
                  label: `${r.serial_number} ${r.cate_name} ${r.product_name} ${r.name}  ${r.is_original} ${r.pay_amount}元  ${r.number}个`,
                  value: [
                    {
                      id: r.id,
                      cate_name: r.cate_name,
                      serial_number: r.serial_number,
                      product_name: r.product_name,
                      name: r.name,
                      pay_amount: r.pay_amount,
                      is_original: r.is_original,
                      total: r.number,
                      number: 1,
                    },
                  ],
                  leaf: true,
                };
              });
              resolve(ArrayData);
            });
          }
        },
      },
      rule: {},
      enName: "",
      num: 0,
      // 模态框输入框
      InputArr: [],
      options: [
        { label: "固定值", value: 1 },
        { label: "百分比", value: 2 },
      ],
      statusoptions: [
        { label: "正常", status: 0 },
        { label: "非正常", status: 1 },
      ],
      type: "",
      loadinglist: [],
      loadtcblist: [],
      isof: {},
      tcbdata: [],
      issale: false,
      send: "",
      sends: "",
      tcbdatas: [],
      accPopoverVisible:false
    };
  },
  computed: {
    // 把对象序列化
    pay_info() {
      return this.bank_info.pay_info
        ? JSON.parse(this.bank_info.pay_info)
        : {
            alipay: { qr_code: "", name: "" },
            wechat: { qr_code: "", name: "" },
            bank: { bank_no: "", name: "", kaihuhang: "" },
          };
    },
  },
  watch: {
    list: {
      handler(newVal, value) {
        if (newVal) {
          console.log(newVal);
          // this.$set(this.loadinglist,'',newVal)
          this.loadinglist = newVal;
          if (newVal.customer_barcode) {
            // this.$set(this.ruleForm,'barcode',newVal.customer_barcode)
          }
        }
      },
      deep: true,
      immediate: true,
    },
    tcblist: {
      handler(newVal, value) {
        if (newVal) {
          // this.$set(this.loadinglist,'',newVal)
          this.loadtcblist = newVal;
          if (newVal.customer_barcode) {
            // this.$set(this.ruleForm,'barcode',newVal.customer_barcode)
          }
        }
      },
      deep: true,
      immediate: true,
    },
    ruleForm: {
      handler(old, now) {
        this.$nextTick(() => {
          console.log(this.ruleForm);
        });
      },
      deep: true,
    },
    imei: {
      handler(newVal, value) {
        if (newVal) {
          if (newVal.zljshow) {
            this.$set(
              this.ruleForm,
              "barcode",
              this.loadinglist.customer_barcode
            );
            this.$set(
              this.ruleForm,
              "tracking_num",
              this.loadinglist.tracking_num
            );
            this.$set(
              this.ruleForm,
              "pay_amount",
              this.loadinglist.order_saled_settle_price
            );
          } else {
            this.$set(this.ruleForm, "tracking_num", "");
            this.$set(this.ruleForm, "barcode", "");
            this.$set(this.ruleForm, "pay_amount", "");
          }
        }
      },
      deep: true,
      immediate: true,
    },
    Obj: {
      handler(newVal, value) {
        if (newVal) {
          // console.log(newVal);
        }
      },
      deep: true,
      immediate: true,
    },
    Input: {
      handler() {
        console.log(this.Input);
      },
      deep: true,
    },
  },
  created() {
    if (this.$store.state.user.auto_outstorage == 1) {
      this.outinput.map((e) => {
        if (e.enName == "is_outstorage") {
          e.disabled = true;
          this.$set(this.ruleForm, "is_outstorage", 2);
        }
      });
    }
  },
  mounted() {
    this.getreslist();
  },
  destroyed() {},
  methods: {
    fromc() {
      // this.ruleForm={}
      this.kehu = "";
      this.issale = false;
      // this.Obj.DialogTitle=''
      this.$set(this.ruleForm, "purchase_price", "");
      this.$set(this.ruleForm, "customer_id", "");
      this.$set(this.ruleForm, "sales_type", "");
      this.$set(this.ruleForm, "three_sale_order_id", "");
      // this.$set(this.ruleForm, 'purchase_price', '')
      this.$set(this.ruleForm, "barcode", "");
      this.$set(this.ruleForm, "xy_amount", "");
      this.$set(this.ruleForm, "pay_amount", "");
      this.Input.forEach((v) => {
        if (v.label == "闲鱼定价") {
          v.Typeshow = false;
        }
      });

      // console.log(this.ruleForm);
    },
    getreslist() {
      // res_advanced_search().then((res) => {
      //   // console.log(res);
      //   this.outinput.map((r) => {
      //     for (const key in res.datas) {
      //       if (r.enName == 'outstorage_user_id') {
      //         r.options = res.datas['employees']
      //       }
      //     }
      //   })
      //   console.log(this.outinput,'1111111111111111111111');
      // })
      this.outinput.map((r) => {
        for (const key in this.res_advanced_search) {
          if (r.enName == "outstorage_user_id") {
            r.options = this.res_advanced_search["employees"];
          }
        }
      });
      console.log(this.outinput, "22222222222222222222");
    },
    someinput(v) {
      // console.log(this.Input, '7777777')
      console.log(v);
      if (v.pay_amount / 1 < this.rowDetails.consignment_reference_price / 1) {
        this.$message.error("您输入的价格低于采购参考价，请您三思");
      }
      if (v.enName == "pay_amount") {
        this.ruleForm[v.enName] = this.AmountInput(
          this.ruleForm[v.enName],
          2,
          "exceed"
        );
        const detail = this.$route.query.row;
        const obj = {
          sales_amount: this.ruleForm.pay_amount,
          res_id: detail,
        };
        this.Input.map((i) => {
          if (i.enName == "purchase_price" && i.Typeshow == true) {
            purchase_back_amount(obj).then((res) => {
              if (
                res &&
                res.errcode == 0 &&
                res.datas.pay_amount &&
                res.datas.pay_amount != ""
              ) {
                this.num = res.datas.pay_amount;
                this.$set(this.ruleForm, "purchase_price", this.num);
              }
            });
          }
        });
      }
      if (v.enName === "customer_id") {
        this.is_interface = "";
        let i = "";
        console.log(this.ruleForm);
        v.options.forEach((item) => {
          if (item.value === this.ruleForm.customer_id) {
            i = item.is_interface ? item.is_interface : 0;
          }
        });
        this.is_interface = i;
        console.log(i);
      }
    },
    inputover(v) {
      // console.log(666);
      // if(v.pay_amount/1<this.rowDetails.consignment_reference_price/1){
      //  this.$message.error('您输入的价格低于采购参考价，请您三思')
      // }
    },
    newcheckchange(val) {
      this.Input.map((e) => {
        if (e.label == "销售价格" || e.label == "收款状态") {
          if (val) {
            this.$set(e, "disabled", true);
            this.$set(e, "required", false);
            this.$set(this.ruleForm, e.enName, "");
          } else {
            this.$set(e, "disabled", false);
            this.$set(e, "required", true);
            this.$set(this.ruleForm, e.enName, "");
          }
        }
      });
    },
    // 添加即购配件显示
    addrepier(e) {
      this.addrepiershow = !this.addrepiershow;
    },
    inputchange(index, row) {
      this.$set(this.accessdata, index, row);
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        if (index === 4) {
          let a = 0;
          sums[index] = 0;
          data.map((e, index) => {
            a += Decimal(e.pay_amount).mul(Decimal(e.number)).toNumber();
          });
          sums[index] = a + "元";
        }
      });
      return sums;
    },
    // 添加采购配件
    operation(row, index, name) {
      if (name == "add") {
        const obj = {};
        const ValueObj = {};
        row.accessoriescustomers.options.map((res) => {
          if (res.value == this.temporaryObj[0].name) {
            obj.name = res.label;
            ValueObj.name = res.value;
          }
        });
        row.accessoriesclassification.options.map((res) => {
          if (res.value == this.temporaryObj[0].cate_name) {
            obj.cate_name = res.label;
            ValueObj.cate_name = res.value;
          }
        });
        row.is_original.options.map((res) => {
          if (res.value == this.temporaryObj[0].is_original) {
            obj.is_original = res.label;
            ValueObj.is_original = res.value;
          }
        });
        obj.pay_amount = this.temporaryObj[0].pay_amount;
        // obj.number = this.temporaryObj[0].number
        this.$set(obj, "number", this.temporaryObj[0].number);
        if (!obj.cate_name) {
          this.$message({ type: "warning", message: "请选择配件分类" });
        } else {
          this.accessdata.push(obj);
          this.isof[this.accessdata.length - 1] = ValueObj;
          this.addrepiershow = false;
        }
      } else {
        this.addrepiershow = false;
      }
    },
    // 清除表格数据事件
    deleteRow(index, rows) {
      this.accessdata.splice(index, 1);
      if (this.accessform.accessories != "") {
        this.accessform.accessories.splice(index, 1);
      }
    },
    // 输入商品编号模糊搜索
    remoteMethod(query) {
      if (query !== "") {
        const obj = { serial_number: query };
        search_accessories(obj).then((res) => {
          const o = [];
          res.datas.map((r, i) => {
            o.push({
              label: `${r.serial_number} ${r.cate_name} ${r.product_name} ${r.name}  ${r.is_original} ${r.pay_amount}元  ${r.number}个`,
              value: {
                id: r.id,
                cate_name: r.cate_name,
                serial_number: r.serial_number,
                product_name: r.product_name,
                name: r.name,
                pay_amount: r.pay_amount,
                is_original: r.is_original,
                total: r.number,
                number: 1,
              },
            });
          });
          this.accessform.accessoriesoptions = o;
        });
      } else {
        this.accessform.accessoriesoptions = [];
      }
    },
    // 获取维修方/采购配件客户
    getweixiufang(accesscatelist, res) {
      this.repair_customer.map((r) => {
        r.accessoriesclassification.options = accesscatelist; // 给采购配件分类赋值
        r.accessoriescustomers.options = res.datas.supplier_info; // 给采购配件客户赋值
      });
    },
    // 获取配件分类
    async getaccessorieslist() {
      const res = await get_accessories_cate_list({
        p_user_id: this.p_user_id,
      });
      const Obj = [];
      res.datas.map((e) => {
        Obj.push({
          label: e.cate_name,
          value: e.id,
        });
      });
      this.repair_customer.map((r) => {
        r.accessoriesclassification.options = Obj; // 给采购配件分类赋值
      });
    },
    setAccessorList(data) {
      data.forEach((obg) => {
        obg.number = 1
        this.accessoriesexist(obg)
      })
    },
    // 级联选择
    jilianchange(row) {
      let obj = {};
      this.accessform.phone_brand = Array(this.accessform.phone_brand);
      this.accessform.phone_brand.map((res) => {
        obj = res[3][0];
      });
      this.accessoriesexist(obj);
      this.accessform.phone_brand = [];
    },
    // 判断配件是否存在
    accessoriesexist(val) {
      const obj = [];
      if (this.accessdata !== undefined && this.accessdata.length > 0) {
        this.accessdata.forEach((item, index) => {
          obj.push(item.serial_number);
        });
        if (obj.indexOf(val.serial_number) != -1) {
          // 存在就提示不添加
          this.$message.error("已选择该配件，请不要重复添加");
        } else {
          this.accessdata.push(val);
        }
      } else {
        this.accessdata.push(val);
      }
    },
    getcode(v) {
      const e = this.imei;
      console.log(v);
      console.log(this.ruleForm);
      console.log(this.rowDetails);
      if (e.account && e.account.length != 0) {
        const Obj = {
          imei: e.imei1,
          imei2: e.imei2,
          account: e.account,
          sn: e.sn,
        };
        third_party_sale_info({
          res_id: this.rowDetails.id,
          customer_id: this.ruleForm.customer_id,
        }).then((res) => {
          console.log(res);
          if (v == "code") {
            this.$set(this.loadinglist, "codeloading", 1);
            if (res.errcode == 0 && res.datas.length != 0) {
              this.$set(this.loadinglist, "gridData", res.datas.sold_data);
              this.$set(
                this.loadinglist,
                "customer_barcode",
                res.datas.sold_data[0].qc_code
              );
              this.$set(
                this.ruleForm,
                "barcode",
                res.datas.sold_data[0].qc_code
              );
              this.$set(this.loadinglist, "codeloading", 2);
              this.$set(
                this.loadinglist,
                "state_name",
                res.datas.sold_data[0].state_name
              );
              this.$set(
                this.loadinglist,
                "sold_time",
                res.datas.sold_data[0].sold_time
              );
              this.$set(
                this.loadinglist,
                "order_time",
                res.datas.sold_data[0].order_time
              );
            } else {
              this.$set(this.loadinglist, "codeloading", 3);
            }
          } else {
            if (res.errcode === 0) {
              if (res.datas.logistics_num) {
                this.$set(this.loadinglist, "codeloading2", 2);
                this.$set(
                  this.loadinglist,
                  "tracking_num",
                  res.datas.logistics_num
                );
                this.$set(
                  this.ruleForm,
                  "tracking_num",
                  res.datas.logistics_num
                );
                this.$set(this.ruleForm, "is_outstorage", 2);
                this.$set(this.ruleForm, "shipping_method", 1);
              } else {
                this.$set(this.loadinglist, "codeloading2", 3);
              }
              if (res.datas.settle_price) {
                this.$set(this.loadinglist, "codeloading3", 2);
                this.$set(
                  this.loadinglist,
                  "order_saled_settle_price",
                  res.datas.settle_price
                    ? (res.datas.settle_price / 100).toFixed(2)
                    : ""
                );
              } else {
                this.$set(this.loadinglist, "codeloading3", 3);
              }
              this.$set(
                this.ruleForm,
                "three_sale_order_id",
                res.datas.order_id
              );
            }
          }
        });
        // if (v == 'code') {
        //   this.$set(this.loadinglist, 'codeloading', 1)
        //   // console.log(Obj);
        //   // console.log(this.rowDetails);
        //   zz_new_status(Obj).then(async(res) => {
        //     if (res.errcode == 0 && res.datas.length != 0) {
        //       this.$set(this.loadinglist, 'gridData', res.datas)
        //       this.$set(this.loadinglist, 'customer_barcode', res.datas[0].qc_code)
        //       this.$set(this.ruleForm, 'barcode', res.datas[0].qc_code)
        //       this.$set(this.loadinglist, 'codeloading', 2)
        //       await this.$set(this.loadinglist, 'state_name', res.datas[0].state_name)
        //       this.$set(this.loadinglist, 'order_time', res.datas[0].order_time)
        //       this.$set(this.loadinglist, 'sold_time', res.datas[0].sold_time)
        //     } else {
        //       this.$set(this.loadinglist, 'codeloading', 3)
        //     }
        //   })
        // } else {
        //   this.$set(this.loadinglist, 'codeloading2', 1)
        //   rollback_get_tracking({ imei: e.imei1, imei2: e.imei2, qc_code: this.ruleForm.barcode, sn: this.rowDetails.sn }).then((res) => {
        //     if (res.datas[0].datas[0].logisticsNum) {
        //       this.$set(this.loadinglist, 'codeloading2', 2)
        //       this.$set(this.loadinglist, 'tracking_num', res.datas[0].datas[0].logisticsNum)
        //       this.$set(this.ruleForm, 'tracking_num', res.datas[0].datas[0].logisticsNum)
        //       this.$set(this.ruleForm, 'is_outstorage', 2)
        //       this.$set(this.ruleForm, 'shipping_method', 1)
        //     } else {
        //       this.$set(this.loadinglist, 'codeloading2', 3)
        //     }
        //     if (res.datas[0].datas[0].settlePrice) {
        //       this.$set(this.loadinglist, 'codeloading3', 2)
        //       this.$set(this.loadinglist, 'order_saled_settle_price', (res.datas[0].datas[0].settlePrice / 100).toFixed(2))
        //     } else {
        //       this.$set(this.loadinglist, 'codeloading3', 3)
        //     }
        //     this.$set(this.ruleForm, 'three_sale_order_id', res.datas[0].datas[0].orderId)
        //   })
        // }
      }
    },
    // 在对话框打开时候使用resetFields方法移除表单的校验
    clearcheck() {
      if (this.$refs["ruleForm"]) {
        this.$refs["ruleForm"].clearValidate();
      }
    },
    Reexamination() {
      this.$emit("Reexamination");
    },
    // 销售信息单选框
    radio_change(val) {
      this.$emit("radio_change", val);
      this.fromc();
    },
    input(e) {
      this.$forceUpdate();
    },
    accesschange(val) {
      this.accessoriesexist(this.accessform.accessories);
      this.accessform.accessories = "";
      this.accessform.accessoriesoptions = [];
    },
    change(enName, e, DialogTitle, label, options, v) {
      console.log(this.ruleForm);
      console.log(enName);
      console.log(e);
      console.log(options);
      console.log(label);
      // console.log(options,);
      // console.log(v,);
      if (e == 887 && enName == "customer_id") {
        this.kehu = "tcb";
      } else if (e != 887 && enName == "customer_id") {
        this.kehu = "";
      }
      if (this.kehu == "tcb" && label == "销售类型") {
        if (e == 1) {
          this.sloading = true;
          this.issale = true;
          const obj = {
            imei: [this.rowDetails.imei1],
            // imei:[863323048319133]
          };
          console.log(obj);
          get_xy_price_qc_code(obj).then((res) => {
            // console.log(res);
            if (res.errcode == 0) {
              this.sloading = false;
              //  console.log(res);
              if (res.datas) {
                this.$set(this.ruleForm, "xy_amount", res.datas[0].pay_amount);

                this.$set(this.ruleForm, "barcode", res.datas[0].qc_code);
                this.tcbdatas = res.datas;
                this.sends = res.datas[0].flag_name;
              }
            }
          });
          get_xy_order_info(obj).then((res) => {
            if (res.errcode == 0) {
              this.$set(
                this.ruleForm,
                "three_sale_order_id",
                res.datas[0].bizOrderId
              );
              this.$set(this.ruleForm, "pay_amount", res.datas[0].payment);
              this.$set(this.ruleForm, "tracking_num", res.datas[0].expressNo);
              this.$set(this.ruleForm, "shipping_method", 1);
              this.tcbdata = res.datas;
              this.send = res.datas[0].orderStatusName;
            }
          });
        } else if (e == 2) {
          this.issale = false; // 只有在销售才显示
          this.sloading = true;
          const obj = {
            imei: [this.rowDetails.imei1],
            // imei:[863323048319133]
          };
          console.log(obj);
          get_xy_price_qc_code(obj).then((res) => {
            // console.log(res);
            if (res.errcode == 0) {
              this.sloading = false;
              //  console.log(res);
              this.$set(this.ruleForm, "xy_amount", res.datas[0].pay_amount);
              this.$set(this.ruleForm, "barcode", res.datas[0].qc_code);
              this.tcbdatas = res.datas;
              this.sends = res.datas[0].flag_name;
              // console.log( this.tcbdatas);
              // console.log( this.sends);
            }
          });
        }
      }
      if (enName == "is_outstorage") {
        this.outinput.map((k) => {
          if (k.enName == "shipping_method") {
            e == 2
              ? this.$set(k, "required", true)
              : this.$set(k, "required", false);
          }
        });
      }
      // if (enName=='shipping_method') {
      //   this.outinput.map(k=>{
      //     if (k.enName=='tracking_num') {
      //       e==1 ? this.$set(k,'required',true) : this.$set(k,'required',false)
      //     }
      //   })
      // }
      if (DialogTitle == "添加销售") {
        if (Array.isArray(options) && enName == "customer_id") {
          options.map((r) => {
            if (e == r.value) {
              this.account_class_code = r.account_class_code;
            }
          });
          console.log(this.account_class_code);
        }
        // this.account_class_code = '' //客户类别
        if (enName == "sales_type") {
          // console.log(6);
          this.newcheck = false;
          this.newcheckchange(false);
          if (e == 1 || e == 3) {
            this.Input.map((k) => {
              if (k.enName == "outstorage_user_id") {
                this.$set(this.outinput[1], "options", k.options);
              }
            });
          }
        }
        console.log(this.account_class_code);
        this.$emit("hide", {
          enName: enName,
          e: e,
          DialogTitle: DialogTitle,
          is_interface: this.is_interface,
          row: this.ruleForm,
          label: label,
          account_class_code: this.account_class_code,
        });
      } else {
        this.$emit("hide", {
          enName: enName,
          e: e,
          DialogTitle: DialogTitle,
          is_interface: this.is_interface,
          row: this.ruleForm,
          label: label,
        });
      }
    },
    focus(row, item) {
      this.$emit("Selectfocus", { row: row, item: item });
    },
    tabclick(value) {
      this.$emit("surplus_money", {
        tabPosition: this.tabPosition,
        actual_Settlement_amount: this.actual_Settlement_amount,
      });
    },
    submitForm(formName, name, DialogTitle, clear) {
      // console.log(formName);
      // console.log(this.ruleForm);
      if (
        this.ruleForm.is_sales_accessories == 0 &&
        this.ruleForm.sales_type == 1
      ) {
        // 手机且销售状态时赠送配件
        const aa = [...this.accessdata];
        this.ruleForm.accessories_info = [];
        aa.forEach((e, i) => {
          if (e["serial_number"] == undefined) {
            this.ruleForm.accessories_info.push({
              accessoriescustomers: this.isof[i]["name"],
              accessoriesclassification: this.isof[i]["cate_name"],
              is_original: this.isof[i]["is_original"],
              accessoriesprice: e.pay_amount,
              accessoriesname: e.cate_name + e.is_original,
              number: e.number,
            });
          }
        });
        this.ruleForm.accessories_res_id = []; // 在库配件的id数组
        this.accessdata.map((res) => {
          if (res.id) {
            this.ruleForm.accessories_res_id.push({
              id: res.id,
              number: res.number,
            });
          }
        });
      }
      this.$refs[formName].validate((valid, obj) => {
        if (valid) {
          if (this.ruleForm.price && this.ruleForm.textarea_price) {
            this.$message({
              type: "warning",
              message: "填写一个即可,禁止填写两个",
            });
            return;
          }
          if (this.ruleForm.remark && this.ruleForm.textarea_remark) {
            this.$message({
              type: "warning",
              message: "填写一个即可,禁止填写两个",
            });
            return;
          }
          if (this.ruleForm.grade_list && this.ruleForm.textarea_grade_list) {
            this.$message({
              type: "warning",
              message: "填写一个即可,禁止填写两个",
            });
            return;
          }
          // console.log(111);
          this.$emit("save", {
            row: this.ruleForm,
            original: this.original,
            tabPosition: this.tabPosition,
            checked: this.checked,
            name: name,
            DialogTitle: DialogTitle,
            newcheck: this.newcheck,
            clear: clear,
          });

          // console.log( this.ruleForm);
          // console.log(222);
          this.issale = false;
          this.Input.forEach((v) => {
            if (v.label == "闲鱼定价") {
              v.Typeshow = false;
            }
          });
          this.tabPosition = "不使用预付款";
          this.$emit("update:dialogVisible", false);
        } else {
          return false;
        }
      });
    },
    resetForm() {
      console.log(1);
      this.accessdata = [];
      this.tabPosition = "不使用预付款";
      this.$emit("colse");
      this.$emit("update:dialogVisible", false);
      this.$set(this.ruleForm, "purchase_price", "");
    },
    close() {
      this.tabPosition = "不使用预付款";
      this.$emit("colse");
      this.$emit("update:dialogVisible", false);
      this.$set(this.ruleForm, "purchase_price", "");
    },
    // 子组件上传图片成功 返回地址
    UrlImg(data) {
      this.$emit("img", data);
    },
    addsave(data) {
      if (data.Sales == "Sales") {
        save(data.row).then((res) => {
          this.$emit("update");
        });
      } else {
        save_User(data.row).then((res) => {});
      }
    },
    addplus() {
      this.Sales.brokerage.push({ range: [], type: "", value: "" });
    },
    del(data) {
      this.$delete(this.Sales.brokerage, data);
    },
    ImgSrc(data) {
      if (data.type == "alipay") {
        this.rule.pay_info.alipay.qr_code = data.imageUrl;
      } else {
        this.rule.pay_info.wechat.qr_code = data.imageUrl;
      }
    },
    // 多选模式下移除Tag触发
    removetag(r) {
      this.$emit("removetag", r);
    },
    //  关闭
    handclose() {
      this.accPopoverVisible = false
    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .el-dialog {
  margin-bottom: 200px;
  .el-dialog__footer {
    padding: 20px !important;
  }
}
.el-divider--horizontal {
  margin: 0;
}
.fonticon {
  color: #fff;
  padding: 0px 15px;
  font-size: 24px;
  position: relative;
  top: 5px;
}
.fontcont {
  padding: 0px 15px;
  font-size: 24px;
}
.IconClass {
  display: flex;
  display: -webkit-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  top: 10px;
}
.Font {
  font-size: 20px;
}
.content ::v-deep .el-dialog__body {
  padding: 0px 20px 20px 20px;
}
.content ::v-deep .el-form-item {
  margin-bottom: 0px;
}
.content ::v-deep .el-form-item__error {
  font-size: 0px;
}
.content ::v-deep .el-form-item__label {
  display: flex;
  width: 100%;
  padding: 0px;
}
.pay_info {
  span {
    padding: 0 20px 0 0;
  }
}
.accessclass {
  width: 100%;
  border: 1px solid #ebeef5;
  padding: 10px;
  font-size: 14px;
}
.accessclass ::v-deep .el-form-item {
  margin-bottom: 0px;
}
</style>
