<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='品牌：浪琴
来源：【麒麟】私信-杰3-3
实价：6500
型号：L2.257.5.89.7
编码：52356065
日期：2021-11-09
备注：全套
付款方式：微信/支付宝/银行卡/现金/数字货币/挂账' 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="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="1">
                        </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="官方指导价" 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="商品成色" required prop="productCondition" borderBottom>
                        <TabSelect :tabList="productConditionList" :isClear="productConditionIsClear"
                            @tabChange="handleTabChangeProductCondition" :colNum="2" mode="single" echoInfo="1"></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="1">
                        </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="总成本价" class="u-form-item-row" borderBottom>
                        <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>
                        <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.agentPrice" placeholder="请输入" clearable border="none"></u--input>
                    </u-form-item>
                    <u-form-item label="销售价格" class="u-form-item-row" borderBottom>
                        <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>
                        <TabSelect :tabList="recycleTypeList" :colNum="4" mode="single" 
                            :isClear="recycleTypeIsClear" @tabChange="handleTabChangeRecycleType">
                        </TabSelect>
                    </u-form-item>
                    <u-form-item label="标签" borderBottom>
                        <TabSelect :tabList="labelList" :colNum="4" mode="single" 
                            :isClear="labelIsClear" @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="payTypeEcho" :colNum="4" mode="single" 
                            :isClear="payTypeIsClear" @tabChange="handlePayTypeTabChange">
                        </TabSelect>
                    </u-form-item>
                </u--form>
            </view>

        </view>
        <view class="btn_group">
            <u-button plain type="primary" @click="submitForm('onlyIn')">仅入库</u-button>
            <u-button type="primary" @click="submitForm('inAndUp')">入库并上架</u-button>
        </view>
    </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'

export default {
    components: {
        TabSelect,
        Cell,
        BrandList,
        ImgsRowScroll,
        PersonPicker
    },
    data() {
        return {
            checkboxValue: [''],
            recognitionContent: '',
            formData: {
                goodPicFileList: [],//商品图片
                desc: '',
                type: '1',
                dictLabel: '艾美',
                dictValue: '88',
                series: '',
                model: '',
                dialType: '',
                caseMaterial: '',
                dialDiameter: '',
                material: '',
                size: '',
                yardage: '',
                price: '',
                productCondition: '1',
                detailPicFileList: [],//细节图片
                // detailVideoFileList:[],
                productNo: '',
                productAttribute: '1',
                stock: 1,
                costPrice: '',
                samePrice: '',
                agentPrice: '',
                salePrice: '',
                productPosition: '',
                watchYear: '',
                identifyingPerson: '',
                identifyingPersonId: '',
                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' },
                ],
                type: [
                    { required: true, message: '请选择商品分类', trigger: 'blur' },
                ],
                dictLabel: [
                    { required: true, message: '请选择品牌', trigger: 'blur' },
                ],
                productCondition: [
                    { required: true, message: '请选择商品成色', trigger: 'blur' },
                ],
                productAttribute: [
                    { required: true, message: '请选择商品属性', trigger: 'blur' },
                ],
                stock: [
                    { required: true, message: '请输入库存数量' },
                ],
                recycleTime: [
                    { required: true, message: '请选择回收时间', trigger: 'blur' },
                ],

            },
            recycleTimeShow: false,
            titlePlaceholder: '如不填，自动截取商品描述前50字',
            typeList: [],
            productConditionList: [
                {
                    name: '闲置未使用',
                    value: '1',
                },
                {
                    name: '二手',
                    value: '2',
                },
            ],
            productAttributeList: [
                {
                    name: '自有商品',
                    value: '1',
                },
                {
                    name: '寄卖商品',
                    value: '2',
                },
                {
                    name: '质押商品',
                    value: '3',
                },
                {
                    name: '其它',
                    value: '4',
                },
            ],
            recycleTypeList: [
                {
                    name: '线上',
                    value: '1',
                },
                {
                    name: '同行',
                    value: '2',
                },
                {
                    name: '门店',
                    value: '3',
                },
                {
                    name: '其它',
                    value: '4',
                },
            ],
            labelList:[
                {
                    name:'完美',
                    value:'1',
                },
                {
                    name:'普通',
                    value:'2',
                },
                {
                    name:'瑕疵',
                    value:'3',
                },
                {
                    name:'假货',
                    value:'4',
                },
                {
                    name:'亏损',
                    value:'5',
                },
            ],
            paymentTabList: [
                {
                    name: '微信',
                    value: 1,
                },
                {
                    name: '支付宝',
                    value: 2,
                },
                {
                    name: '银行卡',
                    value: 3,
                },
                {
                    name: '现金',
                    value: 4,
                },
                {
                    name: '数字货币',
                    value: 5,
                },
                {
                    name: '挂账',
                    value: 6,
                },
            ],
            typeIsClear: false,//商品分类是否清空
            productConditionIsClear: false,//商品成色是否清空
            productAttributeIsClear: false,//商品属性是否清空
            recycleTypeIsClear: false,//回收类型是否清空
            labelIsClear: false,//商品标签是否清空
            payTypeIsClear: false,//付款方式是否清空
            payTypeEcho: ''//付款方式识别回显

        }
    },
    onLoad() {
        this.getTypeList();
    },
    methods: {
        getTypeList(){
            this.$getDicts("crm_form_category").then(res => {
                this.typeList = res
            })
        },
        // 提交表单
        submitForm(submitType) {
            console.log(this.formData);
            
            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：否
                    }
                    console.log(data);
                    
                    uni.$u.api.wareHouseAdd(data).then(res => {
                        console.log(res);
                        if (res.code === 200) {
                            uni.$u.toast('新增成功');
                            if (data.continuousWarehousing == '0') {
                                setTimeout(() => {
                                    uni.navigateBack({
                                        delta: 1
                                    });
                                }, 1000);
                            } else {
                                this.clearForm();
                            }
                        } else {
                            uni.$u.toast(res.msg);
                        }
                    })
                } else {
                    console.log('表单校验不通过');
                }
            });
        },
        clearForm() {
            this.formData = {
                goodPicFileList: [],//商品图片
                desc: '',
                type: '1',
                dictLabel: '艾美',
                dictValue: '88',
                series: '',
                model: '',
                dialType: '',
                caseMaterial: '',
                dialDiameter: '',
                material: '',
                size: '',
                yardage: '',
                price: '',
                productCondition: '1',
                detailPicFileList: [],//细节图片
                // detailVideoFileList:[],
                productNo: '',
                productAttribute: '1',
                stock: 1,
                costPrice: '',
                samePrice: '',
                agentPrice: '',
                salePrice: '',
                productPosition: '',
                watchYear: '',
                identifyingPerson: '',
                identifyingPersonId: '',
                recycleType: '',
                label: '',
                recyclePerson: '',
                recyclePersonId: '',
                recycleBottomDesc: '',
                recycleBottomFileList: [],//回收留底图
                recycleTime: this.$dayjs().format('YYYY-MM-DD'),
                indentifyCode: '',
                targetAudience: '',
                productCard: '',
                cardYear: '',
                productCardPicFileList: [],//商品保卡图片或独立编码照片留底
                productTag: '',
                productAttachment: '',
                productDesc: '',
                productDescPicFileList: [],//商品备注图片
                payType: '',
            }
            this.typeIsClear = true;
            this.productConditionIsClear = true;
            this.productAttributeIsClear = true;
            this.recycleTypeIsClear = true;
            this.payTypeIsClear = true;
            this.labelIsClear = true;
            this.continuousWarehousing = [];
            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')
        },
        // 回收类型
        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.desc = result['来源'];
                }
                if (result['实价']) {
                    this.formData.costPrice = result['实价'];
                }
                if (result['型号']) {
                    this.formData.model = result['型号'];
                }
                if (result['编码']) {
                    this.formData.indentifyCode = result['编码'];
                }
                if (result['日期']) {
                    this.formData.recycleTime = 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.payTypeEcho = arr[0]
            }
        }
    }
}
</script>
<style lang="scss" scoped>
@import '../styles/add.scss';
</style>