<template>
  <view>
    <!-- 转移公海 -->
    <u-modal
      :show="showCollectionModel"
      :showCancelButton="true"
      @confirm="confirmCollection()"
      @cancel="closeMoveInModel()"
      :asyncClose="true"
      title="领取客户">
      <view class="slot-content" style="width: 100%">
        <view class="flex">
          <text>申请说明：</text>
          <u-textarea
            v-model="openSeaObj.applyRemark"
            placeholder="请输入申请说明"
            height="180"
            :count="true"
            maxlength="500"></u-textarea>
        </view>
      </view>
    </u-modal>
  </view>
</template>

<script>
  import { mapGetters } from 'vuex'
  import customerApi from '../../../api/customer'
  import to from 'await-to-js'
  export default {
    data() {
      return {
        showCollectionModel: false,
        openSeaObj: {
          applyRemark: '',
          receive: '1',
          ids: [],
        },
      }
    },
    computed: {
      ...mapGetters(['userId', 'username']),
    },
    methods: {
      open(id) {
        this.openSeaObj.ids = [id]
        this.showCollectionModel = true
      },
      // 领用
      async confirmCollection() {
        this.openSeaObj.salesId = this.userId
        this.openSeaObj.salesName = this.username
        let params = this.openSeaObj
        const [err, res] = await to(customerApi.collection(params))
        if (err) return this.closeMoveInModel()
        console.log(res.code)
        if (res.code == 200) {
          this.$refs.uToast.show({
            type: 'loading',
            message: '客户领用成功',
            complete: () => {
              this.showCollectionModel = false
              this.$emit('fetchList')
            },
          })
        } else {
          this.closeMoveInModel()
        }
      },
      // 关闭移入公海模块
      closeMoveInModel() {
        this.openSeaObj.ids = []
        this.openSeaObj.applyRemark = ''
        this.showCollectionModel = false
      },
    },
  }
</script>

<style></style>
