<template>
  <a-modal
    centered
    class="replenishmentManagement-outWarehousing-modal"
    :footer="null"
    :maskClosable="false"
    :title="modalTit"
    v-model="isShow"
    @cancle="isShow = false"
    :width="800">
    <a-spin :spinning="spinning" tip="Loading...">
      <a-form-model
        id="replenishmentManagement-outWarehousing-form"
        ref="ruleForm"
        layout="inline"
        :model="form"
        :rules="rules"
        style="margin-bottom: 10px;" >
        <a-row :gutter="15">
          <a-col :md="12" :sm="24">
            <a-form-model-item label="补货单号">BH202101010001</a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item label="单据来源">系统创建</a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item label="调往对象" prop="type">
              <a-radio-group v-model="form.type">
                <a-radio v-for="(item,index) in typeList" :key="index" :value="item.val">{{ item.name }}</a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item label="出库备注">
              <a-input id="replenishmentManagement-outWarehousing-remark" v-model.trim="form.remark" allowClear placeholder="请输入出库备注"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <!-- 列表 -->
      <s-table
        class="sTable"
        ref="table"
        size="small"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :scroll="{ y: 400 }"
        :showPagination="false"
        :defaultLoadData="false"
        bordered>
      </s-table>
      <div class="btn-cont">
        <a-button type="primary" id="replenishmentManagement-outWarehousing-modal-save" @click="handleSave">确认出库</a-button>
        <a-button id="replenishmentManagement-outWarehousing-modal-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { STable, VSelect } from '@/components'
import { storeCallOutList } from '@/api/storeCallOut'
export default {
  name: 'OutWarehousingModal',
  components: { STable, VSelect },
  mixins: [commonMixin],
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    nowData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      spinning: false,
      isShow: this.openModal, //  是否打开弹框
      columns: [
        { title: '序号', dataIndex: 'no', width: '8%', align: 'center' },
        { title: '产品编码', dataIndex: 'allocationLinkagePutNo', width: '22%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'outTenantName', width: '32%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '补货应发数量', dataIndex: 'productTotalCategory', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '实发数量', dataIndex: 'outQty', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '单位', dataIndex: 'productUnit', width: '8%', align: 'center', customRender: function (text) { return text || '--' } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        this.spinning = true
        return storeCallOutList(Object.assign(parameter, this.queryParam)).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            const no = (data.pageNo - 1) * data.pageSize
            for (var i = 0; i < data.list.length; i++) {
              data.list[i].no = no + i + 1
            }
            this.disabled = false
          }
          this.spinning = false
          return data
        })
      },
      form: {
        type: undefined,
        remark: ''
      },
      rules: {
        'type': [{ required: true, message: '请选择配送方式', trigger: ['blur', 'change'] }]
      },
      typeList: [
        { name: '送货到店', val: 1 },
        { name: '快递到店', val: 2 }
      ]
    }
  },
  computed: {
    modalTit () {
      const hjName = this.nowData && this.nowData.settleClientName ? this.nowData.settleClientName : ''
      return '补货单出库——' + hjName
    }
  },
  methods: {
    //  确认出库
    handleSave () {
      const _this = this
      this.$confirm({
        title: '提示',
        content: '确认信息无误并进行出库吗？',
        centered: true,
        onOk () {
          _this.$emit('ok', 'outWarehousing')
          // _this.spinning = true
          // storeCallOutOut({ storeCallOutSn: row.storeCallOutSn }).then(res => {
          //   if (res.status == 200) {
          //     _this.$message.success(res.message)
          //     _this.$refs.table.refresh()
          //     _this.spinning = false
          //   } else {
          //     _this.spinning = false
          //   }
          // })
        }
      })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.$refs.table.clearTable()
      } else {
        const _this = this
        this.$nextTick(() => { // 页面渲染完成后的回调
          _this.$refs.table.refresh(true)
        })
      }
    }
  }
}
</script>

<style lang="less">
.replenishmentManagement-outWarehousing-modal {
	.btn-cont {
		text-align: center;
		margin: 35px 0 10px;
	}
}
</style>
