<template>
  <div class="OMSOrderVTPolicy">
    <div class="quickOperation" data-key="ORDER_TURN_PRO">
      快捷操作：
      <Button type="fcdefault" style="margin-right: 8px" @click="saveAll">
        保存
      </Button>
      <Button
        type="fcdefault"
        style="margin-right: 8px"
        v-if="pageMsgId != 'New'"
        @click="refreshParams"
        >刷新</Button
      >
      <Button type="fcdefault" @click="backToList"> 返回 </Button>
    </div>
    <div class="content">
      <div v-for="(item, tabId) in tabList" :key="tabId" class="block">
        <foldPanel
          v-model="item.blockShow"
          :title="item.tabtext"
          :explain="item.explainText"
        >
          <div slot="content" class="block">
            <div class="item">
              <Row>
                <div
                  v-for="(i, cindex) in tabList[tabId].list"
                  :key="cindex"
                  class="form"
                >
                  <Col
                    span="6"
                    v-if="i.display"
                    :style="i.type == 'checkBox' ? 'margin-top: 10px' : ''"
                  >
                    <div
                      v-if="i.title"
                      :data-key="i.SKEY"
                      :class="{
                        title: true,
                        'order-setting-input-error': i.required,
                      }"
                    >
                      {{ i.title }}
                      <Tooltip
                        max-width="300"
                        :content="i.explainContent"
                        placement="bottom"
                      >
                        <img
                          v-if="i.explain"
                          class="img-framelanflag"
                          src="../../../assets/icon/help.png"
                        />
                      </Tooltip>
                    </div>
                    <DatePicker
                      v-if="i.SKEY == 'STARTDATE' || i.SKEY == 'ENDDATE'"
                      type="datetime"
                      v-model="i.VALUE"
                      format="yyyy-MM-dd HH:mm:ss"
                      :vModelFormat="vModelFormat"
                      placeholder="请选择时间"
                      style="width: 100%; max-width: 400px; min-width: 180px"
                      transfer
                      clearable
                      @on-change="rangeDate"
                    ></DatePicker>
                    <arkDropMultiSelectFilter
                      ref="arkDropMultiSelectFilter"
                      class="shopDropMultiSelectFilter"
                      :class="i.errorBox ? 'errorFormBox' : ''"
                      v-model="dropDownShopValue"
                      v-else-if="i.SKEY == 'IES_SHOP_ID'"
                      :props-data="propsData"
                      :url="Url"
                      :table-request="TableRequest"
                      :http="network"
                      @on-change="DropShopvalueChange"
                      @on-clear="ClearDropShopvalue"
                    ></arkDropMultiSelectFilter>
                    <Input
                      v-else-if="
                        i.SKEY == 'POLICY_NAME' ||
                        i.SKEY == 'OWNERNAME' ||
                        i.SKEY == 'CREATIONDATE' ||
                        i.SKEY == 'MODIFIERNAME' ||
                        i.SKEY == 'MODIFIEDDATE'
                      "
                      class="input_box"
                      :class="i.errorBox ? 'errorFormBox' : ''"
                      v-model="i.VALUE"
                      :placeholder="
                        i.SKEY == 'POLICY_NAME' ? '请输入策略名称' : ''
                      "
                      :disabled="i.disabled"
                      @on-keypress="noSpaces($event, i)"
                    />
                    <Input
                      v-else-if="
                        i.SKEY == 'NOCVT_CHANNEL_NAME' ||
                        i.SKEY == 'KEY' ||
                        i.SKEY == 'SKU'
                      "
                      v-model="i.VALUE"
                      style="width: 100%"
                      type="textarea"
                      :rows="2"
                      :placeholder="i.placeholder"
                    />
                    <Checkbox
                      v-else-if="
                        i.SKEY == 'TMSELFORDER' ||
                        i.SKEY == 'JDORDER' ||
                        i.SKEY == 'TBORDER' ||
                        i.SKEY == 'DWORDER' ||
                        i.SKEY == 'MJORDER' ||
                        i.SKEY == 'WMORDER' ||
                        i.SKEY == 'ALLORDER' ||
                        i.SKEY == 'SHIPPED_PDD_LOCALORDER'||
                        i.SKEY == 'YOUZAN_BEFORE_PAYMENT'
                      "
                      v-model="i.VALUE"
                    ></Checkbox>
                  </Col>
                </div>
              </Row>
            </div>
          </div>
        </foldPanel>
      </div>
    </div>
    <Modal
      v-model="showTip"
      mask
      :mask-closable="maskClosable"
      title="警告"
      title-align="left"
      class-name="showTipModel"
      width="400px"
      @on-ok="closePage"
    >
      <p>
        <i
          class="iconfont iconbj_doubt fcWarning"
        />修改的数据未保存，确定返回？
      </p>
    </Modal>
  </div>
</template>
  <script>
import foldPanel from "../../customizedContent/FoldPanel.vue"; // 折叠面板组件
import ShrinkOrExtend from "../../customizedContent/shrinkOrExtend"; //收缩伸展搜索条件组件
import tableFaker from "../../customizedContent/tableFaker.vue"; //表格组件
import strategyMixin from "./mixins/monitorStrategy";

const R3 = window.R3;
const { network, urlSearchParams, store } = R3;
export default {
  mixins: [strategyMixin],

  data() {
    return {
      tabName: "name1",
      selectReturnSKUID: "", //策略明细sku下拉框双向数据绑定

      regx: /^(0|100|([1-9][0-9]?)|(0|[1-9][0-9]?)(?:\.\d{0,2}))?$/, // 0-100带两位小数的正数
      regx1: /^\d{0,15}(\.[0-9]{0,2})?$/, // 两位小数的正数
      vModelFormat: true,
      tabList: [
        {
          tabId: "1",
          tabtext: "基本信息",
          blockShow: true,
          list: [
            {
              ID: "",
              SKEY: "POLICY_NAME",
              title: "策略名称",
              display: true,
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: true, // 是否为必填项
              explain: false, //是否有解释
              errorBox: false,
            },
            {
              ID: "T_V_IESSHOP",
              SKEY: "IES_SHOP_ID",
              title: "参与店铺",
              display: true,
              VALUE: "",
              defaultvalue: "",
              company: "",
              tips: "",
              clearable: true,
              disabled: false,
              flag: true, // 控制必填校验样式展示
              required: true, // 是否为必填项
              standard: true, //标准输入框长度
              optionList: [],
              errorBox: false,
            },
            {
              SKEY: "STARTDATE",
              title: "付款开始时间",
              VALUE: "",
              display: true,
              defaultvalue: "",
              company: "",
              tips: "",
              disabled: false,
              required: false, // 是否为必填项
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              explain: true, //是否有解释
              explainContent:
                "仅付款时间范围在此处设置的付款开始时间至结束时间之内的订单，才执行该条策略", //解释文字
            },
            {
              SKEY: "ENDDATE",
              title: "付款结束时间",
              display: true,
              VALUE: "",
              defaultvalue: "",
              company: "",
              tips: "",
              disabled: false,
              required: false, // 是否为必填项
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
            },
          ],
        },
        {
          tabId: "2",
          tabtext: "转换过滤条件（订单符合条件将不转换）",
          blockShow: true,
          list: [
            {
              ID: "",
              SKEY: "NOCVT_CHANNEL_NAME",
              title: "渠道来源名称",
              display: true,
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "若订单来源渠道属于此处维护的渠道，订单不转换进订单管理", //解释文字
              placeholder: "请输入渠道名称，多个用英文逗号/英文分号/空格分隔",
            },
          ],
        },
        {
          tabId: "3",
          tabtext:
            "已发货订单转换（订单符合任一条件，仅已发货/已完成状态才转换进订单管理，走分仓流程，自动变成平台发货状态）",
          blockShow: true,
          list: [
            {
              ID: "",
              SKEY: "JDORDER",
              title: "京仓订单",
              display: true,
              type: "checkBox",
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "勾选后，使用京仓发货的订单，京仓出库后，已发货状态的订单会转入订单管理，分给勾选“京仓”的实体仓，直接变成平台发货状态", //解释文字
            },
            // {
            //   ID: '',
            //   SKEY: 'TBORDER',
            //   title: '菜鸟仓订单',
            //   display: true,
            //   type: 'checkBox',
            //   VALUE: '',
            //   company: '',
            //   tips: '',
            //   disabled: false,
            //   standard: true,//标准输入框长度
            //   flag: true, // 控制必填校验样式展示
            //   required: false, // 是否为必填项
            //   explain: true, //是否有解释
            //   explainContent: '勾选后，使用菜鸟仓发货的订单，菜鸟仓出库后，已发货状态的订单会转入订单管理，分给勾选“菜鸟仓”的实体仓，直接变成平台发货状态',//解释文字
            // },
            {
              ID: "",
              SKEY: "MJORDER",
              title: "喵街销售单",
              display: true,
              type: "checkBox",
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "勾选后，喵街非商家仓发货的专柜履约订单，会转入订单管理分仓，直接变成平台发货状态", //解释文字
            },
            {
              ID: "",
              SKEY: "DWORDER",
              title: "得物入仓订单",
              display: true,
              type: "checkBox",
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "勾选后，使用得物仓发货的订单，得物仓出库后，已发货状态的订单会转入订单管理分仓，直接变成平台发货状态", //解释文字
            },
            {
              ID: "",
              SKEY: "WMORDER",
              title: "微盟门店交易订单",
              display: true,
              type: "checkBox",
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "勾选后，到店交易无需发货的订单，会转换进订单管理分给云仓，直接变成平台发货状态", //解释文字
            },
            {
              ID: "",
              SKEY: "SHIPPED_PDD_LOCALORDER",
              title: "拼多多本地仓订单",
              display: false,
              type: "checkBox",
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "勾选后，使用拼多多本地仓发货的订单，本地仓出库后，已发货状态的订单会转入订单管理分仓，直接变成平台发货状态", //解释文字
            },
            {
              ID: "",
              SKEY: "ALLORDER",
              title: "全部订单",
              display: true,
              type: "checkBox",
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "勾选后，策略店铺下仅已发货状态订单，才会转换进订单管理分仓，直接变成平台发货状态", //解释文字
            },
            {
              ID: "",
              SKEY: "YOUZAN_BEFORE_PAYMENT",
              title: "有赞寄售单",
              display: false,
              type: "checkBox",
              VALUE: false,
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "勾选后，有赞寄售业务的订单，已发货状态的订单会转入订单管理分仓，直接变成平台发货状态", //解释文字
            },
          ],
        },
        {
          tabId: "4",
          tabtext:
            "已发货转未发货（订单符合任一条件，已发货/已完成状态的订单，会转换进订单管理走正常发货流程）",
          blockShow: true,
          list: [
            {
              ID: "",
              SKEY: "TMSELFORDER",
              title: "天猫自提订单",
              type: "checkBox",
              display: true,
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "勾选后，被识别为天猫自提的订单（ shop_pick字段有值），将会转换进订单管理，执行正常的分仓发货流程", //解释文字
            },
            {
              ID: "",
              SKEY: "KEY",
              title: "商品关键字",
              display: true,
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "若订单中商品全部包含此处维护的关键字，已发货/已完成状态的订单也会转换进订单管理变为未发货状态，执行正常的分仓发货流程", //解释文字
              placeholder: "请输入商品关键字，多个用英文逗号/英文分号/空格分隔",
            },
            {
              ID: "",
              SKEY: "SKU",
              title: "参与sku",
              display: true,
              VALUE: "",
              company: "",
              tips: "",
              disabled: false,
              standard: true, //标准输入框长度
              flag: true, // 控制必填校验样式展示
              required: false, // 是否为必填项
              explain: true, //是否有解释
              explainContent:
                "若订单中商品全部是此处维护的sku，已发货/已完成状态的订单也会转换进订单管理变为未发货状态，执行正常的分仓发货流程", //解释文字
              placeholder: "请输入sku，多个用英文逗号/英文分号/空格分隔",
            },
          ],
        },
      ],

      // 选择商品
      mask: true,
      closable: true,
      maskClosable: false,
      hideFoot: true,
      shrinkHeight: "58px",
      currentValue: false, //默认收缩

      showTip: false,
      startTime: "", // 活动开始时间
      endTime: "", // 活动结束时间

      shopTrue: {
        shopData: {}, //店铺下拉数据
        currentIndex: 0, //当前也从第几条索引开始
        dataEmptyMessage: "数据加载中...", // 无数据的提示
        columnsShop: ["name", "value"], // 店铺数据展现的组
        AutoDataShop: [], //店铺模糊搜索数据
        defaultSelected: [], //编辑页面默认值
      },
      dropDownShopValue: "",
      network,
      propsData: {
        pageSize: 10,
        item: {},
      },
      TableRequest: {
        isdroplistsearch: true,
        refcolid: 202934,
      },
      eventFun: {
        "on-blur": (even) => {
          setTimeout(() => {
            if (!Array.isArray(this.dropDownShopValue)) {
              even.target.value = "";
              this.$emit("change", []);
            }
          }, 200);
        },
      },
      Url: {
        autoUrl: "/p/cs/fuzzyquerybyak",
        tableUrl: "p/cs/QueryList",
        tableSearchUrl: "/p/cs/newQueryList",
      },
      platformIds: [],
      oldBaseMsg: {},
    };
  },
  components: {
    foldPanel,
    ShrinkOrExtend,
    tableFaker,
  },
  created() {
    this.pageMsgId = window.parent.vm._route.params.customizedModuleId;
    this.getQuery("T_V_IESSHOP", { isactive: ["=Y"] }); // 初始查询店铺名称列表

    if (this.pageMsgId != "New") {
      let obj = {
        tabId: "4",
        tabtext: "日志",
        blockShow: true,
        list: [
          {
            ID: "",
            SKEY: "OWNERNAME",
            title: "创建人",
            display: true,
            VALUE: "",
            company: "",
            tips: "",
            disabled: true,
            standard: true, //标准输入框长度
            flag: true, // 控制必填校验样式展示
            required: true, // 是否为必填项
            explain: false, //是否有解释
            errorBox: false,
          },
          {
            ID: "",
            SKEY: "CREATIONDATE",
            title: "创建时间",
            display: true,
            VALUE: "",
            company: "",
            tips: "",
            disabled: true,
            standard: true, //标准输入框长度
            flag: true, // 控制必填校验样式展示
            required: true, // 是否为必填项
            explain: false, //是否有解释
            errorBox: false,
          },
          {
            ID: "",
            SKEY: "MODIFIERNAME",
            title: "修改人",
            display: true,
            VALUE: "",
            company: "",
            tips: "",
            disabled: true,
            standard: true, //标准输入框长度
            flag: true, // 控制必填校验样式展示
            required: true, // 是否为必填项
            explain: false, //是否有解释
            errorBox: false,
          },
          {
            ID: "",
            SKEY: "MODIFIEDDATE",
            title: "修改时间",
            display: true,
            VALUE: "",
            company: "",
            tips: "",
            disabled: true,
            standard: true, //标准输入框长度
            flag: true, // 控制必填校验样式展示
            required: true, // 是否为必填项
            explain: false, //是否有解释
            errorBox: false,
          },
        ],
      };
      this.tabList.push(obj);
      this.getStategyDetail();
    }
  },
  methods: {
    getStategyDetail() {
      // 编辑页面获取策略详情
      let params = {
        id: this.pageMsgId,
      };
      network.post("/p/cs/ordercvt/policy/queryDetail", params).then((res) => {
        const resData = res.data || {};
        const { code, data:resultData } = resData || {};
        if (code == 0) {
          this.tabList[0].list.find(
            (item) => item.SKEY == "POLICY_NAME"
          ).VALUE = res.data.data.POLICY_NAME;
          let idArr = [];
          let titleArr = [];
          let platformArr = [];
          res.data.data.IES_SHOP_LIST.forEach((itemOne, index) => {
            idArr +=
              itemOne.IES_SHOP_ID +
              (index == res.data.data.IES_SHOP_LIST.length - 1 ? "" : ",");
            titleArr +=
              itemOne.SHOPTITLE +
              (index == res.data.data.IES_SHOP_LIST.length - 1 ? "" : ",");
            platformArr +=
              itemOne.PLATFORM +
              (index == res.data.data.IES_SHOP_LIST.length - 1 ? "" : ",");
          });
          let idArrs = idArr.split(",");
          let titleArrs = titleArr.split(",");
          this.oldBaseMsg = res.data.data; // 保存默认的数据
          this.oldBaseMsg.shopid = idArr; // 店铺
          this.tabList[0].list.find(
            (item) => item.SKEY == "IES_SHOP_ID"
          ).VALUE = idArr;
          this.IES_SHOP_LIST = this.dropDownShopValue;
          let platformArrs = platformArr.split(",");
          this.dropDownShopValue = idArrs.map((item, i) => ({
            ID: item,
            Label: titleArrs[i],
          }));
          // 是否显示某些选项
          this.DropShopvalueChange(platformArrs, "start");
          const { SHIPPED_PDD_LOCALORDER:pinddLocal } = resultData || {};
          this.tabList[2].list.find((item) => item.SKEY == "SHIPPED_PDD_LOCALORDER").VALUE = pinddLocal == 1 ? true : false;
          this.tabList[0].list.find((item) => item.SKEY == "STARTDATE").VALUE =
            res.data.data.STARTDATE;
          this.tabList[0].list.find((item) => item.SKEY == "ENDDATE").VALUE =
            res.data.data.ENDDATE;

          this.tabList[1].list.find(
            (item) => item.SKEY == "NOCVT_CHANNEL_NAME"
          ).VALUE = res.data.data.NOCVT_CHANNEL_NAME;

          this.tabList[3].list.find(
            (item) => item.SKEY == "TMSELFORDER"
          ).VALUE = res.data.data.TMSELFORDER == 1 ? true : false;
          this.tabList[3].list.find((item) => item.SKEY == "KEY").VALUE =
            res.data.data.KEY;
          this.tabList[3].list.find((item) => item.SKEY == "SKU").VALUE =
            res.data.data.SKU;

          this.tabList[2].list.find((item) => item.SKEY == "JDORDER").VALUE =
            res.data.data.JDORDER == 1 ? true : false;
          // this.tabList[2].list.find(item=>item.SKEY=='TBORDER').VALUE = res.data.data.TBORDER==1?true:false
          this.tabList[2].list.find((item) => item.SKEY == "MJORDER").VALUE =
            res.data.data.MJORDER == 1 ? true : false;
          this.tabList[2].list.find((item) => item.SKEY == "DWORDER").VALUE =
            res.data.data.DWORDER == 1 ? true : false;
          this.tabList[2].list.find((item) => item.SKEY == "WMORDER").VALUE =
            res.data.data.WMORDER == 1 ? true : false;
          this.tabList[2].list.find((item) => item.SKEY == "ALLORDER").VALUE =
            res.data.data.ALLORDER == 1 ? true : false;
          this.tabList[2].list.find((item) => item.SKEY == "YOUZAN_BEFORE_PAYMENT").VALUE =
            res.data.data.YOUZAN_BEFORE_PAYMENT == 1 ? true : false;
          this.tabList[4].list.find((item) => item.SKEY == "OWNERNAME").VALUE =
            res.data.data.OWNERNAME;
          this.tabList[4].list.find(
            (item) => item.SKEY == "CREATIONDATE"
          ).VALUE = res.data.data.CREATIONDATE;
          this.tabList[4].list.find(
            (item) => item.SKEY == "MODIFIERNAME"
          ).VALUE = res.data.data.MODIFIERNAME;
          this.tabList[4].list.find(
            (item) => item.SKEY == "MODIFIEDDATE"
          ).VALUE = res.data.data.MODIFIEDDATE;
        }
      });
    },
    DropShopvalueChange(value, type) {

      if (type == "start") {
        this.platformIds = this.uniqueArray(value);
      } else {
        this.tabList[0].list.find((item) => item.SKEY == "IES_SHOP_ID").VALUE =
          "";
        this.platformIds = [];
        (value || []).forEach((item) => {
          this.tabList[0].list
            .find((item) => item.SKEY == "IES_SHOP_ID")
            .optionList.forEach((itemOne) => {
              if (itemOne.value == item.ID) {
                this.platformIds.push(itemOne.platform);
              }
            });
          this.tabList[0].list.find(
            (item) => item.SKEY == "IES_SHOP_ID"
          ).VALUE =
            this.tabList[0].list.find((item) => item.SKEY == "IES_SHOP_ID")
              .VALUE == ""
              ? item.ID
              : this.tabList[0].list.find((item) => item.SKEY == "IES_SHOP_ID")
                  .VALUE +
                "," +
                item.ID;
        });
        this.platformIds = this.uniqueArray(this.platformIds);
      }

      this.tabList[3].list.find(
        (item) => item.SKEY == "TMSELFORDER"
      ).display = false;
      this.tabList[3].list.find(
        (item) => item.SKEY == "TMSELFORDER"
      ).VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "JDORDER"
      ).display = false;
      this.tabList[2].list.find((item) => item.SKEY == "JDORDER").VALUE = false;
      // this.tabList[2].list.find(item=>item.SKEY=='TBORDER').display = false;
      // this.tabList[2].list.find(item=>item.SKEY=='TBORDER').VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "MJORDER"
      ).display = false;
      this.tabList[2].list.find((item) => item.SKEY == "MJORDER").VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "DWORDER"
      ).display = false;
      this.tabList[2].list.find((item) => item.SKEY == "DWORDER").VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "WMORDER"
      ).display = false;
      this.tabList[2].list.find((item) => item.SKEY == "WMORDER").VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "ALLORDER"
      ).VALUE = false;
      
      // Lark1.45-拼多多本地仓订单
      if (this.platformIds.indexOf("27") > -1) {
        this.tabList[2].list.find((item) => item.SKEY == "SHIPPED_PDD_LOCALORDER").display = true;
      }

      if (this.platformIds.indexOf("4") > -1) {
        // 京仓
        this.tabList[2].list.find(
          (item) => item.SKEY == "JDORDER"
        ).display = true;
      }
      if (this.platformIds.indexOf("2") > -1) {
        // 菜鸟
        this.tabList[3].list.find(
          (item) => item.SKEY == "TMSELFORDER"
        ).display = true;
        // this.tabList[2].list.find(item=>item.SKEY=='TBORDER').display = true;
      }
      if (this.platformIds.indexOf("247") > -1) {
        // 喵街
        this.tabList[2].list.find(
          (item) => item.SKEY == "MJORDER"
        ).display = true;
      }
      if (this.platformIds.indexOf("119") > -1) {
        // 得物（入仓）
        this.tabList[2].list.find(
          (item) => item.SKEY == "DWORDER"
        ).display = true;
      }
      if (
        this.platformIds.indexOf("30") > -1 ||
        this.platformIds.indexOf("253") > -1
      ) {
        // 微盟，微盟WOS
        this.tabList[2].list.find(
          (item) => item.SKEY == "WMORDER"
        ).display = true;
      }
      // 有赞

      if (this.platformIds.indexOf("20") > -1 || this.platformIds.indexOf("248") > -1) {
        this.tabList[2].list.find((item) => item.SKEY == "YOUZAN_BEFORE_PAYMENT").display = true;
      }else{
        this.tabList[2].list.find((item) => item.SKEY == "YOUZAN_BEFORE_PAYMENT").display = false;
        this.tabList[2].list.find((item) => item.SKEY == "YOUZAN_BEFORE_PAYMENT").VALUE = false;
      }
    },
    ClearDropShopvalue() {
      this.tabList[3].list.find(
        (item) => item.SKEY == "TMSELFORDER"
      ).display = true;
      this.tabList[3].list.find(
        (item) => item.SKEY == "TMSELFORDER"
      ).VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "JDORDER"
      ).display = true;
      this.tabList[2].list.find((item) => item.SKEY == "JDORDER").VALUE = false;
      // this.tabList[2].list.find(item=>item.SKEY=='TBORDER').display = true;
      // this.tabList[2].list.find(item=>item.SKEY=='TBORDER').VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "MJORDER"
      ).display = true;
      this.tabList[2].list.find((item) => item.SKEY == "MJORDER").VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "DWORDER"
      ).display = true;
      this.tabList[2].list.find((item) => item.SKEY == "DWORDER").VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "WMORDER"
      ).display = true;
      this.tabList[2].list.find((item) => item.SKEY == "WMORDER").VALUE = false;
      this.tabList[2].list.find(
        (item) => item.SKEY == "ALLORDER"
      ).VALUE = false;
    },

    uniqueArray(array) {
      return array.filter((item, index, self) => self.indexOf(item) === index);
    },

    refreshParams() {
      // 刷新页面
      this.getStategyDetail();
    },

    backToList() {
      // 返回策略列表页面
      let flag = true;
      if (this.pageMsgId != "New") {
        for (let i = 0; i < this.tabList[0].list.length; i++) {
          if (
            this.oldBaseMsg.POLICY_NAME !=
            this.tabList[0].list.find((item) => item.SKEY == "POLICY_NAME")
              .VALUE
          ) {
            console.log(111);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.shopid !=
            this.tabList[0].list.find((item) => item.SKEY == "IES_SHOP_ID")
              .VALUE
          ) {
            //.join(',')
            console.log(222);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.STARTDATE != null &&
            this.oldBaseMsg.STARTDATE !=
              new Date(
                this.tabList[0].list.find(
                  (item) => item.SKEY == "STARTDATE"
                ).VALUE
              ).getTime()
          ) {
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.STARTDATE == null &&
            this.tabList[0].list.find((item) => item.SKEY == "STARTDATE").VALUE
          ) {
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.ENDDATE != null &&
            this.oldBaseMsg.ENDDATE !=
              new Date(
                this.tabList[0].list.find(
                  (item) => item.SKEY == "ENDDATE"
                ).VALUE
              ).getTime()
          ) {
            console.log(444);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.ENDDATE == null &&
            this.tabList[0].list.find((item) => item.SKEY == "ENDDATE").VALUE
          ) {
            flag = false;
            break;
          }
        }
        for (let i = 0; i < this.tabList[1].list.length; i++) {
          if (
            this.oldBaseMsg.NOCVT_CHANNEL_NAME !=
            this.tabList[1].list.find(
              (item) => item.SKEY == "NOCVT_CHANNEL_NAME"
            ).VALUE
          ) {
            console.log(555);
            flag = false;
            break;
          }
        }
        for (let i = 0; i < this.tabList[2].list.length; i++) {
          // else if (this.oldBaseMsg.TBORDER != this.tabList[2].list.find(item=>item.SKEY=='TBORDER').VALUE) {
          //   flag = false;
          //   break;
          // }
          if (
            this.oldBaseMsg.JDORDER !=
            this.tabList[2].list.find((item) => item.SKEY == "JDORDER").VALUE
          ) {
            flag = false;
            console.log(666);
            break;
          } else if (
            this.oldBaseMsg.MJORDER !=
            this.tabList[2].list.find((item) => item.SKEY == "MJORDER").VALUE
          ) {
            console.log(777);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.DWORDER !=
            this.tabList[2].list.find((item) => item.SKEY == "DWORDER").VALUE
          ) {
            console.log(888);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.WMORDER !=
            this.tabList[2].list.find((item) => item.SKEY == "WMORDER").VALUE
          ) {
            console.log(999);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.ALLORDER !=
            this.tabList[2].list.find((item) => item.SKEY == "ALLORDER").VALUE
          ) {
            console.log(100);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.SHIPPED_PDD_LOCALORDER !=
            this.tabList[2].list.find((item) => item.SKEY == "SHIPPED_PDD_LOCALORDER").VALUE
          ) {
            flag = false;
            break;
          }
        }
        for (let i = 0; i < this.tabList[3].list.length; i++) {
          if (
            this.oldBaseMsg.TMSELFORDER !=
            this.tabList[3].list.find((item) => item.SKEY == "TMSELFORDER")
              .VALUE
          ) {
            console.log(101);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.SKU !=
            this.tabList[3].list.find((item) => item.SKEY == "SKU").VALUE
          ) {
            console.log(102);
            flag = false;
            break;
          } else if (
            this.oldBaseMsg.KEY !=
            this.tabList[3].list.find((item) => item.SKEY == "KEY").VALUE
          ) {
            console.log(103);
            flag = false;
            break;
          }
        }
      } else {
        for (let i = 0; i < this.tabList[0].list.length; i++) {
          if (this.tabList[0].list[i].VALUE) {
            flag = false;
            break;
          }
        }
        for (let i = 0; i < this.tabList[1].list.length; i++) {
          if (this.tabList[1].list[i].VALUE) {
            flag = false;
            break;
          }
        }
        for (let i = 0; i < this.tabList[2].list.length; i++) {
          if (this.tabList[2].list[i].VALUE) {
            flag = false;
            break;
          }
        }
        for (let i = 0; i < this.tabList[3].list.length; i++) {
          if (this.tabList[3].list[i].VALUE) {
            flag = false;
            break;
          }
        }
      }
      if (!flag) {
        this.showTip = true;
      } else {
        this.closePage();
      }
    },
    rangeDate(e) {
      console.log(e);
      console.log(this.tabList);
      // this.startTime = e[0];
      // this.endTime = e[1];
    },
    // 关闭当前页面
    closePage() {
      const { fullPath } = this.$route;
      const { keepAliveModuleName, tableName } =
        this.$store.state.global.activeTab;
      this.$store.commit("global/tabCloseAppoint", {
        tableName,
        routeFullPath: fullPath,
        keepAliveModuleName,
        stopRouterPush: true,
      });
      // 跳转
      setTimeout(() => {
        R3.store.commit("global/tabOpen", {
          type: "S",
          tableName: "T_OMSORDERCVTPOLICY",
          tableId: "11759",
          back: true,
        });
      }, 0);
    },
    //初始查询标准下拉框数据
    getQuery(tableName, fixed) {
      let virtual = {
        fixedcolumns: fixed ? fixed : {},
        range: 2000,
        startindex: 0,
        table: tableName,
      };
      if (tableName == "T_V_IESSHOP") {
        virtual.isdroplistsearch = true;
      }
      network.post("/p/cs/list/query", virtual).then((res) => {
        this.tabList[0].list.forEach((item) => {
          if (item.ID == tableName) {
            if (tableName == "T_V_IESSHOP") {
              item.optionList = res.data.rows.map((i) => {
                return {
                  label: i.SHOPTITLE.val,
                  value: i.ID.val,
                  platform: String(i.PLATFORM.refobjid),
                };
              });
            } else {
              item.optionList = res.data.rows.map((i) => {
                return {
                  label: i.NAME.val,
                  value: i.ID.val,
                };
              });
            }
          }
        });
      });
    },
    // 平台单号，退款单号(换货单没有)，退回物流单号禁止输入空格
    noSpaces(e, i) {
      if (i.SKEY == "satisfied_amount" || i.SKEY == "satisfied_pieces") {
        if (e.keyCode == 32) e.returnValue = false;
      }
    },
    // 保存
    saveAll() {
      let baseMsg = this.tabList[0]; //基本设置
      let zhglMsg = this.tabList[1]; //转换过滤条件
      let yfhddzhMsg = this.tabList[2]; //已发货订单转换
      let yfhzwfhMsg = this.tabList[3]; //已发货转未发货
      let flag = false;
      if (!baseMsg.list.find((item) => item.SKEY == "POLICY_NAME").VALUE) {
        return this.$Message.warning("策略名称不能为空！");
      }
      if (!baseMsg.list.find((item) => item.SKEY == "IES_SHOP_ID").VALUE) {
        return this.$Message.warning("参与店铺不能为空！");
      }

      let params = {};
      if (this.pageMsgId == "New") {
        params = {
          ID: -1,
          POLICY_NAME: baseMsg.list.find((item) => item.SKEY == "POLICY_NAME")
            .VALUE,
          IES_SHOP_ID: baseMsg.list.find((item) => item.SKEY == "IES_SHOP_ID")
            .VALUE,
          STARTDATE: baseMsg.list.find((item) => item.SKEY == "STARTDATE")
            .VALUE,
          ENDDATE: baseMsg.list.find((item) => item.SKEY == "ENDDATE").VALUE,
          NOCVT_CHANNEL_NAME: zhglMsg.list.find(
            (item) => item.SKEY == "NOCVT_CHANNEL_NAME"
          ).VALUE,
          TMSELFORDER: yfhzwfhMsg.list.find(
            (item) => item.SKEY == "TMSELFORDER"
          ).VALUE
            ? 1
            : 0,
          KEY: yfhzwfhMsg.list.find((item) => item.SKEY == "KEY").VALUE,
          SKU: yfhzwfhMsg.list.find((item) => item.SKEY == "SKU").VALUE,
          SHIPPED_PDD_LOCALORDER: yfhddzhMsg.list.find((item) => item.SKEY == "SHIPPED_PDD_LOCALORDER").VALUE ? 1 : 0,//拼多多
          JDORDER: yfhddzhMsg.list.find((item) => item.SKEY == "JDORDER").VALUE
            ? 1
            : 0,
          // TBORDER: yfhddzhMsg.list.find(item=>item.SKEY=='TBORDER').VALUE?1:0,
          MJORDER: yfhddzhMsg.list.find((item) => item.SKEY == "MJORDER").VALUE
            ? 1
            : 0,
          DWORDER: yfhddzhMsg.list.find((item) => item.SKEY == "DWORDER").VALUE
            ? 1
            : 0,
          WMORDER: yfhddzhMsg.list.find((item) => item.SKEY == "WMORDER").VALUE
            ? 1
            : 0,
          ALLORDER: yfhddzhMsg.list.find((item) => item.SKEY == "ALLORDER")
            .VALUE
            ? 1
            : 0,
          YOUZAN_BEFORE_PAYMENT: yfhddzhMsg.list.find((item) => item.SKEY == "YOUZAN_BEFORE_PAYMENT")
            .VALUE
            ? 1
            : 0,
        };
        this.saveSubmit(params);
      } else {
        params = {
          ID: this.pageMsgId,
          POLICY_NAME: baseMsg.list.find((item) => item.SKEY == "POLICY_NAME")
            .VALUE,
          IES_SHOP_ID: baseMsg.list.find((item) => item.SKEY == "IES_SHOP_ID")
            .VALUE,
          STARTDATE: baseMsg.list.find((item) => item.SKEY == "STARTDATE")
            .VALUE,
          ENDDATE: baseMsg.list.find((item) => item.SKEY == "ENDDATE").VALUE,
          NOCVT_CHANNEL_NAME: zhglMsg.list.find(
            (item) => item.SKEY == "NOCVT_CHANNEL_NAME"
          ).VALUE,
          TMSELFORDER: yfhzwfhMsg.list.find(
            (item) => item.SKEY == "TMSELFORDER"
          ).VALUE
            ? 1
            : 0,
          KEY: yfhzwfhMsg.list.find((item) => item.SKEY == "KEY").VALUE,
          SKU: yfhzwfhMsg.list.find((item) => item.SKEY == "SKU").VALUE,
          SHIPPED_PDD_LOCALORDER: yfhddzhMsg.list.find((item) => item.SKEY == "SHIPPED_PDD_LOCALORDER").VALUE ? 1 : 0,//拼多多
          JDORDER: yfhddzhMsg.list.find((item) => item.SKEY == "JDORDER").VALUE
            ? 1
            : 0,
          // TBORDER: yfhddzhMsg.list.find(item=>item.SKEY=='TBORDER').VALUE?1:0,
          MJORDER: yfhddzhMsg.list.find((item) => item.SKEY == "MJORDER").VALUE
            ? 1
            : 0,
          DWORDER: yfhddzhMsg.list.find((item) => item.SKEY == "DWORDER").VALUE
            ? 1
            : 0,
          WMORDER: yfhddzhMsg.list.find((item) => item.SKEY == "WMORDER").VALUE
            ? 1
            : 0,
          ALLORDER: yfhddzhMsg.list.find((item) => item.SKEY == "ALLORDER")
            .VALUE
            ? 1
            : 0,
          YOUZAN_BEFORE_PAYMENT: yfhddzhMsg.list.find((item) => item.SKEY == "YOUZAN_BEFORE_PAYMENT")
            .VALUE
            ? 1
            : 0,
        };
        // console.log(params)
        this.saveSubmit(params);
      }
    },
    saveSubmit(params) {
      network.post("/p/cs/ordercvt/policy/add", params).then(async (res) => {
        if (res.data.code == 0) {
          this.$Message.success("保存成功");
          if (this.pageMsgId != "New") {
            this.refreshParams();
            return;
          } else {
            const { fullPath } = this.$route;
            const { keepAliveModuleName, tableName } =
              this.$store.state.global.activeTab;
            this.$store.commit("global/tabCloseAppoint", {
              tableName,
              routeFullPath: fullPath,
              keepAliveModuleName,
              stopRouterPush: true,
            });
            // 跳转
            setTimeout(() => {
              R3.store.commit("global/tabOpen", {
                type: "tableDetailAction" || "C",
                label: "订单转换策略",
                customizedModuleName: "EDITOMSORDERVTPOLICY",
                customizedModuleId: res.data.data.objId,
              });
            }, 0);
          }
        }
      });
    },
    getTime(date) {
      let time = new Date(date).getTime();
    },
  },
};
</script>
  <style lang="less">
.quickOperation {
  height: 64px;
  border-bottom: 1px solid #d8d8d8;
  display: flex;
  align-items: center;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
}
.content {
  // .block {
  //   padding-top: 24px;
  // }
  .ark-col {
    display: flex;
    align-items: center;
    // justify-content: flex-end;
    margin-bottom: 16px;
    .input_box {
      max-width: 400px;
      min-width: 180px;
    }

    .ark-input-wrapper /deep/ textarea {
      resize: none;
      min-height: 36px !important;
    }
    .title {
      min-width: 120px;
      display: flex;
      justify-content: flex-end;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #575757;
      display: flex;
      align-items: center;
      margin-right: 4px;
      img {
        margin-left: 5px;
        width: 16px;
      }
    }
  }
}
.refund-content {
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;

  .count-part {
    height: 60px;
    margin-bottom: 16px;
    border-bottom: 1px solid #d8d8d8;
    .item {
      display: flex;
      align-items: center;
      .text {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
      }
    }
    .img-framelanflag {
      cursor: pointer;
      vertical-align: middle;
      margin-top: -3px;
      margin-left: 5px;
      width: 16px;
    }
    .input-money {
      width: 80px;
      margin: 0 8px;
    }
    .plus {
      margin: 0 16px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #979797;
    }
  }
  .total-part {
    display: flex;
    align-items: center;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
  }
}

.OMSOrderVTPolicy .ark-upload-drag {
  border: none;
}
.OMSOrderVTPolicy .ark-select-multiple .ark-select-item.ark-select-item-all {
  display: none;
}
.priceMonitor .img-framelanflag {
  cursor: pointer;
  vertical-align: middle;
  margin-top: 0px;
  margin-left: 0px;
  width: 16px;
}
.OMSOrderVTPolicy .priceMonitor .input_box.ark-fkrp-select {
  width: 220px;
}
.OMSOrderVTPolicy .shopDropMultiSelectFilter {
  width: 100%;
}
</style>
  <style lang="less" scoped>
.errorFormBox {
  border: 1px solid red;
}
.OMSOrderVTPolicy {
  min-width: 1380px;
  padding: 0 16px;
}
.pageContent {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}
.order-setting-input-error:before {
  content: "*";
  color: red;
}
.conditionContent,
.conditionContentOne {
  width: 100%;
  display: flex;
  max-height: 3000px;
  overflow: hidden;
  flex-wrap: wrap;
  padding-top: 8px;
  justify-content: space-between;
  .itemContent {
    width: calc((100% - 120px) / 3);
    display: flex;
    align-items: center;
    margin: 0 20px 24px;
    .itemLabel {
      min-width: 84px;
      font-size: 12px;
      font-weight: 500;
      color: #4c4c4c;
      line-height: 17px;
      margin-right: 8px;
      text-align: right;
    }
    .posterType {
      width: calc(100% - 84px);
    }
  }
}
.tableArea /deep/ .ark-tabs-bar {
  margin-bottom: 0px;
  .ark-tabs-tab {
    line-height: 22px !important;
  }
}
.tableArea {
  padding-top: 24px;
  .handleBtn {
    height: 16px;
    margin-bottom: 16px;
    display: flex;
    .handleItem {
      width: 48px;
      height: 16px;
      margin-bottom: 16px;
      display: flex;
      .handleItem {
        width: 48px;
        height: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: var(--primary-color);
        line-height: 16px;
        margin: 0 2px;
        cursor: pointer;
      }
    }
  }
}
.content /deep/ .ark-select-input[disabled] {
  color: #575757;
}

.strategy-panel {
  width: 100%;
  /deep/.ark-collapse-item {
    padding: 0;
  }
  /deep/.ark-collapse > .ark-collapse-item > .ark-collapse-content {
    padding: 0;
  }
}

.form-item {
  display: flex;
  align-items: center;
  .form-label {
    margin-right: 4px;
  }
  .value-width {
    width: 166px !important;
  }
}
/deep/ #syncpltstock .ItemComponentRoot .itemLabel {
  flex: 0 0 210px !important;
}
</style>
  