<template>
  <div class="add-pre-sale-strategy">
    <div class="quickOperation">
      <!-- 快捷操作： -->
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click="handleSubmit('formInline')"
      >
        保存
      </Button>
      <Button
        type="fcdefault"
        @click="closePage"
      >
        关闭
      </Button>
    </div>
    <div class="paramsBox">
      <Form
        ref="formInline"
        :label-width="156"
        label-position="right"
        :model="formInline"
        :rules="ruleInline"
      >
        <FormItem
          prop="strategyType"
          label="策略类型:"
        >
          <Select
            v-model="formInline.strategyType"
            style="width:280px"
            @on-change="onChangeStrategyType"
          >
            <Option
              v-for="item in strategyTypeOptions"
              :value="item.value"
              :key="item.value"
            >{{ item.label }}</Option>
          </Select>
        </FormItem>

        <FormItem
          prop="default_strategy_type"
          label="默认策略类型:"
          v-if="formInline.strategyType===2"
          :rules="defaultStrategyRule"
        >
          <Select
            v-model="formInline.default_strategy_type"
            style="width:280px"
            clearable
            @on-change="onChangeDefaultStrategyType"
          >
            <Option
              v-for="item in platformStrategyOptions"
              :value="item.value"
              :key="item.value"
            >{{ item.label }}</Option>
          </Select>
        </FormItem>

        <FormItem
          prop="strategyName"
          label="策略名称:"
          :class="errorNameShow?'ark-form-item-error':''"
        >
          <Input
            ref="strategyName"
            v-model="formInline.strategyName"
            style="width: 280px"
            type="text"
            placeholder=""
            @on-keyup="changeStrategyName"
            @on-blur="blurStrategy"
          />
          <p
            v-if="errorStrategyName"
            class="ark-form-item-error-tip-right"
          >
            {{ errorStrategyName }}
          </p>
          <p
            v-if="errorNameShow"
            class="ark-form-item-error-tip"
          >
            {{ errorName }}
          </p>
        </FormItem>

        <FormItem
          prop="isOpen"
          label="是否开启:"
        >
          <i-switch
            v-model="formInline.isOpen"
            @on-change="changeIsOpen"
          />
        </FormItem>

        <FormItem
          prop="priority"
          label="策略优先级:"
        >
          <div>
            <Input
              v-model.number="formInline.priority"
              :regx="/^[0-9]*$/"
              style="width: 280px"
            />
            <p class="bottomTips">数字越大优先级越高</p>
          </div>
        </FormItem>

        <FormItem
          prop="keyword"
          label="识别关键字:"
          :class="errorKeyShow?'ark-form-item-error':''"
        >
          <Input
            v-model="formInline.keyword"
            style="width: 280px"
            type="text"
            placeholder=""
            :disabled="formInline.strategyType===2"
            @keydown.native="keydown($event)"
            @on-keyup="changeKeyword"
            @on-blur="blurKeyword"
          />
          <p
            v-if="errorKeyWord"
            class="ark-form-item-error-tip-right"
          >
            {{ errorKeyWord }}
          </p>
          <p
            v-if="errorKeyShow"
            class="ark-form-item-error-tip"
          >
            {{ errorKey }}
          </p>
          <p class="bottomTips">
            在平台商品名称或商家编码或商品规格中添加【识别关键字】，系统识别到关键字后，将识别订单为预售订单/商品为预售商品，设置步骤请参考<a
              href="https://burgeonwing.yuque.com/anicqo/zm70bv/est4ys?"
              target="_blank"
            >【预售商品设置操作手册】。</a>
          </p>
        </FormItem>
        <FormItem
          prop="availableFirst"
          label="有货先发:"
        >
          <RadioGroup
            v-model="formInline.availableFirst"
            @on-change="changeAvailableFirst"
          >
            <Radio label="true">
              <span>是</span>
            </Radio>
            <Radio label="false">
              <span>否</span>
            </Radio>
          </RadioGroup>
          <p class="bottomTips">
            设置有货先发后，仅为订单打【预售】标识。
          </p>
          <div class="sub-item">
            <Checkbox
              v-model="checkEncode"
              @on-change="onCheckChange"
              size="small"
            ></Checkbox>
            <span>排除平台SKU编码:</span>
            <Input
              v-show="checkEncode"
              style="width: 280px;"
              v-model="formInline.exclude_extskuid"
              type="textarea"
              :autosize="true"
              placeholder="请输入平台SKU编码，多个支持空格、分号、逗号隔开"
            />
          </div>
        </FormItem>
        <FormItem
          prop="ispresalesplitorder"
          label="预售拆单:"
        >
          <RadioGroup
            v-model="formInline.ispresalesplitorder"
          >
            <Radio
              label="true"
            >
              <span>是</span>
            </Radio>
            <Radio
              label="false"
            >
              <span>否</span>
            </Radio>
          </RadioGroup>
          <p class="bottomTips">
            勾选是，占单时订单中不同计划发货时间的商品会拆单；勾选否，占单时不拆单，整单的计划发货时间，以订单中计划发货时间最早的商品为准。
          </p>
        </FormItem>
        <FormItem
          v-if="formInline.strategyType!=2"
          prop="planSendDate"
          label="计划发货日期:"
        > 
          <Select
            v-model="formInline.planSendDate_type"
            style="width:100px"
            @on-change="onChangeplanSendDateType"
          >
            <Option
              v-for="item in planSendDateTypeOptions"
              :value="item.value"
              :key="item.value"
            >{{ item.label }}</Option>
          </Select>
          <DatePicker
            v-model="formInline.planSendDate"
            v-if="formInline.planSendDate_type == 1"
            type="date"
            format="yyyy-MM-dd"
            :options="options3"
            placeholder=""
            style="width: 280px"
            :editable="editable"
            is-emit-on-change
            @on-change="changeDate(formInline)"
            @on-clear="clearDate"
            :disabled="formInline.strategyType === 2"
          />
          <Input
            v-else
            v-model="formInline.planSendDay"
            placeholder=""
            :regx="regx"
            style="width: 240px"
          />
          <p class="bottomTips">
            选择指定日期，匹配到预售策略的订单，计划发货日期将赋值此处维护的日期；选择付款后x天，匹配到预售策略的订单，计划发货日期为订单付款时间+此处维护的天数。
          </p>
        </FormItem>
        <FormItem
          prop="prePlanDays"
          label="提前发货天数:"
        >
          <Input
            v-model="formInline.prePlanDays"
            placeholder=""
            :regx="regx"
            style="width: 280px"
            @on-keyup="changePrePlanDays"
          />
          <p class="bottomTips">
            设置提前发货天数后，实际的计划发货时间将为计划发货日期减去提前发货天数，如计划11月11日发货，提前发货天数为2，则实际开始占用库存日期为11月9日。
          </p>
        </FormItem>
        <FormItem
          prop="storeList"
          label="使用店铺:"
        >
          <div class="shopSelect">
            <DropDownCom
              ref="DropDownCom"
              style="width:600px"
              select-width="600"
              :choosed-express-list="choosedExpressList"
              placeholder=""
              :express-list="shopList"
              :clearable='true'
              @changeShopArr="changeShopArr"
              @searchList="getEnterExpressList"
              @clearAllData="clearAllFilter"
            />
            <div
              v-if="selectShopArr.length"
              class="selectPart"
            >
              <div class="selectGroup">
                <span style="margin-right:8px;font-size: 11px;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;color: #CDCDCD;line-height: 16px;">检索项</span>
                <div
                  v-for="(item,index) in selectShopArr"
                  :key="index"
                  class="groupItem"
                >
                  <span>{{ item.label }}</span>
                  <Icon
                    type="ios-close"
                    @click="deleteShop(item,index)"
                  />
                </div>
              </div>
              <div class="selectBtn">
                <div
                  style="cursor:pointer; padding:8px;padding-top: 0px;"
                  @click="clearAll"
                >
                  清空
                </div>
                <div style="padding:8px 0;height:40px;padding-top: 0px;">
                  |
                </div>
                <div
                  style="padding:8px;cursor:pointer;padding-top: 0px;padding-right: 0px;"
                  @click="showAll"
                >
                  {{ showAllText }}
                  <Icon :type="isShow?'iconios-arrow-down':'iconios-arrow-up'" />
                </div>
              </div>
            </div>
          </div>
        </FormItem>
      </Form>
    </div>
    <Spin
      v-if="spinShow"
      fix
    >
      <Icon
        type="ios-loading"
        size="18"
        style="animation: ani-demo-spin 1s linear infinite"
      />
      <div>加载中...</div>
    </Spin>
  </div>
</template>

<script>
import DropDownCom from '@yunque/component/customizedContent/DropDownCom';

const R3 = window.R3;

const { network } = R3;
export default {
  components: { DropDownCom },
  data() {
    return {
      maskClosable: false,
      precision: 2,
      regx: /^\d{0,15}?$/, // 0-99正整数
      spinShow: false,
      editable: false,
      choosedExpressList: [],
      shopList: [],
      selectShopArr: [], // 搜索列表选中数据
      isShowItem: true,
      isShow: false,
      showAllText: '展开',
      options3: {
        disabledDate(date) {
          return date && date.valueOf() < Date.now();
        }
      },
      errorNameShow: false,
      errorName: '',
      errorKeyShow: false,
      errorKey: '',
      formInline: {
        strategyName: '',
        isOpen: false,
        keyword: '',
        availableFirst: 'false',
        ispresalesplitorder: 'true',
        planSendDate_type: 1,
        planSendDate: '',
        planSendDay: '',
        prePlanDays: '0',
        storeList: [],
        exclude_extskuid: '',
        strategyType: 1, // 策略类型,1自定义,2默认
        default_strategy_type: '', // 默认策略类型
        priority: undefined, // 优先级
      },
      ruleInline: {
        strategyType: [
          { required: true }
        ],
        strategyName: [
          { required: true, message: '请输入策略名称', trigger: 'blur' },
        ],
        keyword: [
          { required: true, message: '请输入识别关键字', trigger: 'blur' },
        ],
      },
      errorKeyWord: '',
      errorStrategyName: '',
      checkEncode: false,
      strategyTypeOptions: [
        {
          value: 1,
          label: '自定义策略'
        },
        {
          value: 2,
          label: '默认策略'
        },
      ],
      platformStrategyOptions: [
        {
          value: 1,
          label: '淘宝/天猫全款预售'
        },
        {
          value: 2,
          label: '抖音全款预售'
        },
        {
          value: 3,
          label: '得物全款预售'
        },
        {
          value: 4,
          label: '微盟全款预售'
        },
        {
          value: 5,
          label: '预售xx.xx发'
        },
        {
          value: 6,
          label: '预售xx月xx日发'
        },
        {
          value: 7,
          label: '小红书全款预售'
        },
        {
          value: 8,
          label: '微盟（WOS）全款预售'
        },
        {
          value: 9,
          label: '视频号小店全款预售'
        },
        {
          value: 10,
          label: '拼多多全款预售'
        },
        {
          value: 11,
          label: '快手全款预售'
        },
        {
          value: 12,
          label: '有赞全款预售'
        },
        {
          value: 13,
          label: '京东全款预售'
        },
      ],
      planSendDateTypeOptions: [
      {
          value: 1,
          label: '指定日期'
        },
        {
          value: 2,
          label: '付款后x天'
        },
      ],
      defaultStrategyRule: {
        required: true,
        validator: (rule, value, callback) => {
          console.log("🚀 ~ file: AddPreSaleStrategy.vue:356 ~ data ~ value:", value)
          if (value) {
            callback()
          } else {
            callback(new Error('请输入默认策略类型'));
          }
        }
      }
    };
  },
  created() {
    this.setPlanSendDate();
    this.getShopArr(); // 获取店铺列表
  },
  methods: {
    // 修改策略类型
    onChangeStrategyType(val) {
      this.formInline.strategyName = ''
      this.formInline.default_strategy_type = ''
      this.formInline.keyword = ''
      if(this.formInline.strategyType===2) {
        this.formInline.planSendDate = ''
      }
    },

    // 修改默认策略类型
    onChangeDefaultStrategyType(val) {
      const res = this.platformStrategyOptions.find(item => item.value === val)
      if (res) {
        this.formInline.strategyName = `默认预售策略-${res.label}`
      }

      if (this.formInline.strategyType === 2) {
        this.setDefaultKeyword(val)
      }
    },
    // 修改计划发货日期类型
    onChangeplanSendDateType(val) {
      this.formInline.planSendDate = ''
      this.formInline.planSendDay = ''
    },

    // 设置默认策略的关键字
    setDefaultKeyword(val) {
      console.log("🚀 ~ file: AddPreSaleStrategy.vue:397 ~ setDefaultKeyword ~ val:", val)
      switch (val) {
        case 1:
          this.formInline.keyword = '【淘宝商品中设置的发货时间】'
          break
        case 2:
          this.formInline.keyword = '【抖音商品中设置的发货时间】'
          break
        case 3:
        this.formInline.keyword = '【商品中设置的发货时间】'
          break
        case 4:
        this.formInline.keyword = '【微盟订单中设置的预计发货时间】'
          break
        case 5:
        this.formInline.keyword = '预售xx.xx发'
          break
        case 6:
        this.formInline.keyword = '预售xx月xx日发'
          break
        case 7:
        this.formInline.keyword = '【小红书订单中的预计发货时间】'
          break
        case 8:
          this.formInline.keyword = '【微盟（WOS）订单中设置的预计发货时间】'
          break
        case 9:
          this.formInline.keyword = '【视频号小店订单中的预计发货时间】'
          break
        case 10:
          this.formInline.keyword = '【拼多多订单中的预计发货时间】'
          break
        case 11:
          this.formInline.keyword = '【快手订单中的预计发货时间】'
          break
        case 12:
          this.formInline.keyword = '【有赞订单中的预计发货时间】'
          break
        case 13:
          this.formInline.keyword = '【京东订单中的预计发货时间】'
          break
      }
    },

    changeStrategyName(event) { // 输入策略名称触发事件
      if (event.target.value.length > 20) {
        this.formInline.strategyName = event.target.value.slice(0, 20);
        this.errorNameShow = true;
        this.errorStrategyName = '最多只能输入20字符';
      }
    },
    blurStrategy() { // 输入名称失去焦点事件
      this.errorNameShow = false;
      this.errorStrategyName = '';
    },
    changeKeyword(event) { // 输入关键字触发事件
      if (event.target.value.length > 15) {
        this.formInline.keyword = event.target.value.slice(0, 15);
        this.errorKeyShow = true;
        this.errorKeyWord = '最多只能输入15字符';
      }
    },
    blurKeyword() { // 输入关键字失去焦点事件
      this.errorKeyShow = false;
      this.errorKeyWord = '';
    },
    changePrePlanDays(e) { // 提前发货天数输入框校验
      if (Number(e.target.value) > 99) {
        this.formInline.prePlanDays = '99';
      } else if (e.target.value[0] == 0 && e.target.value.length > 1) {
        this.formInline.prePlanDays = e.target.value.slice(1, e.target.value.length);
      }
    },
    // 初始化发货日期
    setPlanSendDate() {
      let nowDate = new Date();
      // let date = {
      //   year: nowDate.getFullYear(),
      //   month: nowDate.getMonth() + 1,
      //   date: nowDate.getDate(),
      // };
      // 当前日期
      // let systemDate = `${date.year}-${date.month}-${date.date}`;
      let afterdate = new Date(nowDate);
      afterdate.setDate(nowDate.getDate() + 30);
      // 30天后
      this.formInline.planSendDate = `${afterdate.getFullYear()}-${afterdate.getMonth() + 1 < 10 ? `0${afterdate.getMonth() + 1}` : afterdate.getMonth() + 1}-${afterdate.getDate() < 10 ? `0${afterdate.getDate()}` : afterdate.getDate()}`;
    },
    // 以下为使用店铺相关逻辑
    // 初始化店铺列表
    getShopArr() {
      let data = {
        table: 'T_V_IESSHOP',
        range: 1000,
        isdroplistsearch: true,
        fkdrplist: {
          searchcols: ['ID', 'SHOPTITLE']
        }
      };
      network.post('/p/cs/list/query', data).then((res) => {
        if (res.data.rows.length) {
          this.shopList = res.data.rows.map(item => ({
            value: item.ID.val,
            label: item.SHOPTITLE.val
          }));
        }
      });
    },
    changeShopArr(val, deffArr) {
      if (val.length) {
        if (val.some(item => Object.hasOwnProperty.call(item, 'label'))) { // 全选时第一次传入没有label
          this.shopName = '';
          this.shopIds = '';
          this.choosedExpressList = [];
          let Data = [...val].filter(x => [...this.selectShopArr].every(y => y.value !== x.value));
          this.selectShopArr = [...this.selectShopArr, ...Data];
          if (deffArr.length) {
            this.selectShopArr = this.selectShopArr.filter(x => [...deffArr].every(y => y.value !== x.value)); // 过滤掉取消项
          }

          this.selectShopArr.forEach(item => {
            this.choosedExpressList.push(String(item.value));
            this.shopName = this.shopName == '' ? item.label.replace(/[\r\n]/g, '').replace(/\ +/g, '') : (`${this.shopName},${item.label.replace(/[\r\n]/g, '').replace(/\ +/g, '')}`);
            this.shopIds = this.shopIds == '' ? item.value : `${this.shopIds},${item.value}`;
          });
          this.$refs.DropDownCom.choosedExpress = this.choosedExpressList;
        }
      } else { // 当前下拉列表里全部清空
        this.shopName = '';
        this.shopIds = '';
        this.choosedExpressList = [];
        if (deffArr.length) {
          this.selectShopArr = this.selectShopArr.filter(x => [...deffArr].every(y => y.value !== x.value)); // 过滤掉取消项
        }

        this.selectShopArr.forEach(item => {
          this.choosedExpressList.push(String(item.value));
          this.shopName = this.shopName == '' ? item.label.replace(/[\r\n]/g, '').replace(/\ +/g, '') : (`${this.shopName},${item.label.replace(/[\r\n]/g, '').replace(/\ +/g, '')}`);
          this.shopIds = this.shopIds == '' ? item.value : `${this.shopIds},${item.value}`;
        });
        this.$refs.DropDownCom.choosedExpress = this.choosedExpressList;
      }
    },
    getEnterExpressList(val) {
      let data = {
        table: 'T_V_IESSHOP',
        range: 1000,
        isdroplistsearch: true,
        fkdrplist: {
          searchcols: ['ID', 'SHOPTITLE']
        },
        fixedcolumns: { SHOPTITLE: val },
      };
      this.$refs.DropDownCom.choosedExpress = this.choosedExpressList;
      network.post('/p/cs/list/query', data).then((res) => {
        this.shopList = res.data.rows.map(item => ({
          value: item.ID.val,
          label: item.SHOPTITLE.val
        }));
      });
    },
    deleteShop(obj, index) { // 删除某一检索项
      this.$refs.DropDownCom.choosedExpress = this.$refs.DropDownCom.choosedExpress.filter(item => obj.value != item);
      this.selectShopArr = this.selectShopArr.filter(item => obj.value != item.value);
      this.shopName = '';
      this.shopIds = '';
      this.choosedExpressList = [];
      this.selectShopArr.forEach(item => {
        this.choosedExpressList.push(String(item.value));
        this.shopName = this.shopName == '' ? item.label.replace(/[\r\n]/g, '').replace(/\ +/g, '') : (`${this.shopName},${item.label.replace(/[\r\n]/g, '').replace(/\ +/g, '')}`);
        this.shopIds = this.shopIds == '' ? item.value : `${this.shopIds},${item.value}`;
      });
      this.$refs.DropDownCom.choosedExpress = this.choosedExpressList;
    },
    clearAllFilter(value) { // 清空带有筛选的检索项
      value.forEach(itemOne => {
        this.selectShopArr.forEach((item, index) => {
          if (itemOne.value == item.value) {
            this.selectShopArr.splice(index, 1);
          }
        });
      });
      this.choosedExpressList = [];
      this.selectShopArr.forEach(item => {
        this.choosedExpressList.push(String(item.value));
        this.shopName = this.shopName == '' ? item.label.replace(/[\r\n]/g, '').replace(/\ +/g, '') : (`${this.shopName},${item.label.replace(/[\r\n]/g, '').replace(/\ +/g, '')}`);
        this.shopIds = this.shopIds == '' ? item.value : `${this.shopIds},${item.value}`;
      });
      this.$refs.DropDownCom.choosedExpress = this.choosedExpressList;
    },
    clearAll() { // 清空全部检索项
      this.$refs.DropDownCom.choosedExpress = [];// 检索项清空
      this.selectShopArr = [];
      this.shopName = '';
      this.shopIds = '';
    },
    showAll() { // 显示所有搜索项
      this.isShow = !this.isShow;
      if (this.isShow) {
        this.showAllText = '收起';
        document.getElementsByClassName('selectGroup')[0].style.height = 'auto';
      } else {
        document.getElementsByClassName('selectGroup')[0].style.height = '52px';
        this.showAllText = '展开';
      }
    },
    // 以上为使用店铺相关逻辑
    // 禁止输入空格
    keydown(e) {
      if (e.keyCode == 32) {
        e.returnValue = false;
      }
    },
    dateChange(date) {
      let d = new Date(date);
      let mouth = d.getMonth() + 1 < 10 ? `0${d.getMonth() + 1}` : d.getMonth() + 1;
      let day = d.getDate() < 10 ? `0${d.getDate()}` : d.getDate();
      let datetime = `${d.getFullYear()}-${mouth}-${day}`;
      return datetime;
    },
    changeDate(formInline) {
      if (formInline.planSendDate == '' || formInline.planSendDate == 'NaN-NaN-NaN') {
        formInline.planSendDate = '';
      } else {
        formInline.planSendDate = this.dateChange(formInline.planSendDate);
      }
    },
    clearDate() {
      this.formInline.planSendDate = '';
    },
    changeIsOpen() {
      console.log(this.formInline);
    },
    changeAvailableFirst(value) {
      console.log(1234)
      if (value == 'true') {
        this.isShowItem = false;
        this.formInline.planSendDate = ''
        this.formInline.planSendDay = ''
        this.formInline.prePlanDays = ''
      } else {
        this.isShowItem = true;
      }
    },

    validate() {
      let isValid = false
      // 【有货先发】为'否'，【计划发货日期】和【提前发货天数】都必填
      // 【有货先发】为'是'，且【排除平台SKU编码】有值，【计划发货日期】和【提前发货天数】都必填
      if(this.formInline.strategyType===2) {
        if (this.formInline.availableFirst === 'false') {
          if (!this.formInline.prePlanDays) {
            isValid = false
          } else {
            isValid = true
          }
        } else{
          if (this.formInline.exclude_extskuid && !this.formInline.prePlanDays) {
            isValid = false
          } else {
            isValid = true
          }
        }
        if (!isValid) {
          this.$Message.error('请填写提前发货天数');
        }
      } else {
        if (this.formInline.availableFirst === 'false') {
          if ((!this.formInline.planSendDate && !this.formInline.planSendDay) || !this.formInline.prePlanDays) {
            isValid = false
          } else {
            isValid = true
          }
        } else{
          if (this.formInline.exclude_extskuid && (!this.formInline.prePlanDays)) {
            isValid = false
          } else {
            isValid = true
          }
        }

        if (!isValid) {
          this.$Message.error('请填写计划发货日期和提前发货天数');
        }
      }

      console.log('校验结果', isValid)
      return isValid
    },

    handleSubmit(name) {
      if (!this.validate()) {
        return
      }
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.saveStrategy();
          //   this.$Message.success('Success!');
        } else {
          console.log('校验失败', this.$refs[name], valid)
          //   this.$Message.error('Fail!');
        }
      });
    },
    saveStrategy() {
      // 默认策略类型时不显示，不显示不判断 formInline.planSendDate_type
      if(this.formInline.strategyType !=2 && this.formInline.availableFirst === 'false' && !this.formInline.planSendDate && this.formInline.planSendDate_type ===1){
        return this.$Message.error('请填写计划发货日期');
      }
      if(this.formInline.availableFirst === 'false' && this.formInline.planSendDate_type == 2 && !this.formInline.planSendDay){
        return this.$Message.error('请填写计划发货天数');
      }
      // if(this.formInline.strategyType===2 && this.formInline.planSendDate_type == 1 && !this.formInline.planSendDate){
      //   this.formInline.planSendDate = this.formInline.keyword
      // }
      this.errorNameShow = false;
      this.errorKeyShow = false;
      let params = {
        name: this.formInline.strategyName,
        is_active: this.formInline.isOpen ? 'Y' : "N",
        is_advance: this.formInline.availableFirst == 'true' ? 1 : 0,
        ispresalesplitorder: this.formInline.ispresalesplitorder == 'true' ? 1 : 0,
        keywords: this.formInline.keyword,
        shopIds: this.choosedExpressList,
        exclude_extskuid: this.formInline.exclude_extskuid?this.formInline.exclude_extskuid.replace(/\n/g, ' '):'',
        planned_type:this.formInline.planSendDate_type,
        advance_days: this.formInline.prePlanDays,
        priority: this.formInline.priority,
        strategyType: this.formInline.strategyType,
      };
      if (this.formInline.planSendDate_type == 1) {
        params.plan_delivery_date = this.formInline.planSendDate
      }else if(this.formInline.planSendDate_type == 2) {
        params.payafter_day = this.formInline.planSendDay
      }
      if (this.formInline.strategyType === 2) {
        params.default_strategy_type = this.formInline.default_strategy_type
      }
      // if (this.formInline.availableFirst == 'false') {
      //   params.plan_delivery_date = this.formInline.planSendDate;
      //   params.advance_days = this.formInline.prePlanDays;
      // }
      network.post('/p/cs/pre/sell/strategy/create', params).then((res) => {
        if (res.data.code == 0) {
          this.$Message.success('新增预售策略成功');
          // this.closePage();
          this.linkToEditPage(res.data.data);
        } else if (res.data.code == 1) {
          this.errorNameShow = true;
          this.errorName = '已存在相同的策略名称，请检查后重新输入';
        } else if (res.data.code == 2) {
          this.errorKeyShow = true;
          this.errorKey = '已存在相同的识别关键字，请检查后重新输入';
        } else {
          this.$Message.error(res.data.message);
        }
      });
    },
    closeTab() {
      // 关闭自定义界面，
      const { path } = this.$route;
      const { keepAliveModuleName, tableName } = this.$store.state.global.activeTab;
      this.$store.commit('global/tabCloseAppoint', {
        tableName,
        routeFullPath: path,
        keepAliveModuleName,
        stopRouterPush: false,
      });
    },
    closePage() {
      // 关闭自定义界面，
      const { path } = this.$route;
      const { keepAliveModuleName, tableName } = this.$store.state.global.activeTab;
      this.$store.commit('global/tabCloseAppoint', {
        tableName,
        routeFullPath: path,
        keepAliveModuleName,
        stopRouterPush: false,
      });
      // 跳转
      setTimeout(() => {
        R3.store.commit('global/tabOpen', {
          type: 'S',
          tableName: 'T_OMSPRESELLSTRATEGY',
          tableId: '11407',
          back: true
        });
      }, 0);
    },
    linkToEditPage(objId) {
      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: 'EDITPRESALESTRATEGY',
          customizedModuleId: objId,
        })
      }, 0);
    },

    // 【排除平台SKU编码】勾选变化
    onCheckChange(val) {
      if (val === false) {
        this.formInline.exclude_extskuid = ''
      }
    },
  },
};
</script>
<style lang='less'>
.SystemParamsSetting .ark-form .ark-form-item-label {
  color: #333;
}
.SystemParamsSetting .ark-select-single .ark-select-selection,
.SystemParamsSetting input.ark-input {
  height: 32px;
}
.SystemParamsSetting
  .ark-select-single
  .ark-select-selection
  .ark-select-placeholder,
.SystemParamsSetting
  .ark-select-single
  .ark-select-selection
  .ark-select-selected-value,
.SystemParamsSetting .ark-input-icon {
  height: 32px;
  line-height: 32px;
}
.SystemParamsSetting .DropDownSelectInput .ark-input-icon.iconios-search {
  display: none;
}
.SystemParamsSetting .DropDownSelectInput input.ark-input {
  height: 36px !important;
}
.SystemParamsSetting .ark-date-picker-cells span em,
.SystemParamsSetting .ark-date-picker-cells-cell-today em {
  color: unset;
}
.SystemParamsSetting
  .ark-date-picker-cells-cell.ark-date-picker-cells-cell-prev-month
  em,
.SystemParamsSetting
  .ark-date-picker-cells-cell.ark-date-picker-cells-cell-next-month
  em {
  color: #d8d8d8 !important;
}
.showTipModel .fcWarning {
  color: #f7b901;
  font-size: 24px;
  margin-right: 10px;
  vertical-align: middle;
}
.showTipModel p {
  height: 50px;
  line-height: 50px;
}
.showTipModel .ark-modal-footer .ark-btn {
  border: 1px solid var(--primary-color);
  background: #fff;
  color: var(--primary-color);
}
.SystemParamsSetting .ark-form .ark-input-wrapper textarea {
  min-height: 60px !important;
}
.SystemParamsSetting .ark-form-item-error-tip-right {
  position: absolute;
  top: 5px;
  left: 250px;
  line-height: 1;
  padding-top: 6px;
  color: #fd6442;
}
</style>
<style lang='less' scoped>
.quickOperation {
  position: fixed;
  top: 82px;
  background: #fff;
  width: 100%;
  z-index: 10;
  height: 64px;
  display: flex;
  align-items: center;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
  padding-left: 16px;
}
.r3-vertical-content .quickOperation{ 
  top: 32px;
}
.paramsBox {
  margin-top: 64px;
  padding: 8px 8px;
}
.bottomTips {
  color: #989898;
  font-size: 12px;
  line-height: 20px;
  margin-top: 6px;
}
.foldpanelDIV {
  margin-bottom: 10px;
}

.shopSelect {
  .selectPart {
    display: flex;
    width: 700px;
    .selectGroup {
      flex: 1;
      height: 52px;
      overflow: hidden;
      margin-top: 8px;
      display: flex;
      flex-wrap: wrap;
      .groupItem {
        background: #f2f2f2;
        border-radius: 2px;
        margin-right: 8px;
        margin-bottom: 8px;
        padding: 0 8px;
        height: 18px;
        font-size: 11px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
        line-height: 16px;
      }
    }
    .selectBtn {
      display: flex;
      height: 40px;
      color: #0f6afb;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
    }
  }
}

.sub-item {
  margin-top: 8px;
  display: flex;
  align-items: flex-start;
}
</style>
