<template>
  <!-- <Modal
    v-model="model1"
    title="提示"
    :mask="mask"
    @on-ok="toBatchAudit"
  >
    
  </Modal> -->
  <div>
    <div>
      <p v-html="OneMsg" />
    </div>
    <div
      class="pop-btn"
      style="display:flex;justify-content: flex-end;"
    >
      <Button
        type="fcdefault"
        class="sav-btn"
        @click="toBatchAudit"
      >
        确定
      </Button>
      <Button
        class="cancel-btn"
        style="margin-left:8px"
        @click="close"
      >
        取消
      </Button>
    </div>
  </div>
</template>
<script>
  const R3 = window.R3;
  const { network, urlSearchParams, store } = R3;
  export default {
    props: {
      externalOptions: {
        type: Object,
        default: ()=>{}
      },
    },
    data() {
      return {
        OneMsg: '',
        model1: true,
        MyStr: '',
        flag: 'one',
        orderids: [],
        itemList: '',
        itemListOne: '',
        itemListTwo: '',
      };
    },
    created() {
      let list = JSON.parse(this.externalOptions.massage).list;
      if (list.length > 1) {
        this.itemList = list.find((item) => item.code == '19');
        this.itemListOne = list.find((item) => item.code == '10');
        this.itemListTwo = list.find((item) => item.code == '-1');
        if (this.itemListOne && this.itemList) {
          this.flag = 'two';
          if (list.length == '2') {
            this.OneMsg = `${JSON.parse(this.externalOptions.massage).msg}:</br>订单[${this.itemListOne.orderids.join(',')}]${this.itemListOne.msg}`;
            this.orderids = this.itemListOne.orderids;
          } else if (list.length == '3') {
            this.OneMsg = `${JSON.parse(this.externalOptions.massage).msg}:</br>订单[${this.itemListOne.orderids.join(',')}]${this.itemListOne.msg}`;
            this.OneMsg += `</br>订单[${this.itemListTwo.orderids.join(',')}]${this.itemListTwo.msg}`;
            this.orderids = [...this.itemListOne.orderids, ...this.itemListTwo.orderids];
          }
        } else {
          this.flag = 'one';
          list.forEach((item, index) => {
            if (index != list.length - 1) {
              this.OneMsg = `${JSON.parse(this.externalOptions.massage).msg}:</br>订单[${item.orderids.join(',')}]${item.msg}`;
            } else {
              this.OneMsg += `</br>订单[${item.orderids.join(',')}]${item.msg}`;
            }
            this.orderids = [...this.orderids, ...item.orderids];
          });
        }
      } else {
        this.flag = 'one';
        list.forEach(item => {
          this.OneMsg = `${JSON.parse(this.externalOptions.massage).msg}:</br>订单[${item.orderids.join(',')}]${item.msg}`;
          this.orderids = [...this.orderids, ...item.orderids];
        });
      }
    },
    methods: {
      toBatchAudit() {
        // let str = this.externalOptions.massage.substring(this.externalOptions.massage.indexOf('[') + 1, this.externalOptions.massage.indexOf(']'));
        let arr = [];
        arr = this.orderids;
        // arr = str.split(',');
        console.log(arr);
        let data = {
          tableName: 'T_V_OMSONLINEORDER', 
          ids: arr, 
          actionName: 'T_V_OMSONLINEORDER_恢复拦截_sp_2' 
        };
        network.post('/p/cs/exeAction', data).then((res) => {
          if (res.data.code == 0) {
            this.$Message.success(res.data.message);
          }
          // 成功关闭弹框
          // this.externalOptions.refresh();// 手动刷新页面
          // this.$emit('cancel');
          this.close();
        });
      },
      close() {
        if (this.flag == 'two') {
          // 成功关闭弹框
          this.externalOptions.refresh();// 手动刷新页面
          this.$emit('cancel');
          let refresh = this.searchClickData;
          this.$R3Dialog({
            dialogComponentName: 'ResumeInterceptionTwo', // 自定义的弹框组件
            title: '恢复拦截', // 弹框标题
            footerHide: true,
            externalOptions: {
              msg: JSON.parse(this.externalOptions.massage).msg,
              massage: this.itemList, // msg
              refresh
            }
          }, () => {
          });
        } else {
          this.externalOptions.refresh();// 手动刷新页面
          this.$emit('cancel');
        }
      }
    }
    
  };
</script>
