<template>
    <div class="PlatformSearch" style="display:flex;">
        <Input
        v-model="TID"
        type="text"
        :disabled='isDisabled'
        class='typeInputTextOne'
        :placeholder="placeholderText"
        @on-keydown="getMessageByPlatformId"
        ></Input>
        <!--  clearable -->
        <Modal
        v-model="selectOrderModal"
        title="选择订单"
        width="400"
        :mask="mask"
        :closable="closable"
        :mask-closable="maskClosable"
        :footer-hide="hideFoot"
        @on-cancel="cancelSelectOrder">
        <div class="orderListByplatformId">
            <p style="margin-bottom: 12px;">根据输入的平台单号查询到多个订单号，请选择订单号进行操作</p>
            <div style="max-height: 200px;overflow-y: auto;">
            <p style="height:24px;line-height:24px;margin: 8px 0px;color: #0f8ee9;cursor: pointer;text-align: center;" v-for="item in orderListByplatformId" @click="chooseOrderIdbyplatform(item)">{{ item }}</p>
            </div>
        </div>
        </Modal>
    </div>
</template>
  
  <script type="text/ecmascript-6">
  const R3 = window.R3;
  const { network, urlSearchParams } = R3;
  const { setFormItemValue } = R3.componentsAttribute;
  export default {
    name: 'PlatformSearchTodo',
  
    props: {
      options: {
        type: Object,
        default: () => ({})
      },
      value: {
        type: [Array,String,Number],
        default: () => ''
      }
    },
  
    data() {
      return {
        isDisabled: false,
        regx1:/^\d{0,15}?$/,
        TID: '',
        placeholderText: '请输入平台单号',
        orderListByplatformId:[], //平台单号带出多个订单列表
        selectOrderModal: false,
        mask:true,
        closable: true,
        maskClosable: false,
        hideFoot: true,
      };
    },
    created() {
      // console.log(this.options)
    },
    watch: {
      value(val){
        this.TID = val
      }
    },
  
    methods: {
        getMessageByPlatformId(e) {
          if(e.keyCode == 13){
            if(this.TID==''){
                // this.$Message.warning('未找到系统订单号');
                return
            } else {
                let params = {
                    id: this.TID,
                    type: '1'
                }
                network.post('/p/cs/findOrderIdByParam', params).then((res) => {
                    if(res.data.code == 0){
                        if(res.data.data.length == 1){
                            // let virtual={id:res.data.data[0]}
                            this.ok(res.data.data[0])
                        }else if(res.data.data.length > 1){
                            this.orderListByplatformId = res.data.data
                            this.selectOrderModal = true;
                        }
                    }else {
                        this.TID = ''
                    }
                })
            }
          }
            
        },
        chooseOrderIdbyplatform(item){
            this.selectOrderModal = false;
            // let virtual={id:item}
            this.ok(item)
        },
        cancelSelectOrder() {
            this.selectOrderModal = false;
            this.TID = '';
        },
        ok(virtual) {
          // this.TID = virtual;

          // this.$emit('change', virtual)
          let params = {
            ASSIGN: {
              "ONLINEORDERID": virtual,
              "TID": this.options.valuedata,
              "ORDERSHOPID": "",
              "ACTUALAMOUNT": "",
              "ORDERSTATUS": "",
              "BUYERRATE": "0"
            }
          }
          network.post('/p/cs/order_todo/order_query',params).then(res => {
            // console.log(this.$parent)
            if(res.data&&res.data.length > 0){
              res.data.forEach(item => {
                if(item.COLUMN_NAME == 'TID'){
                  this.TID = item.LABLE_VALUES[0].VALUE
                }
              })
            }
            let obj = {
              "COLUMN_NAME":"ORDER_ID",
              "COLUMN_TYPE":0,
              "LABLE_VALUES":[
                {
                  "LABLE":virtual,
                  "VALUE":virtual
                }
              ]
            }
            res.data.push(obj);
            setFormItemValue(res.data,this.$parent.$parent.$parent)
          })
        },
    },
  
    mounted() {
      this.TID = this.options.valuedata
    }
  };
  </script>
  
  <style lang="scss" >
  .PlatformSearch .ark-input-group-prepend .ark-select-selection,.PlatformSearch .ark-input-group-append .ark-select-selection {
    border: 1px solid #d8d8d8 !important;
    margin-top: -1px;
  }
  </style>
  