<template>
  <div style="width:100%">
    <!-- <div
      v-if="isFirst"
      class="firstModal"
    >
      <div style="width:100%">
        <p
          style="word-break: break-all;"
          v-html="externalOptions.massage"
        />
      </div>
      <div
        class="pop-btn"
        style="display:flex;justify-content: flex-end;"
      >
        <Button
          type="fcdefault"
          class="sav-btn"
          @click="toSecond"
        >
          确定
        </Button>
      </div>
    </div> -->
    <div
      class="secondModal"
    >
      <div v-if="isFirst">
        <div style="width:100%">
          <p
            style="word-break: break-all;"
            v-html="externalOptions.massage"
          >
            <!-- 订单[{{ mergeIds }}]为可以合并的订单,是否继续审核? -->
          </p>
        </div>
        <div
          class="pop-btn"
          style="display:flex;justify-content: flex-end;margin-top: 8px;"
        >
          <!-- <Button
            class="cancel-btn"
            style="margin-right:8px"
            @click="toHandle"
            v-if="externalOptions.showHandlerButton"
          >
            去处理
          </Button> -->
          <Button
            class="cancel-btn"
            style="margin-right:8px"
            @click="close"
          >
            取消
          </Button>
          <Button
            v-if="externalOptions.mergeIds.length == 0"
            type="fcdefault"
            class="sav-btn"
            @click="close"
          >
            确定
          </Button>
          <Button
            v-else
            type="fcdefault"
            class="sav-btn"
            @click="toBatchAudit"
          >
            继续审核
          </Button>
          <!-- <Button
            class="cancel-btn"
            style="margin-left:8px"
            @click="close"
          >
            取消
          </Button> -->
        </div>
      </div>
      <div v-else>
        <div style="width:100%;">
          <p
            style="word-break: break-all;"
            v-html="errorMsg"
          />
        </div>
        <div
          class="pop-btn"
          style="display:flex;justify-content: flex-end;"
        >
          <Button
            type="fcdefault"
            class="sav-btn"
            @click="close"
          >
            确定
          </Button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  const R3 = window.R3;
  const { network, urlSearchParams, store } = R3;
  export default {
    props: {
      externalOptions: {
        type: Object,
        default: ()=>{}
      },
    },
    data() {
      return {
        model1: true,
        MyStr: '',
        isFirst: true, // 第一个弹窗
        ifSecond: true, // 第二个弹窗
        mergeIds: '', // 第二个弹窗内容
        errorMsg: '', // 失败原因
      };
    },
    methods: {
      // 跳转到订单编辑页面
      toHandle() {
        console.log(111,this.externalOptions.orderIds)
        window.parent.R3.store.commit('global/tabOpen', {
          type: 'C',
          customizedModuleName: 'ORDERMANAGEMENTEDITOR',
          customizedModuleId: this.externalOptions.orderIds[0],
          label: '订单编辑',
        });
        this.close()
      },

      // // 判断是否弹出第二次弹窗
      // toSecond() {
      //   if (this.externalOptions.mergeIds.length) { // 有可合并的订单
      //     this.isFirst = false;
      //     this.mergeIds = this.externalOptions.mergeIds.join();
      //   } else {
      //     // 成功关闭弹框
      //     this.externalOptions.refresh();// 手动刷新页面
      //     this.$emit('cancel');
      //   }
      // },

      // 第二次调接口合并订单
      toBatchAudit() {
        // let str = this.externalOptions.massage.substring(this.externalOptions.massage.indexOf('[') + 1, this.externalOptions.massage.indexOf(']'));
        // let arr = [];
        // arr = str.split(',');
        let data = {
          orderids: this.externalOptions.mergeIds,
          ismerge: false
        };
        network.post('/p/cs/auditorder', data).then((res) => {
          if (res.data.code == 0) {
            this.$Message.success(res.data.message);
            // 成功关闭弹框
            this.externalOptions.refresh();// 手动刷新页面
            // this.$emit('cancel');
            this.close();
          } else if (res.data.code == 10) {
            this.ifSecond = false;
            this.errorMsg = res.data.message;
            this.close();
          }
        });
      },
      close() {
        // 成功关闭弹框
        if (this.externalOptions.type == 'detail') {
          this.$emit('cancel');
        } else if(this.externalOptions.type == 'list') {
          document.querySelector('#refresh').click(); // 标准列表刷新按钮
          this.$emit('cancel');
        }else {
          this.externalOptions.refresh();// 手动刷新页面
          this.$emit('cancel');
        }
      }
    }

  };
</script>
<style lang="less" scoped>
  .firstModal{
    width: 100%;
  }
  .secondModal{
    width: 100%;
  }
</style>
