<template>
    <div>
      <p>{{ tip }}</p>
      <DialogFooter
        confirmText="继续"
        :onCancel="onCancel"
        :onConfirm="onConfirm"
      ></DialogFooter>
    </div>
  </template>
  
  <script>
  import DialogFooter from '@yunque/component/modal/commonModal/dialog-footer.vue'
  
  const R3 = window.R3;
  const { network, urlSearchParams } = R3;
  
  
  export default {
    name: 'ReplaceGoodStratege',
  
    components: {
      DialogFooter,
    },
    props: {
      selectRowData: {// 获取ID用于多选,获取勾选的明细对应的row内的数据
        type: [Array, Object],
        default: () => {}
      },
      idArray: {// 可获取明细表勾选的明细ID
        type: [Array, Object],
        default: () => {}
      },
    },
  
    data() {
      return {
        choosedFlag: false,
        formData: {},
        tip: '当前的操作会对筛选出的数据执行全量替换，是否继续操作？'
      };
    },
  
    created() {
      if (this.selectRowData.length > 0) {
        this.choosedFlag = true;
        this.tip = '当前的操作会对勾选的数据执行替换，是否继续操作？';
      }
      this.getFormData();
    },
  
    methods: {
      async getFormData() {
        const dom = document.querySelector(".ListsForm-box");
        if (dom) {
          const vm = dom.__vue__
          const data = await vm.getFormData();
          if(this.idArray.length > 0){
            data.OMSID = this.idArray.join(' ')
          }
          this.formData = data
        }
      },
  
      execute() {
        const params = {
          searchdata: {
            table: 'T_V_OMSONLINEORDER',
            startindex: 0,
            range: 10,
            fixedcolumns: this.formData,
            column_include_uicontroller: true,
            isolr: true,
            getsumfileds: true
          }
        }
  
        network.post('/p/cs/replaceSkuStrategy/execute', urlSearchParams(params)).then(res => {
          if(res.data.code === 0) {
            this.$Message.success(res.data.message);
          }
        }).finally(() => {
          this.close()
        })
      },
  
      onConfirm() {
        this.execute()
      },
  
      close() {
        this.$emit('closeActionDialog', false);
      },
  
      onCancel() {
        this.close()
      }
    },
  };
  </script>
  
  <style lang="less" scoped>
  </style>
  