<template>
  <view>
    <!-- 转移公海 -->
    <u-modal
      :show="showMoveInModel"
      :showCancelButton="true"
      @confirm="confirmMoveInOpenSea()"
      @cancel="closeMoveInModel()"
      :asyncClose="true"
      title="移入公海">
      <view class="slot-content">
        <view class="flex">
          <text>备注：</text>
          <u-textarea
            v-model="openSeaObj.remark"
            placeholder="请输入内容"
            height="180"
            :count="true"
            maxlength="300"></u-textarea>
        </view>
        <u-text
          :customStyle="{ marginTop: '20rpx' }"
          text="* 转移到公海后此客户数据将属于公共资源，原归属人员不能再维护跟进和更新此客户数据。"></u-text>
      </view>
    </u-modal>
  </view>
</template>

<script>
  import customerApi from '../../../api/customer'
  import to from 'await-to-js'
  export default {
    data() {
      return {
        flag: true,
        showMoveInModel: false,
        openSeaObj: {
          remark: '',
          ids: [],
        },
      }
    },
    methods: {
      open(id) {
        this.openSeaObj.ids = [id]
        this.showMoveInModel = true
      },
      // 移入公海
      async confirmMoveInOpenSea() {
        if (!this.flag) return
        let params = this.openSeaObj
        this.flag = false
        const [err, res] = await to(customerApi.moveInOpenSea(params))
        this.flag = true
        if (err) return this.closeMoveInModel()
        if (res.code == 200) {
          this.$refs.uToast.show({
            type: 'loading',
            message: '移入公海成功',
            complete: () => {
              this.showMoveInModel = false
              this.$emit('fetchList')
            },
          })
        } else {
          this.closeMoveInModel()
        }
      },
      // 关闭移入公海模块
      closeMoveInModel() {
        this.openSeaObj.ids = []
        this.openSeaObj.remark = ''
        this.showMoveInModel = false
      },
    },
  }
</script>

<style></style>
