<template>
    <view>
        <view class="add_page">
            <u-navbar class="nav-bar" title="商品入库" :autoBack="true" :placeholder="true" v-hideNav>
                <view class="u-nav-slot" slot="right">
                    <u-checkbox-group v-model="continuousWarehousing" placement="column">
                        <u-checkbox label="连续入库" name="1"></u-checkbox>
                    </u-checkbox-group>
                </view>
            </u-navbar>
            <view class="form_list">
                <u--form labelPosition="top" :model="formData" :rules="rules" ref="addForm" labelWidth="100%">
                    <u-form-item borderBottom class="u-form-item-col">
                        <u--textarea v-model="recognitionContent" placeholder='品牌：-
来源：-
实价：-
型号：-
编码：-
日期：-
备注：-
付款方式：-' confirmType="done" height="170" :maxlength="-1">
                        </u--textarea>
                        <view class="btn_group_recognition">
                            <u-button text="清除" @click="clearRecognitionContent()"></u-button>
                            <u-button text="粘贴识别" type="primary"
                                @click="handlePasteRecognition(recognitionContent)"></u-button>
                        </view>
                    </u-form-item>
                    <u-form-item label="商品图片" required prop="goodPicFileList" borderBottom>
                        <view class="imgs_scroll">
                            <ImgsRowScroll v-if="formData.goodPicFileList.length > 0" :isShowDeleteIcon="true"
                                @deleteImgInfo="getDeleteGoodPicInfo" imgMode="aspectFill" :totalWidth="400"
                                :images="formData.goodPicFileList" :previewEnabled="true" :imageWidth="150"
                                :imageHeight="150"></ImgsRowScroll>
                            <u-upload @afterRead="afterReadGoodPic" name="3" multiple :maxCount="9"
                                :previewFullImage="true"></u-upload>
                        </view>
                    </u-form-item>
                    <u-form-item label="商品描述（详细的描述让用户更好的了解您的产品）" required prop="desc" borderBottom>
                        <u--textarea v-model="formData.desc" clearable placeholder="95新 WHZ19219H CHANEL香奈儿链条单肩包
21开 牛皮 尺寸25 4 15
配件中溯卡" count autoHeight maxlength="250" :height="150" confirmType="done"></u--textarea>
                    </u-form-item>
                    <u-form-item label="来源" prop="origin" borderBottom>
                        <u--textarea v-model="formData.origin" clearable placeholder="请输入来源" count autoHeight maxlength="250" height="100" confirmType="done"></u--textarea>
                    </u-form-item>
                    <u-form-item label="商品分类" required prop="type" borderBottom>
                        <TabSelect :tabList="typeList" :isClear="typeIsClear" @tabChange="handleTabChangeType"
                            labelKey="dictLabel" valueKey="dictValue" :colNum="4" mode="single" :echoInfo="echoInfoType">
                        </TabSelect>
                    </u-form-item>
                    <u-form-item label="品牌" required prop="dictLabel" class="u-form-item-row" borderBottom
                        @click="showBrandList">
                        <Cell :val="formData.dictLabel"></Cell>
                        <BrandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></BrandList>
                    </u-form-item>
                    <u-form-item label="系列" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.series" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="型号" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.model" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="机芯类型" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.dialType" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="表壳材质" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.caseMaterial" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="表盘直径" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.dialDiameter" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="材质" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.material" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="尺寸" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.size" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="尺码" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.yardage" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="商品成色" required prop="productCondition" borderBottom>
                        <TabSelect :tabList="productConditionList" :isClear="productConditionIsClear"
                            @tabChange="handleTabChangeProductCondition" :colNum="2" mode="single" :echoInfo="echoInfoProductCondition">
                        </TabSelect>
                    </u-form-item>
                    <u-form-item label="细节图" borderBottom>
                        <!-- <view class="detail_pic_container"> -->
                        <!-- <view>
                                <text class="tip">视频：</text>
                                <ImgsRowScroll v-if="formData.detailVideoFileList.length > 0" :isShowDeleteIcon="true"
                                    @deleteVideoInfo="getDeleteDetailVideoInfo" imgMode="aspectFill" :totalWidth="400"
                                    :videos="formData.detailVideoFileList" :previewEnabled="true" :imageWidth="150"
                                    :imageHeight="150" accept="video"></ImgsRowScroll>
                                <u-upload @afterRead="afterReadDeatilVideo"  name="2" multiple :maxCount="10" accept="video"></u-upload>
                            </view> -->
                        <!-- <view> -->
                        <!-- <text class="tip">图片：</text> -->
                        <view class="imgs_scroll">
                            <ImgsRowScroll v-if="formData.detailPicFileList.length > 0" :isShowDeleteIcon="true"
                                @deleteImgInfo="getDeleteDetailPicInfo" imgMode="aspectFill" :totalWidth="400"
                                :images="formData.detailPicFileList" :previewEnabled="true" :imageWidth="150"
                                :imageHeight="150"></ImgsRowScroll>
                            <u-upload @afterRead="afterReadDetailPic" name="1" multiple :maxCount="10"></u-upload>
                        </view>
                        <!-- </view> -->
                        <!-- </view> -->
                    </u-form-item>
                    <u-form-item label="商品标题" borderBottom>
                        <u--textarea v-model="formData.title" clearable :placeholder="titlePlaceholder" count autoHeight
                            maxlength="50" height="100" confirmType="done"></u--textarea>
                    </u-form-item>
                    <u-form-item label="商品货号" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.productNo" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="商品属性" required prop="productAttribute" borderBottom>
                        <TabSelect :tabList="productAttributeList" :colNum="4" mode="single"
                            :isClear="productAttributeIsClear" @tabChange="handleTabChangeProductAttribute"
                            :echoInfo="echoInfoProductAttribute">
                        </TabSelect>
                    </u-form-item>
                    <u-form-item label="库存数量" required prop="stock" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.stock" placeholder="请输入" clearable border="none"
                            type="number"></u--input>
                    </u-form-item>
                    <u-form-item label="官方指导价" required prop="price" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.price" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="总成本价" class="u-form-item-row" borderBottom v-if="isWareHouser">
                        <u--input v-model="formData.costPrice" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="同行价格" class="u-form-item-row" borderBottom v-if="isWareHouser">
                        <u--input v-model="formData.peerPrice" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="实价" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.actualPrice" placeholder="请输入" clearable border="none" type="number" @blur="handleBlurActualPrice"></u--input>
                    </u-form-item>
                    <u-form-item label="代理价格" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.agentPrice" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="销售价格" class="u-form-item-row" borderBottom v-if="isWareHouser">
                        <u--input v-model="formData.salePrice" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="商品位置" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.productPosition" placeholder="请输入" clearable
                            border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="手表年份" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.watchYear" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="鉴定人员" class="u-form-item-row" borderBottom @click="identifyingPersonClick">
                        <Cell :val="formData.identifyingPerson" :isDelete="true"
                            @handleClear="clear('identifyingPerson')"></Cell>
                        <PersonPicker ref="identifyingPersonPickerRef" title="请选择鉴定人员"
                            @selectPerson="handleSelectIdentifyingPerson"></PersonPicker>
                    </u-form-item>
                    <u-form-item label="是否入库" borderBottom required prop="stockStatus">
                        <TabSelect :tabList="stockStatusList" :colNum="2" mode="single" :isClear="stockStatusIsClear" :echoInfo="echoInfoStockStatus"
                            @tabChange="handleTabChangeStockStatus"></TabSelect>
                    </u-form-item>
                    <u-form-item label="回收类型" borderBottom>
                        <TabSelect :tabList="recycleTypeList" :colNum="4" mode="single" :isClear="recycleTypeIsClear" :echoInfo="echoInfoRecycleType"
                            @tabChange="handleTabChangeRecycleType">
                        </TabSelect>
                    </u-form-item>
                    <u-form-item label="标签" borderBottom>
                        <TabSelect :tabList="labelList" :colNum="5" mode="single" :isClear="labelIsClear" :echoInfo="echoInfoLabel"
                            @tabChange="handleTabChangeLabel">
                        </TabSelect>
                    </u-form-item>
                    <u-form-item label="回收人员" class="u-form-item-row" borderBottom @click="recyclePersonClick">
                        <!-- <u--input v-model="formData.recyclePerson" disabledColor="#fff" disabled clearable
                            border="none"></u--input> -->
                        <Cell :val="formData.recyclePerson" :isDelete="true" @handleClear="clear('recyclePerson')">
                        </Cell>
                        <PersonPicker ref="recyclePersonPickerRef" title="请选择回收人员"
                            @selectPerson="handleSelectRecyclePerson"></PersonPicker>
                    </u-form-item>
                    <u-form-item label="回收留底图" borderBottom>
                        <view class="recycle_bottom_desc">
                            <u--textarea v-model="formData.recycleBottomDesc" clearable count autoHeight maxlength="250"
                                height="100" confirmType="done"></u--textarea>
                            <view class="imgs_scroll">
                                <ImgsRowScroll v-if="formData.recycleBottomFileList.length > 0" :isShowDeleteIcon="true"
                                    @deleteImgInfo="getDeleteRecycleBottomPicInfo" imgMode="aspectFill"
                                    :totalWidth="400" :images="formData.recycleBottomFileList" :previewEnabled="true"
                                    :imageWidth="150" :imageHeight="150"></ImgsRowScroll>
                                <u-upload @afterRead="afterReadRecycleBottom" name="1" multiple :maxCount="1"
                                    accept="image"></u-upload>
                            </view>
                        </view>
                    </u-form-item>
                    <u-form-item label="回收时间" required prop="recycleTime" class="u-form-item-row" borderBottom
                        @click="clickRecycleTimeRow">
                        <Cell :val="formData.recycleTime"></Cell>
                        <u-datetime-picker @confirm="confirmRecycleTime" @close="closeRecycleTimePicker"
                            @cancel="closeRecycleTimePicker" :show="recycleTimeShow" v-model="formData.recycleTime"
                            mode="date"></u-datetime-picker>
                    </u-form-item>
                    <u-form-item label="独立编码" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.indentifyCode" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="适用人群" class="u-form-item-row" borderBottom>
                        <u-radio-group v-model="formData.targetAudience" placement="row">
                            <u-radio activeColor="#3c9cff" name="general" label="通用"></u-radio>
                            <u-radio activeColor="#3c9cff" name="man" label="男"></u-radio>
                            <u-radio activeColor="#3c9cff" name="woman" label="女"></u-radio>
                        </u-radio-group>
                    </u-form-item>
                    <u-form-item label="商品保卡" class="u-form-item-row" borderBottom>
                        <u-radio-group v-model="formData.productCard" placement="row">
                            <u-radio activeColor="#3c9cff" name="has" label="有保卡"></u-radio>
                            <u-radio activeColor="#3c9cff" name="no" label="无保卡"></u-radio>
                        </u-radio-group>
                    </u-form-item>
                    <u-form-item label="保卡年份" class="u-form-item-row" borderBottom
                        v-if="formData.productCard === 'has'">
                        <u--input v-model="formData.cardYear" placeholder="不填写默认空白保卡" clearable
                            border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="保卡图片或独立编码照片留底(仅内部人员可见)" borderBottom>
                        <view class="imgs_scroll">
                            <ImgsRowScroll v-if="formData.productCardPicFileList.length > 0" :isShowDeleteIcon="true"
                                @deleteImgInfo="getDeleteProductCardPicInfo" imgMode="aspectFill" :totalWidth="400"
                                :images="formData.productCardPicFileList" :previewEnabled="true" :imageWidth="150"
                                :imageHeight="150"></ImgsRowScroll>
                            <u-upload @afterRead="afterReadProductCardPic" name="3" multiple :maxCount="9"
                                :previewFullImage="true"></u-upload>
                        </view>
                    </u-form-item>
                    <u-form-item label="商品标签" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.productTag" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="商品附件" class="u-form-item-row" borderBottom>
                        <u--input v-model="formData.productAttachment" placeholder="请输入" clearable
                            border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="备注(仅内部人员可见)" borderBottom>
                        <view class="recycle_bottom_desc">
                            <u--textarea v-model="formData.productDesc" clearable count autoHeight maxlength="250"
                                height="100" confirmType="done"></u--textarea>
                            <view class="imgs_scroll">
                                <ImgsRowScroll v-if="formData.productDescPicFileList.length > 0"
                                    :isShowDeleteIcon="true" @deleteImgInfo="getDeleteProductDescPicInfo"
                                    imgMode="aspectFill" :totalWidth="400" :images="formData.productDescPicFileList"
                                    :previewEnabled="true" :imageWidth="150" :imageHeight="150"></ImgsRowScroll>
                                <u-upload @afterRead="afterReadProductDescPic" name="1" multiple :maxCount="1"
                                    accept="image"></u-upload>
                            </view>
                        </view>
                    </u-form-item>
                    <u-form-item label="付款方式">
                        <TabSelect :tabList="paymentTabList" :echoInfo="echoInfoPayType" :colNum="4" mode="single"
                            :isClear="payTypeIsClear" @tabChange="handlePayTypeTabChange">
                        </TabSelect>
                    </u-form-item>
                </u--form>
            </view>
        </view>
        <view :class="['btn_group', {'col-2': formData.stockStatus == '1'}]">
            <u-button plain type="primary" @click="openInfoModal('onlyIn')">保存</u-button>
            <u-button type="primary" @click="openInfoModal('inAndUp')" v-if="formData.stockStatus == '1'">入库并上架</u-button>
        </view>
        <moreInfo ref="moreInfoRef" :moreOptions="moreOptions" @confirm="handleMoreInfoConfirm" :isCopy="true" :showCancelButton="true"></moreInfo>
    </view>
</template>
<script>
import TabSelect from '@/components/custom-tab-select/index.vue'
import Cell from '@/components/custom-cell/index.vue'
import BrandList from '@/components/brand-list/index.vue'
import ImgsRowScroll from '@/components/imgs-row-scroll/index.vue'
import PersonPicker from '@/components/person-picker/index.vue'
import { permissionCheck,getRoles } from '@/utils/util.js'
import moreInfo from './moreInfo.vue'
import { productConditionList,productAttributeList,stockStatusList,recycleTypeList,labelList,paymentTabList } from '../js/public.js'
export default {
    components: {
        TabSelect,
        Cell,
        BrandList,
        ImgsRowScroll,
        PersonPicker,
        moreInfo
    },
    data() {
        return {
            checkboxValue: [''],
            recognitionContent: '',
            formData: {
                goodPicFileList: [],//商品图片
                desc: '',
                origin: '',
                type: '1',
                dictLabel: '艾美',
                dictValue: '88',
                series: '',
                model: '',
                dialType: '',
                caseMaterial: '',
                dialDiameter: '',
                material: '',
                size: '',
                yardage: '',
                price: 0,
                productCondition: '1',
                detailPicFileList: [],//细节图片
                // detailVideoFileList:[],
                title:'',
                productNo: '',
                productAttribute: '1',
                stock: 1,
                costPrice: '',
                peerPrice: '',
                actualPrice: '',
                agentPrice: '',
                salePrice: '',
                productPosition: '',
                watchYear: '',
                identifyingPerson: '',
                identifyingPersonId: '',
                stockStatus: '0',
                recycleType: '',
                recyclePerson: '',
                recyclePersonId: '',
                recycleBottomDesc: '',
                recycleBottomFileList: [],//回收留底图
                recycleTime: this.$dayjs().format('YYYY-MM-DD'),
                indentifyCode: '',
                targetAudience: '',
                productCard: '',
                cardYear: '',
                productCardPicFileList: [],//商品保卡图片或独立编码照片留底
                productTag: '',
                productAttachment: '',
                productDesc: '',
                productDescPicFileList: [],//商品备注图片
                payType: '',
            },
            continuousWarehousing: [],//是否连续入库 1：是 0：否
            rules: {
                goodPicFileList: [
                    { required: true, message: '请上传商品图片' },
                ],
                desc: [
                    { required: true, message: '请输入商品描述', trigger: ['blur', 'change'] },
                ],
                type: [
                    { required: true, message: '请选择商品分类', trigger: ['blur', 'change'] },
                ],
                dictLabel: [
                    { required: true, message: '请选择品牌', trigger: ['blur', 'change'] },
                ],
                productCondition: [
                    { required: true, message: '请选择商品成色', trigger: ['blur', 'change'] },
                ],
                productAttribute: [
                    { required: true, message: '请选择商品属性', trigger: ['blur', 'change'] },
                ],
                stock: [
                    { required: true, message: '请输入库存数量' }
                ],
                price: [
                    { required: true, message: '请输入官方指导价' }
                ],
                stockStatus: [
                    { required: true, message: '请选择是否入库', trigger: [ 'change'] },
                ],
                recycleTime: [
                    { required: true, message: '请选择回收时间', trigger: ['blur', 'change'] },
                ],

            },
            recycleTimeShow: false,
            titlePlaceholder: '如不填，自动截取商品描述前50字',
            typeList: [],
            typeIsClear: false,//商品分类是否清空
            productConditionIsClear: false,//商品成色是否清空
            productAttributeIsClear: false,//商品属性是否清空
            recycleTypeIsClear: false,//回收类型是否清空
            stockStatusIsClear: false,//是否入库是否清空
            labelIsClear: false,//商品标签是否清空
            payTypeIsClear: false,//付款方式是否清空
            echoInfoPayType: '',//付款方式识别回显
            echoInfoRecycleType:'',//入库回显的时候 回收类型回显
            echoInfoLabel:'',//入库回显的时候 商品标签回显
            echoInfoType:'',//入库回显的时候 类型回显
            echoInfoProductAttribute:'',//入库回显的时候 商品属性回显
            echoInfoProductCondition:'',//入库回显的时候 商品成色回显
            echoInfoStockStatus:'',//入库回显的时候 是否入库回显
            isWareHouser: permissionCheck('WAREHOUSER',false),
            formType: '',//表单类型 add：新增 edit：编辑
            xhlSystemSetList: [],//系统设置-列表
            productConditionList:productConditionList,
            productAttributeList: productAttributeList,
            stockStatusList: stockStatusList,
            recycleTypeList: recycleTypeList,
            labelList: labelList,
            paymentTabList: paymentTabList,
            moreOptions: {},
            
        }
    },
    onLoad(options) {
        this.getTypeList();
        this.getXhlSystemSetList()
        this.$nextTick(async()=>{
            this.formType = options.formType
            if(options.formType == 'add'){
                this.clearForm()
            }else if(options.formType == 'edit'){
                const res = await uni.$u.api.wareHouseDetail({
                    id: options.id,
                    userId: this.$store.state.user.userInfo.userId,
                })
                this.formData = res.data
                this.formData.recycleTime = this.$dayjs(res.data.recycleTime).format('YYYY-MM-DD') || ''
                this.echoInfoType = res.data.type || '1'//商品分类回显
                this.formData.type = res.data.type || '1'//商品分类校验
                this.echoInfoProductAttribute = res.data.productAttribute || '1'//商品属性回显
                this.formData.productAttribute = res.data.productAttribute || '1'//商品属性校验
                this.echoInfoProductCondition = res.data.productCondition || '1'//商品成色回显
                this.formData.productCondition = res.data.productCondition || '1'//商品成色校验
                this.echoInfoStockStatus = res.data.stockStatus || '0'//是否入库回显
                this.formData.stockStatus = res.data.stockStatus || '0'//是否入库校验
                this.formData.stock = res.data.stock ? res.data.stock : 1//入库数量校验
                this.formData.price = res.data.price || 0//官方指导价校验
                this.echoInfoPayType = res.data.payType//付款方式回显
                this.echoInfoRecycleType = res.data.recycleType//回收类型回显
                this.echoInfoLabel = res.data.label//商品标签回显
                this.recognitionContent = `品牌：${res.data.dictLabel || '-'}
来源：${res.data.origin || '-'}
实价：${res.data.actualPrice || '-'}
型号：${res.data.model || '-'}
编码：${res.data.indentifyCode || '-'}
日期：${res.data.cardYear || '-'}
备注：${res.data.productDesc || '-'}
付款方式：${this.paymentTabList.find(item => item.value == res.data.payType)?.name || '-'}
`
            }
        })
    },
    methods: {
        getXhlSystemSetList(){
            uni.$u.api.xhlSystemSetList({
                pageNum: 1,
                pageSize: 99,
            }).then(res => {
                this.xhlSystemSetList = res.rows || []
            })
        },
        handleBlurActualPrice() {
            if (this.formData.actualPrice) {
                const actualPrice = Number(this.formData.actualPrice)
                let obj = {}
                // 只要账号权限里面有销售权限，就按照销售的计算规则，没有就固定计算
                if(getRoles().includes('SALESMAN')){
                    obj = this.xhlSystemSetList.find(item => item.agentType == 'SALESMAN') || {}
                }else{
                    obj = {
                        goodsRate: 0.003,
                        goodsAmount: 500,
                    }
                }
                this.formData.agentPrice = (actualPrice + actualPrice*obj.goodsRate + obj.goodsAmount).toFixed(2)
            }
        },
        getTypeList() {
            this.$getDicts("crm_form_category").then(res => {
                this.typeList = res
            })
        },
        openInfoModal(submitType) {
            this.$refs.addForm.validate().then(() => {
                this.submitType = submitType
                this.moreOptions = {
                    dictLabel: this.formData.dictLabel || '',
                    origin: this.formData.origin || '',
                    actualPrice: this.formData.actualPrice || '',
                    model: this.formData.model || '',
                    indentifyCode: this.formData.indentifyCode || '',
                    cardYear: this.formData.cardYear || '',
                    productDesc: this.formData.productDesc || '',
                }
                this.$refs.moreInfoRef.showMoreInfo();
            })
        },
        handleMoreInfoConfirm() {
            if(!permissionCheck('WAREHOUSER')) return false
            this.submitForm(this.submitType)
        },
        // 提交表单
        submitForm(submitType) {
            this.$refs.addForm.validate().then((valid) => {
                if (valid) {
                    if (this.formData.title == '') {
                        this.formData.title = this.formData.desc.substring(0, 50);
                    }
                    this.formData.recycleTime = this.$dayjs(this.formData.recycleTime).format('YYYY-MM-DD')
                    const data = {
                        ...this.formData,
                        submitType: submitType, //提交类型 onlyIn：仅入库/暂存入库 inAndUp：入库并上架
                        continuousWarehousing: this.continuousWarehousing[0] || '0',//是否连续入库 1：是 0：否
                    }
                    this.$refs.moreInfoRef.closeModal();
                    if(this.formType == 'add'){
                        uni.$u.api.wareHouseAdd(data).then(res => {
                            uni.$u.toast('操作成功');
                            if (data.continuousWarehousing == '0') {
                                setTimeout(() => {
                                    uni.navigateBack({
                                        delta: 1
                                    });
                                }, 1000);
                            } else {
                                this.clearForm();
                            }
                        }).catch(err => {
                            uni.$u.toast(err);
                        })
                    }else if(this.formType == 'edit'){
                        uni.$u.api.wareHouseUpdate(data).then(res => {
                            uni.$u.toast('操作成功');
                            if (data.continuousWarehousing == '0') {
                                setTimeout(() => {
                                    uni.navigateBack({
                                        delta: 1
                                    });
                                }, 1000);
                            } else {
                                this.clearForm();
                            }
                        }).catch(err => {
                            uni.$u.toast(err);
                        })
                    }
                } else {
                    console.log('表单校验不通过');
                }
            });
        },
        clearForm() {
            this.formData = {
                goodPicFileList: [],//商品图片
                desc: '',
                origin: '',
                type: '1',
                dictLabel: '艾美',
                dictValue: '88',
                series: '',
                model: '',
                dialType: '',
                caseMaterial: '',
                dialDiameter: '',
                material: '',
                size: '',
                yardage: '',
                price: 0,
                productCondition: '1',
                detailPicFileList: [],//细节图片
                // detailVideoFileList:[],
                productNo: '',
                productAttribute: '1',
                stock: 1,
                costPrice: '',
                samePrice: '',
                agentPrice: '',
                salePrice: '',
                productPosition: '',
                watchYear: '',
                identifyingPerson: '',
                identifyingPersonId: '',
                stockStatus: '0',
                recycleType: '',
                label: '',
                recyclePerson: '',
                recyclePersonId: '',
                recycleBottomDesc: '',
                recycleBottomFileList: [],//回收留底图
                recycleTime: this.$dayjs().format('YYYY-MM-DD'),
                indentifyCode: '',
                targetAudience: '',
                productCard: '',
                cardYear: '',
                productCardPicFileList: [],//商品保卡图片或独立编码照片留底
                productTag: '',
                productAttachment: '',
                productDesc: '',
                productDescPicFileList: [],//商品备注图片
                payType: '',
            }
            this.recycleTypeIsClear = true;
            this.payTypeIsClear = true;
            this.labelIsClear = true;
            this.echoInfoType = '1';//类型默认第一项
            this.echoInfoProductCondition = '1';//商品成色默认第一项
            this.echoInfoProductAttribute = '1';//商品属性默认第一项
            this.echoInfoStockStatus = '0';//是否入库默认第一项
            this.continuousWarehousing = [];
            this.$nextTick(()=>{
                this.$refs.addForm.resetFields();
            })
        },
        // 选择品牌
        handleSelectedBrand(info) {
            this.formData.dictLabel = info.dictLabel;
            this.formData.dictValue = info.dictValue;
            this.$refs.addForm.validateField('dictLabel');
        },
        // 显示品牌列表
        showBrandList() {
            this.$refs.brandListRef.showBrandList();
        },
        // 清空输入框
        clear(key) {
            // 品牌
            if (key == 'dictLabel') {
                this.formData.dictLabel = '';
                this.formData.dictValue = '';
                return;
            }
            // 鉴定人
            if (key == 'identifyingPerson') {
                this.formData.identifyingPerson = '';
                this.formData.identifyingPersonId = '';
                return;
            }
            // 回收人
            if (key == 'recyclePerson') {
                this.formData.recyclePerson = '';
                this.formData.recyclePersonId = '';
                return;
            }
            this.formData[key] = '';
        },
        // 商品分类
        handleTabChangeType(e) {
            this.formData.type = e;
            this.$refs.addForm.validateField('type')
        },
        // 商品成色
        handleTabChangeProductCondition(e) {
            this.formData.productCondition = e;
            this.$refs.addForm.validateField('productCondition')
        },
        // 商品属性
        handleTabChangeProductAttribute(e) {
            this.formData.productAttribute = e;
            this.$refs.addForm.validateField('productAttribute')
        },
        // 是否入库
        handleTabChangeStockStatus(e) {
            this.formData.stockStatus = e;
        },
        // 回收类型
        handleTabChangeRecycleType(e) {
            this.formData.recycleType = e;
        },
        // 商品标签
        handleTabChangeLabel(e) {
            this.formData.label = e;
        },
        // 付款方式
        handlePayTypeTabChange(e) {
            this.formData.payType = e;
        },
        // 打开回收时间选择器
        clickRecycleTimeRow() {
            this.recycleTimeShow = true;
        },
        // 确认回收时间
        confirmRecycleTime(val) {
            this.$nextTick(() => {
                this.formData.recycleTime = this.$dayjs(val.value).format('YYYY-MM-DD');
                this.recycleTimeShow = false;
            })
        },
        // 关闭回收时间选择器
        closeRecycleTimePicker(val) {
            this.recycleTimeShow = false;
        },
        // 打开鉴定人选择器
        identifyingPersonClick() {
            this.$refs.identifyingPersonPickerRef.open();
        },
        // 选择鉴定人
        handleSelectIdentifyingPerson(info) {
            this.formData.identifyingPerson = info.label;
            this.formData.identifyingPersonId = info.id;
        },
        // 打开回收人选择器
        recyclePersonClick() {
            this.$refs.recyclePersonPickerRef.open();
        },
        // 选择回收人
        handleSelectRecyclePerson(info) {
            this.formData.recyclePerson = info.label;
            this.formData.recyclePersonId = info.id;
        },
        // 新增商品图片
        async afterReadGoodPic(event) {
            event.file.forEach(item => {
                uni.$u.api.uploadFile(item.url).then((res) => {
                    this.formData.goodPicFileList.push(res.data.url);
                    uni.$u.toast("文件上传成功");
                }).catch(() => {
                    uni.$u.toast("上传文件失败");
                })
            })
        },
        // 获取删除商品图片信息
        getDeleteGoodPicInfo(info) {
            this.formData.goodPicFileList = info.newImages
        },
        // 获取删除细节图片信息
        getDeleteDetailPicInfo(info) {
            this.formData.detailPicFileList = info.newImages
        },
        // 新增细节图片
        async afterReadDetailPic(event) {
            event.file.forEach(item => {
                uni.$u.api.uploadFile(item.url).then((res) => {
                    this.formData.detailPicFileList.push(res.data.url);
                    uni.$u.toast("文件上传成功");
                }).catch(() => {
                    uni.$u.toast("上传文件失败");
                })
            })
        },
        // 获取删除回收留底图信息
        getDeleteRecycleBottomPicInfo(info) {
            this.formData.recycleBottomFileList = info.newImages
        },
        // 新增回收留底图
        async afterReadRecycleBottom(event) {
            event.file.forEach(item => {
                uni.$u.api.uploadFile(item.url).then((res) => {
                    this.formData.recycleBottomFileList.push(res.data.url);
                    uni.$u.toast("文件上传成功");
                }).catch(() => {
                    uni.$u.toast("上传文件失败");
                })
            })
        },
        // 删除商品保卡图片或独立编码照片留底
        getDeleteProductCardPicInfo(info) {
            this.formData.productCardPicFileList = info.newImages
        },
        // 新增商品保卡图片或独立编码照片留底
        async afterReadProductCardPic(event) {
            event.file.forEach(item => {
                uni.$u.api.uploadFile(item.url).then((res) => {
                    this.formData.productCardPicFileList.push(res.data.url);
                    uni.$u.toast("文件上传成功");
                }).catch(() => {
                    uni.$u.toast("上传文件失败");
                })
            })
        },
        // 获取删除商品备注图片信息
        getDeleteProductDescPicInfo(info) {
            this.formData.productDescPicFileList = info.newImages
        },
        // 新增商品备注图片
        async afterReadProductDescPic(event) {
            event.file.forEach(item => {
                uni.$u.api.uploadFile(item.url).then((res) => {
                    this.formData.productDescPicFileList.push(res.data.url);
                    uni.$u.toast("文件上传成功");
                }).catch(() => {
                    uni.$u.toast("上传文件失败");
                })
            })
        },
        async handlePasteRecognition(text) {
            // 品牌：浪琴
            // 来源：【麒麟】私信-杰3-3
            // 实价：6500
            // 型号：L2.257.5.89.7
            // 编码：52356065
            // 日期：2021-11-09
            // 备注：全套
            // 付款方式：微信
            if (!text) {
                return;
            }
            try {
                if (!text) return {};

                const result = {};
                // 支持中文冒号和英文冒号
                const lines = text.split(/[\n\r]+/);

                lines.forEach(line => {
                    const lineStr = line.trim();
                    if (!lineStr) return;

                    // 尝试中文冒号
                    let separatorIndex = lineStr.indexOf('：');
                    // 如果没有中文冒号，尝试英文冒号
                    if (separatorIndex === -1) {
                        separatorIndex = lineStr.indexOf(':');
                    }

                    if (separatorIndex > 0) {
                        const key = lineStr.substring(0, separatorIndex).trim();
                        const value = lineStr.substring(separatorIndex + 1).trim();
                        result[key] = value;
                    }
                });
                if (result['品牌']) {
                    this.formData.dictLabel = result['品牌'];
                }
                if (result['来源']) {
                    this.formData.origin = result['来源'];
                }
                if (result['实价']) {
                    this.formData.actualPrice = result['实价'];
                }
                if (result['型号']) {
                    this.formData.model = result['型号'];
                }
                if (result['编码']) {
                    this.formData.indentifyCode = result['编码'];
                }
                if (result['日期']) {
                    this.formData.cardYear = result['日期'];
                }
                if (result['备注']) {
                    this.formData.productDesc = result['备注'];
                }
                if (result['付款方式']) {
                    this.getPaymentType(result['付款方式'])
                    this.formData.payType = result['付款方式'];

                }
                // return result;
            } catch (e) {
                uni.$u.toast("文本识别异常");
            }
        },
        // 清空识别内容
        clearRecognitionContent() {
            this.recognitionContent = '';
        },
        // 识别内容 回显付款方式
        getPaymentType(val) {
            let arr = []
            this.paymentTabList.filter(item => {
                if (item.name == val) arr.push(item.value)
            })
            if (arr.length > 0) {
                this.echoInfoPayType = arr[0]
            }
        }
    }
}
</script>
<style lang="scss" scoped>
@import '../styles/edit.scss';
</style>