<template>
  <div class="SystemParamsSetting" data-key="SYSTEM_PAGE">
    <div class="quickOperation">
      <!-- 快捷操作： -->
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click="saveParams"
      >
        保存
      </Button>
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click="refreshParams"
      >
        刷新
      </Button>
      <Button
        type="fcdefault"
        style="margin-right:8px"
        @click="closeTab"
      >
        关闭
      </Button>
      <Button
        type="fcdefault"
        @click="openOrCloseFanol"
      >
        {{buttonText}}
      </Button>
    </div>
    <div class="paramsBox">
      <div
        v-for="(panel,index) in paramsList"
        :key="index"
        class="foldpanelDIV"
      >
        <foldPanel
          v-model="panel.show"
          :title="panel.paramName"
          v-if="panel.sysParam.length>0"
        >
          <div
            slot="content"
            class="block"
          >
            <div class="item">
              <Form
                ref="systemSetting"
                :model="systemSetting"
                :label-width="206"
                label-position="right"
              >
                <FormItem
                  v-for="(param, indexPar) in panel.sysParam"
                  v-show="(
                    (param.paraName == 'jit_pick_order_type_wms' && isShoParamNameValues['jit_uselarkdistribution'] == 'WMS') ||
                    (param.paraName == 'KeepLeft' && isShowSplitType == 1) ||
                    (param.paraName == 'KeepRight' && isShowSplitType == 2) ||
                    (param.paraName == 'CutRight' && isShowSplitType == 3) ||
                    (param.paraName == 'CutLeft' && isShowSplitType == 3) ||
                    (param.paraName == 'FIRSTLOGISTICSRULE' && isShowFirstLogisticsRule) ||
                    (param.paraName == 'SA_RECEIVABLESUB' && isShowSELFDRP) ||
                    (param.paraName == 'SA_PAYABLESUB' && isShowSELFDRP) ||
                    (
                      param.paraName !== 'CutRight' &&
                      param.paraName !== 'CutLeft' &&
                      param.paraName !== 'KeepLeft' &&
                      param.paraName !== 'KeepRight' &&
                      param.paraName !== 'FIRSTLOGISTICSRULE' &&
                      param.paraName !== 'SA_RECEIVABLESUB' &&
                      param.paraName !== 'SA_PAYABLESUB' &&
                      param.paraName !== 'jit_pick_order_type_wms'
                    )
                  )"
                  :class='(param.paraName == "DINGJINBUTUIXINDANSHANGPINSKU" && !isShowDingjinType)?"NoShowDingjin":""'
                  :required='param.paraName == "DINGJINBUTUIXINDANSHANGPINSKU" && isShowDingjinType'
                  :key="indexPar"
                  :data-key="param.paraName"
                  :label="param.paramDesc"
                >
                  <div v-if="param.displayType == 2" data-key="RADIO_CELL">
                    <!-- Combobox -->
                    <RadioGroup
                      v-if="param.paraValue == &quot;False&quot; || param.paraValue==&quot;True&quot;"
                      v-model="param.paraValue"
                      @on-change="changeRadio(param)"
                    >
                      <Radio label="True" :disabled="param.READONLY==1">
                        <span>是</span>
                      </Radio>
                      <Radio label="False" :disabled="param.READONLY==1">
                        <span>否</span>
                      </Radio>
                    </RadioGroup>
                    <RadioGroup
                      v-else-if="param.paraValue == &quot;false&quot; || param.paraValue==&quot;true&quot;"
                      v-model="param.paraValue"
                      @on-change="changeRadio(param)"
                    >
                      <Radio label="true" :disabled="param.READONLY==1" >
                        <span>是</span>
                      </Radio>
                      <Radio label="false" :disabled="param.READONLY==1">
                        <span>否</span>
                      </Radio>
                    </RadioGroup>
                    <RadioGroup
                      v-else
                      v-model="param.paraValue"
                      @on-change="changeRadio(param)"
                    >
                      <Radio label="1" :disabled="param.READONLY==1">
                        <span>是</span>
                      </Radio>
                      <Radio label="0" :disabled="param.READONLY==1">
                        <span>否</span>
                      </Radio>
                    </RadioGroup>
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else-if="param.displayType == &quot;3&quot;">
                    <!-- Numberbox -->
                    <!-- <InputNumber
                      v-model="param.paraValue"
                      :precision="precision"
                      style="width: 100px;margin-right: 8px;"
                    /> -->
                    <Input
                      v-model="param.paraValue"
                      :placeholder="param.paraName=='expiredDaysByLogin'?'请输入天数，单位：天':''"
                      :regx="(param.paraName=='expiredDaysByLogin' || param.paraName=='RANKING_GIFT_WAITING_TIME')?regx2:regx"
                      style="width: 240px"
                    />
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else-if="param.displayType == &quot;4&quot;">
                    <!-- Datebox -->
                    <DatePicker
                      v-model="param.paraValue"
                      type="date"
                      format="yyyy-MM-dd"
                      placeholder=""
                      style="width: 240px"
                      :editable="editable"
                      is-emit-on-change
                      @on-change="changeDate(param)"
                    />
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else-if="param.displayType == &quot;5&quot;">
                    <ImageUpload
                        multiple
                        :dataitem="dataitem"
                        @uploadFileChangeSuccess='changeSuccess'
                        @deleteImg="deleteImg"
                    ></ImageUpload>
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else-if="param.displayType == &quot;13&quot;">
                    <!-- CheckBox -->
                    <!-- v-if="(param.adLimitValueContext == null && param.paraValue !== null) || (param.adLimitValueContext && param.adLimitValueContext.length>0 && param.paraValue !== null)" -->
                    <Input
                      v-if="(param.adLimitValueContext == null && param.paraValue !== null) || (param.adLimitValueContext && param.adLimitValueContext.length == 0 && param.paraValue !== null)"
                      :regx="getRegx(param)"
                      v-model="param.paraValue"
                      placeholder=""
                      style="width: 240px"
                    />
                    <Select
                      v-else
                      data-key="SELECT_CELL"
                      v-model="param.paraValue"
                      style="width:240px"
                      @on-change="changeSelectValue(param)"
                      :clearable="param.clearable"
                      :disabled="param.paraName == 'DW_INSTORAGE_DISTRISYS' || param.paraName == 'DW_OUTSTORAGE_DISTRISYS'"
                    >
                      <Option
                        v-for="item in param.valueList"
                        :key="item.value"
                        :value="item.value"
                      >
                        {{ item.label }}
                      </Option>
                    </Select>
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else-if="param.displayType == &quot;15&quot;">
                    <!-- textarea -->
                    <Input
                      v-model="param.paraValue"
                      type="textarea"
                      :autosize="true"
                      style="width:300px"
                      placeholder=""
                    />
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else-if="param.displayType ==  &quot;16&quot;">
                    <DropMultiSelectFilter
                      single
                      class="input_box"
                      :data="SystemSKUList"
                      :totalRowCount="SystemSKUList.totalRowCount"
                      :showColnameKey="'isak'"
                      :defaultSelected="defaultSelectedSystemSKU"
                      @on-page-change="changePageShop($event,param)"
                      @on-input-value-change="InputValueChangeShop($event,param)"
                      @on-popper-show="searchShopData(param)"
                      @on-fkrp-selected="checkDataShop($event,param)"
                      @on-clear="clearDataShop($event,param)"
                      :dataEmptyMessage="dataEmptyMessage"
                      :columns="columnsSystemSKU"
                      :AutoData="SystemSKUAutoData">
                    </DropMultiSelectFilter>
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else-if="param.displayType ==  &quot;20&quot;">
                    <DropMultiSelectFilter
                      class="input_box"
                      placeholder="请选择拦截原因"
                      :data="interceptionList"
                      :totalRowCount="interceptionList.totalRowCount"
                      :showColnameKey="'isak'"
                      :defaultSelected="defaultSelectedInterception"
                      @on-page-change="changePageShop($event,param)"
                      @on-input-value-change="InputValueChangeShop($event,param)"
                      @on-popper-show="searchShopData(param)"
                      @on-fkrp-selected="checkDataShop($event,param)"
                      @on-clear="clearDataShop($event,param)"
                      :dataEmptyMessage="dataEmptyMessage"
                      :columns="columnsinterception"
                      :AutoData="interceptionAutoData">
                    </DropMultiSelectFilter>
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else-if="param.displayType ===  21">
                    <CheckboxGroup v-model="param.paraValue">
                      <Checkbox v-for="option in param.options" :key="option.label" :label="option.label"></Checkbox>
                    </CheckboxGroup>
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                  <div v-else>
                    <!-- 其他 -->
                    <Input
                      v-model="param.paraValue"
                      placeholder=""
                      :regx="getRegx(param)"
                      style="width: 240px"
                    />
                    <p
                      v-if="param.remark"
                      class="bottomTips"
                    >
                      {{ param.remark }}
                    </p>
                  </div>
                </FormItem>
              </Form>

            </div>
          </div>
        </foldPanel>
      </div>
    </div>
    <Modal
      v-model="showTip"
      mask
      :mask-closable="maskClosable"
      title="警告"
      title-align="left"
      class-name="showTipModel"
      width="400px"
      @on-ok="getParamsList"
    >
      <p><i class="iconfont iconbj_doubt fcWarning " />修改的数据未保存，确定刷新？</p>
    </Modal>
    <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 foldPanel from '../customizedContent/FoldPanel.vue';

  const R3 = window.R3;

  const { network, urlSearchParams } = R3;
  export default {
    components: { foldPanel, R3CheckboxGroup:R3.components.CheckboxGroup },
    data() {
      return {
        systemSetting: {},
        paramsList: [],
        paramsListOld: [],
        count: 0,
        adIDList: [],
        showTip: false,
        maskClosable: false,
        precision: 2,
        regx: /^-?\d{0,15}(\.[0-9]{0,2})?$/,
        regx2: /^\d+$/, // 正整数  /^\d{0,15}?$/
        spinShow: true,
        editable: false,
        status: true,

        isShowSplitType: 0, // 0.无保留无截断1.商品sku左边保留2.商品sku右边保留3.商品sku截断
        isShowFirstLogisticsRule: false, // 是否展示优先物流规则
        isShowDingjinType: false, // 定金不退新单商品sku是否展示
        isShowSELFDRP: false, // 是否使用云雀分销模块，决定是否展示相关字段
        isShoParamNameValues: {},// {key1: value1 }, 仅仅控制其他选项是否显示

        dataitem: {
            url: '/p/cs/upload2', // 上传地址
            sendData: {}, // 上传参数
            width: 150,
            height: 150,
            length: 2,
            readonly: false,
            valuedata: [],
            name: '上传'  //点击上传按钮名称
        },

        // 平台商品选择商品弹框系统SKU编码参数
        SystemSKUList: {}, // 系统SKU编码下拉展示数据
        SystemSKUtotalRowCount: 0,
        SystemSKUcurrentIndex: 0, // 系统SKU编码搜索初始index
        SystemSKUAutoData: [], // 系统SKU编码模糊搜索的结果组
        columnsSystemSKU: ['name', 'value'], // 展现的组
        defaultSelectedSystemSKU: [],
        dataEmptyMessage: '数据加载中...', // 无数据的提示
        checkedSKUSList: [], // 定金不退新单商品sku选择的sku存储值

        // 多选拦截原因
        interceptionList: {}, // 多选拦截原因下拉展示数据
        interceptiontotalRowCount: 0,
        interceptioncurrentIndex: 0, // 多选拦截原因搜索初始index
        interceptionAutoData: [], // 多选拦截原因模糊搜索的结果组
        columnsinterception: ['name', 'value'], // 展现的组
        defaultSelectedInterception: [],
        dataEmptyMessage: '数据加载中...', // 无数据的提示
        checkedInterceptionList: [], // 多选拦截原因选择的sku存储值

        regx1: /^([0-9]|10)$/, // 0-10的整数
        buttonText: '收起',
      };
    },
    created() {
      // this.getParamsTypeList();
      this.getParamsList();
    },
    methods: {
      openOrCloseFanol() {
        if(this.buttonText == '收起') {
          this.paramsList.forEach(item => {
            item.show = false
          })
          this.buttonText = '展开'
        }else if(this.buttonText == '展开') {
          this.paramsList.forEach(item => {
            item.show = true
          })
          this.buttonText = '收起'
        }
        this.paramsList = JSON.parse(JSON.stringify(this.paramsList))
      },
      getRegx(param) {
        if(param.paraName == 'MERGETIME' || param.paraName == 'billoverdays' || param.paraName == 'WeightAutoSubmitTimes') {
          return this.regx1
        } else if(param.paraName == 'vop_pick_split_cnt') {
          return /^[1-9]\d*$/
        } else if(param.paraName == 'REFUND_CVT_WAIT_DAYS') { // 订单、退单超时未转换时间
          return /^([0-9]|10)$/ // 0-10的整数
        } else if(param.paraName == 'REFUND_NOTIN_STOCK_TIMEOUT') { // 退回包裹超时未入库监控时间
          return /^\d+$/ // 正整数
        } else if (param.paraName == 'PrintMaxNum') {
          return /^(100|[1-9]?[0-9])$/
        } else {
          return param.paraName == 'WeightDeviationRange'?this.regx:''
        }
      },
      changeSuccess(e) {
        let obj = {
          NAME: e.data.Name,
          URL: e.data.Url,
        }
        this.dataitem.valuedata = [obj];
        this.paramsList.forEach(item => {
          item.sysParam.forEach(sysParam => {
            if (sysParam.displayType == 5 && sysParam.paraName == 'indeximg') {
              sysParam.paraValue = e.data.Url
            }
          })
        })
      }, //图片上传成功回调函数
      deleteImg(e) {
        this.dataitem.valuedata.forEach((item,index)=>{
          if(item.URL == e.URL){
            this.dataitem.valuedata.splice(index,1)
          }
        })
        this.paramsList.forEach(item => {
          item.sysParam.forEach(sysParam => {
            if (sysParam.displayType == 5 && sysParam.paraName == 'indeximg') {
              sysParam.paraValue = ''
            }
          })
        })
      }, //t图片删除回调函数
      changeSelectValue(param) {
        const { paraName,  paraValue } = param || {};
        if (param.paraName == 'CustomScannSkuPlan') {
          this.isShowSplitType = param.paraValue;
          this.paramsList[1].sysParam.forEach(item => {
            if (item.paraName == 'KeepLeft' || item.paraName == 'KeepRight' || item.paraName == 'CutRight' || item.paraName == 'CutLeft') {
              item.paraValue = 0;
            }
          });
        }
        if (param.paraName == 'LogisticsRuleType') {
          this.isShowFirstLogisticsRule = param.paraValue == 3?true:false;
        }
        this.isShoParamNameValues[paraName] = paraValue;
        // console.log(param, 'param_001');
        // console.log(this.isShoParamNameValues, 'isShoParamNameValues_01');
      },
      changeRadio(param) {
        if(param.paraName == 'PRESALECANCELISJOINRECONCILIATION'){
          if(param.paraValue == 'True' || param.paraValue == 'true' || param.paraValue == 'TRUE'){
            this.isShowDingjinType = true;
          } else {
            this.isShowDingjinType = false;
          }
        }
        if(param.paraName == 'SELFDRP'){
          if(param.paraValue == 'True' || param.paraValue == 'true' || param.paraValue == 'TRUE'){
            this.isShowSELFDRP = true;
          } else {
            this.isShowSELFDRP = false;
          }
        }
      },
      dateChange(date) {
        let d = new Date(date);
        let datetime = `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
        return datetime;
      },
      changeDate(param) {
        param.paraValue = this.dateChange(param.paraValue);
      },
      getParamsList(type) {
        network.post('/p/cs/getSysParams', {}).then(res => {
          if (res.data.code == 0) {
            this.count = 0;
            this.adIDList = [];
            const data = res.data.data;
            const allParams = {};
            data.forEach(item => {
              if (item.sysParam.length > 0) {
                item.sysParam.forEach(sysParam => {
                  if (sysParam.displayType == 3) {
                    sysParam.paraValue = sysParam.paraValue == null ? '' : Number(sysParam.paraValue);
                  }
                  if (sysParam.displayType == 4) {
                    sysParam.paraValue = sysParam.paraValue == null ? '' : sysParam.paraValue;
                  }
                  if (sysParam.displayType == 5) {
                    sysParam.paraValue = !sysParam.paraValue? '' : sysParam.paraValue;
                    this.dataitem.valuedata = !sysParam.paraValue?[]:[{URL:sysParam.paraValue}];
                  }
                  if (sysParam.paraName == 'BillAmount_max' || sysParam.paraName == 'BillAmount_min') {
                    if (sysParam.paraValue == null || sysParam.paraValue == '') {
                      sysParam.paraValue = 0;
                    }
                  }
                  if (sysParam.adLimitValueContext) {
                    if (sysParam.adLimitValueContext !== null) {
                      if (sysParam.adLimitValueContext.length > 0) {
                        if (sysParam.paraName == 'CustomScannSkuPlan') {
                          this.isShowSplitType = sysParam.paraValue;
                        }
                        let valueList = [];
                        sysParam.adLimitValueContext.forEach(adLimit => {
                          let obj = {
                            value: adLimit.VALUE,
                            label: adLimit.DESCRIPTION
                          };
                          valueList.push(obj);
                        });
                        sysParam.valueList = valueList;
                      }
                    }
                  }
                  if(sysParam.paraName == 'PRESALECANCELISJOINRECONCILIATION'){
                    if(sysParam.paraValue == 'True' || sysParam.paraValue == 'true' || sysParam.paraValue == 'TRUE'){
                      this.isShowDingjinType = true;
                    }else {
                      this.isShowDingjinType = false;
                    }
                  }
                  if(sysParam.paraName == 'DINGJINBUTUIXINDANSHANGPINSKU') {
                    let list = [];
                    if(sysParam.skus && sysParam.skus.length > 0){
                      sysParam.skus.forEach(item => {
                        let obj = {
                          ID: String(item.id),
                          Label: item.sku
                        }
                        list.push(obj)
                      })
                    }
                    this.defaultSelectedSystemSKU = list;
                  }
                  if(sysParam.paraName == 'DO_NOT_INTERCEPT_ORDERS') {
                    let list = [];
                    if(sysParam.skus && sysParam.skus.length > 0){
                      sysParam.skus.forEach(item => {
                        let obj = {
                          ID: item.id,
                          Label: item.sku
                        }
                        list.push(obj)
                      })
                    }
                    this.defaultSelectedInterception = list;
                  }
                  if (sysParam.paraName == 'LogisticsRuleType') {
                    this.isShowFirstLogisticsRule = sysParam.paraValue == 3?true:false;
                  }
                  
                  if (sysParam.paraName == 'SELFDRP') {
                    if(sysParam.paraValue == 'True' || sysParam.paraValue == 'true' || sysParam.paraValue == 'TRUE'){
                      this.isShowSELFDRP = true;
                    }else {
                      this.isShowSELFDRP = false;
                    }
                  }
                  if(sysParam.displayType === 21) {
                    const originValue = sysParam.paraValue || ''
                    const originValueArr = originValue.split(',')
                    const defaultValue = []
                    sysParam.options.forEach(option => {
                      if(originValueArr.includes (option.value)) {
                        defaultValue.push(option.label)
                      }
                    })
                    sysParam.paraValue = defaultValue
                  }
                  if(sysParam.paraName === 'ISOPENLIVESERVICE') {
                    let isFold = sysParam.paraValue === 'True' ? true : false;
                    window.localStorage.setItem('ISOPENLIVESERVICE',isFold);

                  }
                  // 缓存默认值控制是否显示其他选项
                  this.isShoParamNameValues[sysParam.paraName] = sysParam.paraValue;
                  allParams[sysParam.paraName] = sysParam.paraValue;// 缓存更新到全局-修改后会再次调用这里
                });
              }
            });
            this.$store.commit('customize/setSystemParams', allParams);
            this.paramsList = data
            console.log(this.paramsList, 'this.paramsList');
            this.paramsList.forEach(item => {
              item.show = true;
              if(this.buttonText == '展开'){
                this.buttonText = '收起'
              }
            })
            this.paramsListOld = JSON.parse(JSON.stringify(this.paramsList));

            if (type == 'refresh') {
              this.$Message.success('刷新参数成功');
            }
            this.spinShow = false;
          }
        });
      },
      getLocalParamsList(arr) {
        let arr1 = [];
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].sysParam.length > 0) {
            arr[i].sysParam.forEach(item => {
              let obj = {
                id: item.id,
                paraValue: item.paraValue,
                displayType: item.displayType,
                paraName: item.paraName
              };
              arr1.push(obj);
            });
          }
        }
        return arr1;
      },

      // 获取系统参数
      // getSystemList(data) {
      //   return data.find(item => item.paramName === '对接WMS/ERP参数')
      // },
      // 获取系统参数
      getSystemList(data,obj) {
        let objOne = {}
        data.forEach(item => {
          item.sysParam.forEach(itemOne => {
            if(itemOne.paraName == obj.paraName){
              objOne = item
            }
          })
        })
        return objOne
        // return data.find(item => item.paramName === '对接WMS/ERP参数')
      },

      getChangeParamsNow() {
        let newList = this.getLocalParamsList(this.paramsList);
        let oldList = this.getLocalParamsList(this.paramsListOld);
        let changeList = [];
        for (let i = 0; i < newList.length; i++) {
          if(newList[i].displayType === 21) {
            const oldValue = oldList[i].paraValue.join(',')
            const newValue = newList[i].paraValue.join(',')
            if(oldValue !== newValue) {
              const selectValue = newList[i].paraValue
              const systemList = this.getSystemList(this.paramsList,newList[i])
              const currentObj = systemList.sysParam.find(item => item.paraName === newList[i].paraName)
              const value = currentObj.options.filter(option => selectValue.includes(option.label)).map(item => item.value).join(',')
              changeList.push({
                ...newList[i],
                paraValue: value
              })
            }
          } else if (newList[i].paraValue !== oldList[i].paraValue) {
            if (newList[i].displayType == 2) {
              if (newList[i].paraValue == 0) {
                newList[i].paraValue = 'False';
              } else if (newList[i].paraValue == 1) {
                newList[i].paraValue = 'True';
              }
              changeList.push(newList[i]);
            } else if (newList[i].displayType == 4) {
              if (newList[i].paraValue == 'NaN-NaN-NaN') {
                newList[i].paraValue = '';
              } else {
                changeList.push(newList[i]);
              }
            } else { changeList.push(newList[i]); }
          } else if (newList[i].paraValue == 'false' || newList[i].paraValue == 'true') {
            if (newList[i].displayType == 2) {
              if (newList[i].paraValue == 'false') {
                newList[i].paraValue = 'False';
              } else if (newList[i].paraValue == 'true') {
                newList[i].paraValue = 'True';
              }
            }
            changeList.push(newList[i]);
          }
        }
        return changeList;
      },
      saveParams() {
        let changeList = this.getChangeParamsNow();
        let newList = this.getLocalParamsList(this.paramsList);
        let oldList = this.getLocalParamsList(this.paramsListOld);
        if (changeList.length <= 0) {
          return this.$Message.info('当前并未更改参数，无需保存！');
        }
        let tabs = this.paramsList[0].sysParam.filter((p) => p.paraName == 'PRESALECANCELISJOINRECONCILIATION');
        let tabsOne = this.paramsList[0].sysParam.filter((p) => p.paraName == 'DINGJINBUTUIXINDANSHANGPINSKU');
        let tabsTwo = newList.filter((p) => p.paraName == 'ISUSERETURNBATCHMANAGEMENT');
        let tabsTwoOld = oldList.filter((p) => p.paraName == 'ISUSERETURNBATCHMANAGEMENT');
        if((tabs[0].paraValue == 'True' || tabs[0].paraValue == 'true' || tabs[0].paraValue == 'TRUE') && (!tabsOne[0].paraValue || tabsOne[0].paraValue.length == 0)){
          return this.$Message.info('定金不退新单商品sku不能为空！');
        }
        changeList.forEach(item => {
          if (item.paraName == 'BillAmount_min') {
            if (item.paraValue == '') {
              this.status = false;
              return this.$Message.info('可核销差异金额最小值不能为空！');
            }
            this.status = true;
          } else if (item.paraName == 'BillAmount_max') {
            if (item.paraValue == '') {
              this.status = false;
              return this.$Message.info('可核销差异金额最大值不能为空！');
            }
            this.status = true;
          } else if (item.paraName == 'DINGJINBUTUIXINDANSHANGPINSKU'){
            item.skus = this.checkedSKUSList
          }
        });
        setTimeout(() => {
          if (this.status) {
            network.post('/p/cs/batchUpdate', changeList).then((res) => {
              if (res.data.code == 0) {
                this.$Message.success('更新参数成功');
                this.getParamsList();
                if(tabsTwo[0] && tabsTwoOld[0] && (tabsTwo[0].paraValue !== tabsTwoOld[0].paraValue)){
                  let isFold = tabsTwo[0].paraValue === 'True' ? true : false;
                  window.localStorage.setItem('ISUSERETURNBATCHMANAGEMENTFLAG',isFold);
                }
                console.log('保存参数', changeList,this.paramsList);
              }
            });
          }
        }, 200);
      },
      refreshParams() {
        let changeList = this.getChangeParamsNow();
        if (changeList.length > 0) {
          this.showTip = true;
        } else {
          this.getParamsList('refresh');
        }
      },
      closeTab() {
        // 关闭自定义界面，
        const { path } = this.$route;
        const { keepAliveModuleName, tableName } = this.$store.state.global.activeTab;
        this.$store.commit('global/tabCloseAppoint', {
          tableName,
          routeFullPath: path,
          keepAliveModuleName,
          stopRouterPush: false,
        });
      },

      // 选择入库单弹框中的筛选下拉框数据start
      // 单选下拉分页改变
      changePageShop(e, param) {
        if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
          this.SystemSKUcurrentIndex = (e - 1) * 10;
          this.searchShopData(param);
        } else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){
          this.interceptioncurrentIndex = (e - 1) * 10;
          this.searchShopData(param);
        }
      },
      // 外键下拉框
      searchShopData(param) {
        let virtual = {};
        if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
          virtual = {
            searchdata: {
              isdroplistsearch: true,
              refcolid: 198192,
              startindex: this.SystemSKUcurrentIndex,
              range: 10,
            }
          };
        }else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){  //interceptionList
          virtual = {
            searchdata: {
              isdroplistsearch: true,
              refcolid: 207536,
              startindex: this.interceptioncurrentIndex,
              range: 10,
            }
          };
        }
        network.post('/p/cs/QueryList', urlSearchParams(virtual)).then((res) => {
          if (res.data.code == 0) {
            if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
              this.SystemSKUtotalRowCount = res.data.data.totalRowCount;
              this.SystemSKUList = res.data.data;
              this.SystemSKUcurrentIndex = 0;
            }else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){
              this.interceptiontotalRowCount = res.data.data.totalRowCount;
              this.interceptionList = res.data.data;
              this.interceptioncurrentIndex = 0;
            }
          }
        });
      },
      // 单选下拉模糊搜索数据
      InputValueChangeShop(e, param) {
        let virtual = {};
        if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
          virtual = {
            ak: e,
            colid: 198192,
            fixedcolumns: {}
          };
        } else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){  //interceptionList
          virtual = {
            ak: e,
            colid: 207536,
            fixedcolumns: {}
          };
        }
        network.post('/p/cs/fuzzyquerybyak', urlSearchParams(virtual)).then((res) => {
          if (res.data.code == 0) {
            let list = [];
            res.data.data.forEach(item => {
              let obj = {
                value: item.value,
                id: item.id
              };
              list.push(obj);
            });
            if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
              this.SystemSKUAutoData = list;
            }else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){
              this.interceptionAutoData = list;
            }
          }
        });
      },
      // 外键下拉框搜索
      focusInputValueChangeShop(e, param) {
        let virtual = {};
        if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
          virtual = {
            ak: e.target.value,
            colid: 198192,
            fixedcolumns: {}
          };
        } else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){  //interceptionList
          virtual = {
            ak: e.target.value,
            colid: 207536,
            fixedcolumns: {}
          };
        }
        network.post('/p/cs/fuzzyquerybyak', urlSearchParams(virtual)).then((res) => {
          if (res.data.code == 0) {
            let list = [];
            res.data.data.forEach(item => {
              let obj = {
                value: item.value,
                id: item.id
              };
              list.push(obj);
            });
            if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
              this.SystemSKUAutoData = list;
            } else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){
              this.interceptionAutoData = list;
            }
          }
        });
      },
      // 单选下拉选中
      checkDataShop(val, param) {
        this.checkedSKUSList = [];
        this.checkedInterceptionList = [];
        // let list = [];
        if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
          param.paraValue = '';
          val.forEach((item,index) => {
            if(index == val.length - 1){
              param.paraValue += item.Label;
            }else {
              param.paraValue += item.Label + ',';
            }
            // let obj = {
            //   id: Number(item.ID),
            //   sku: item.Label
            // }
            this.checkedSKUSList.push(item.Label);
          })
        } else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){
          param.paraValue = '';
          val.forEach((item,index) => {
            if(index == val.length - 1){
              param.paraValue += item.ID;
            }else {
              param.paraValue += item.ID + ',';
            }
            let obj = {
              id: Number(item.ID),
              sku: item.Label
            }
            this.checkedInterceptionList.push(obj);
          })
        }
      },
      clearDataShop(val,param) {
        if (param.paraName === 'DINGJINBUTUIXINDANSHANGPINSKU') {
          param.paraValue = [];
        } else if(param.paraName == "DO_NOT_INTERCEPT_ORDERS"){
          param.paraValue = '';
          this.defaultSelectedInterception = '';
        }
      },
      // 选择入库单弹框中的筛选下拉框数据end
    },
  };
</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 .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;
  }
  .SystemParamsSetting .iconios-close-circle-outline:before {
    color: #fff;
  }
  .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;
  }
  #dropMultiSelectPopper .ark-fktable {
    width: 330px;
  }
</style>
<style lang='less' scoped>
  .SystemParamsSetting {
    padding-top: 65px;
  }
  .quickOperation{
    position: fixed;
    top: 82px;
    background: #fff;
    width: calc(100% - 130px);
    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 {
    padding: 8px 8px;
  }
  .bottomTips {
    color: #989898;
    font-size: 12px;
    line-height: 20px;
    margin-top: 6px;
  }
  .foldpanelDIV {
    margin-bottom: 10px;
  }
  .NoShowDingjin {
    display: none;
  }
  #dropMultiSelectFilter {
    width: 400px;
  }
</style>
