<template>
  <div style="width:600px">
    <div>
      <div style="margin-bottom: 16px;line-height: 20px;">
        <span>请选择需要开具发票的订单</span>
        <!-- ，下拉选择内容为该合并订单中的所有平台单号，一个平台单号为一个选项值； -->
      </div>
      <div style="display: flex;align-items: center;margin-bottom: 16px;">
        <label style="width: 70px;"><span style="color: red">*</span>平台单号</label>
        <!-- clearable -->
        <Select
          v-model="billType"
        >
          <Option
            v-for="(option,index) in billTypeArr"
            :key="index"
            :value="option.value"
          >
            {{ option.label }}
          </Option>
        </Select>
      </div>
      <footer style="display: flex; justify-content: flex-end; margin-top: 16px">
        <Button
          type="fcdefault"
          style="width: 80px; height: 34px; font-size: 14px"
          @click="cancelModal"
        >
          取消
        </Button>
        <Button
          type="posdefault"
          style="width: 80px; height: 34px; font-size: 14px; margin-left: 8px"
          @click="okToAddBill"
        >
          确定
        </Button>
      </footer>
    </div>
  </div>
</template>
<script>
  const R3 = window.R3;
  const { network, urlSearchParams, store } = R3;
  export default {
    props: {
      externalOptions: {
        type: Object,
        default: ()=>{}
      },
    },
    data() {
      return {
        billType: '', // 选择的单据类型
        billTypeArr: [],
      };
    },
    created() {
      let TIDs = this.externalOptions.selectArray[0].TID.val.split(',');
      TIDs.forEach(item => {
        this.billTypeArr.push({
          label: item,
          value: item
        });
      });
    },
    methods: {
      //   取消按钮
      cancelModal() {
        // this.externalOptions.refresh();// 手动刷新页面
        this.$emit('cancel');
      },
      // 确定添加赠品
      okToAddBill() {
        this.cancelModal();
        if (!this.billType) {
          return this.$Message.warning('没有选择平台单号');
        }
        let params = {
          platformTid: this.billType
        };
        network.post('/p/cs/checkInvoiceParam', params).then((res) => {
          if (res.data.code == 0) {
            R3.store.commit('global/tabOpen', {
              type: 'tableDetailAction' || 'C',
              label: '手工开票',
              url: `/CUSTOMIZED/ADDINVOICE/3530?OMSID=${this.externalOptions.selectArray[0].OMSID.val}&TID=${this.billType}`,
            });
          }
        });
      }
    }
  };
</script>
<style lang="less" scoped>

</style>
