<template>
	<!-- 添加外卖商品 -->
	<view class="productpages">
		
		
		<view class="flexv ali-c" style="padding: 30upx 0 0 0;" :hidden="linkage_product_id != 0 " v-if="is_bld == 1 && is_datashow">
			<image class="mb-20 img"  @tap="saoma"  src="/static/icon/saoma.png"></image>
			<view>扫码入库</view>
		</view>	
		<!-- <view class="noecellbox">
				<view class="title" >关联产品 </view>
				<view class="inputbox flex">
					<input class="input flex1"  type="text" v-model="" value="" placeholder-class="plclass" placeholder="请填写产品名称"  />
				</view>
		</view> -->
		<view class="noecellbox" >
			<view class="title" >关联产品 </view>
			<view class="inputbox flex">
				<picker mode="multiSelector" :value="classDataValue"  :range="classData" @change="bindData"  @columnchange="columnbindData">
					<input disabled="true"  class="input flex1"  type="text" v-model="classValue" placeholder-class="plclass" placeholder="请选择关联产品"  />
				</picker>
			</view>
		</view>

		<view class="noecellbox" :hidden="linkage_product_id == 0 " >
			<view class="title" >产品规格(kg或个) </view>
			<view class="inputbox flex">
				<input class="input flex1"  type="text" value="" v-model="form.specifications" placeholder-class="plclass" placeholder="请填写产品规格"  />
			</view>
		</view>
		
		
		
		<view class="noecellbox">
			<view class="title" >产品名称 <text style="color: red;">(必填)</text></view>
			<view class="inputbox flex">
				<input class="input flex1"  type="text" v-model="form.product_name" value="" placeholder-class="plclass" placeholder="请填写产品名称"  />
			</view>
		</view>
		
		<view class="noecellbox">
			<view class="title" >产品价格<text style="color: red;">(必填)</text></view>
			<view class="inputbox flex">
				<input class="input flex1"  type="number" v-model="form.price" value="" placeholder-class="plclass" placeholder="请填写产品价格"  />
				
			</view>
		</view>
		
		
		<!-- 
			stock 商品库存
			purchase 进货价钱
			code 条形编码
			commission 返佣比例
			original_name 原始商品名 
		-->
		<!-- 2020-10-12 -->
		<view class="" :hidden="linkage_product_id != 0 " v-if="is_bld == 1 && is_datashow">
			<!-- <view class="noecellbox">
				<view class="title">售卖类型</view>
				<view class="inputbox flex">
					<radio-group @change="radioChange">
						<view class="chindlost ali-c flex flex-wrap" >
							<view class=""  v-for="(item, index) in sellType" :key="item.value">
								<label class="lableitem flex ali-c" >
									<view>
										<radio  color="#FF6900" :value="item.value" :checked="item.value == form.sell_type" />
									</view>
									<view class="titles">{{item.name}}</view>
								</label>
							</view>	
						</view>	
					</radio-group>
				</view>	
			</view> -->
			
			<view class="noecellbox">
				<view class="title">必选品或非必选</view>
				<view class="inputbox flex">
					<radio-group @change="mandatoryradioChange">
						<view class="chindlost ali-c flex flex-wrap" >
							<view class=""  v-for="(item, index) in mandatoryType" :key="item.value">
								<label class="lableitem flex ali-c" style="margin-right: 40upx;">
									<view >
										<radio  color="#FF6900" :value="item.value" :checked="item.value == form.mandatory" />
									</view>
									<view class="titles">{{item.name}}</view>
								</label>
							</view>	
						</view>	
					</radio-group>
				</view>	
			</view>
			
			<view class="noecellbox"   v-if="isadd==1">
				<view class="title">商品库存(库存剩余{{form.stock}})</view>
				<view class="inputbox flex">
					<radio-group @change="radioChanges">
						<view class="chindlost ali-c flex flex-wrap" >
							<view class="" style="margin-right: 20rpx;"  v-for="(item, index) in storeNumber" :key="item.value">
								<label class="lableitem flex ali-c" >
									<view>
										<radio  color="#FF6900" :value="item.value" :checked="item.checked == 1" />
									</view>
									<view class="titles">{{item.name}}</view>
								</label>
							</view>	
						</view>
					</radio-group>
					数量：<input class="input flex1" v-if=""  @input="bingInput" type="number" v-model="stock_number" value="" placeholder-class="plclass" placeholder="增加库存数量"  />
				</view>
			</view>
			
			<view class="noecellbox" v-if="isadd==0">
				<view class="title">商品库存</view>
				<view class="inputbox flex">
					<input class="input flex1" v-if=""  type="number" v-model="stock_number" value="" placeholder-class="plclass" placeholder="增加库存数量"  />
				</view>
			</view>
			
			
			
			<view class="noecellbox" v-if="codeDisabled" >
				<view class="title">条形编码</view>
				<view class="inputbox flex">
					<input class="input flex1" type="number"   :disabled='codeDisabled' @tap="onCodeFocus" :value="form.code" placeholder-class="plclass" placeholder="请填写条形编码"  />
				</view>
			</view>
			
			
			<view class="noecellbox" v-if="!codeDisabled">
				<view class="title">条形编码 <text style="color: #808080;">(称重商品编码1-4000)</text></view>
				<view class="inputbox flex">
					<input class="input flex1" type="number" v-model="form.code"   @tap="onCodeFocus" value="" placeholder-class="plclass" placeholder="请填写条形编码"  />
				</view>
			</view>
			
			<view class="noecellbox">
				<view class="title">返佣比例</view>
				<view class="inputbox flex">
					<input class="input flex1"  type="number" v-model="form.commission" value="" placeholder-class="plclass" placeholder="请填写返佣比例(0-100)%"  />
				</view>
			</view>
			
			<view class="noecellbox">
				<view class="title">进货价</view>
				<view class="inputbox flex">
					<input class="input flex1"  type="text" v-model="form.cost_price" value="" placeholder-class="plclass" placeholder="请填写进货价"  />
				</view>
			</view>
			<!--quality_guarantee_period 保质期（月）
				manufacture_date 生产日期
				manufacturer 生产厂商
				brand 品牌 
			-->
			<view class="noecellbox">
				<view class="title">生产日期</view>
				<view class="inputbox flex">
					<picker mode="date" fields="day" :value="form.manufacture_date"  @change="bindDateChange">
						<input disabled="true" class="input flex1"  type="text" v-model="form.manufacture_date" value="" placeholder-class="plclass" placeholder="请填写生产日期"  />
					</picker>
				</view>
			</view>
			
			<view class="noecellbox">
				<view class="title">保质期</view>
				<view class="inputbox flex">
					<input class="input flex1" style="text-align: center;" type="number" v-model="qualitYears" value="" placeholder-class="plclass" placeholder="请填写年"  />
					年
					<input class="input flex1" style="text-align: center;" type="number" v-model="qualityMonths" value="" placeholder-class="plclass" placeholder="请填写月"  />
					月
					<input class="input flex1" style="text-align: center;" type="number" v-model="qualityDays" value="" placeholder-class="plclass" placeholder="请填写日"  />
					日
				</view>
				
			</view>
			
			<view class="noecellbox">
				<view class="title">生产厂商</view>
				<view class="inputbox flex">
					<input class="input flex1"  type="text" v-model="form.manufacturer" value="" placeholder-class="plclass" placeholder="请填写生产厂商"  />
				</view>
			</view>
			
			<view class="noecellbox">
				<view class="title">品牌</view>
				<view class="inputbox flex">
					<input class="input flex1"  type="text" v-model="form.brand" value="" placeholder-class="plclass" placeholder="请填写品牌"  />
				</view>
			</view>
			
		</view>
		<!-- YYYYY -->
		
		<view class="" :hidden="linkage_product_id != 0 "  v-if="is_datashow">
			
		
		<view class="briefIntroduction">
			<view class="title fontColor">产品描述<text style="color: red;">(必填)</text></view>
			<textarea class="textarea" v-model="form.desc" placeholder="请输入产品描述"/>
		</view>
		
		<view class="noecellbox">
			<view class="title">餐盒费</view>
			<view class="inputbox flex">
				<input class="input flex1"  type="text" v-model="form.lunch_box_fee" value="0" placeholder-class="plclass" placeholder="请填写产品餐盒费"  />
			</view>
		</view>
		
		
		<view class="noecellbox">
			<view class="title">排序</view>
			<view class="inputbox flex">
				<input class="input flex1"  type="number" v-model="form.orderby" maxlength="3" value="0" placeholder-class="plclass" placeholder="请填写产品排序"  />
			</view>
		</view>
		
		<!-- 分类 -->
		<view class="Specificationsbox">
			<view class="splcsinfo flex ali-c jus-b">
				<view class="name">产品分类</view>
				<view class="ali-c">
					<text></text>
					<image class="imgs" src="/static/news/xiamassfd.png" mode=""></image>
				</view>
			</view>
			<view class="sort flex ali-c ">
				<view class="name fontColor" >分类<text style="color: red;">(必选)</text></view>
				<view class="inputs" @tap='pickerone'>
					<view class="" style="padding-left: 15upx;">{{cate_name}}</view>
				</view>
				<lb-picker ref="picker" :list="chindformList" :value='index' range-key="label" :props="myProps" @confirm='confirm'></lb-picker>
			</view>
		</view>

		<view class="addmigs">
			<view class="titlehe">产品缩略图<text style="color: red;">(必传)</text></view>
			<robby-image-upload 
				fileKeyName="img" 
				:value="c_pics" 
				:server-url="uploadurl1+'/merchant.php/FileUpload/uploadify'" 
				:form-data="c_formData" 
				 @add="c_onImg" 
				 @delete="c_delImage" 
				 :limit="1"
				 >
			 </robby-image-upload>
		</view>
		
		<view class="addmigs">
			<view class="titlehe">产品轮播图<text style="color: red;">(必传)</text></view>
			<robby-image-upload 
				fileKeyName="img"
				:value="c_pics1" 
				:server-url="uploadurl1+'/merchant.php/FileUpload/uploadify'" 
				:form-data="c_formData" 
				 @add="c_onImg1" 
				@delete="c_delImage1" 
				 :limit="4"
				 >
			 </robby-image-upload>
		</view>
		
		<view class="addmigs">
			<view class="titlehe">产品详情图</view>
			<robby-image-upload 
				fileKeyName="img" 
				:value="c_pics2" 
				:server-url="uploadurl1+'/merchant.php/FileUpload/uploadify'" 
				:form-data="c_formData" 
				@add="c_onImg2" 
				@delete="c_delImage2" 
				:limit="9"
			>
			</robby-image-upload>
		</view>
		<!-- 多选列表  勾选的位置 -->
		<view class="checkboxs">
			<view class="title">属性:</view>
			
			<checkbox-group @change="checkboxChange">
				<view class="chindlost ali-c flex flex-wrap">
					<label class="lableitem flex ali-c" v-for="(item,index) in listchind" :key="index">
						<view>
							<checkbox color="#FF6900" :value="item.value" :checked="item.checked" />
						</view>
						<view class="titles">{{item.name}}</view>
					</label>
				</view>
				
				<view v-if="activity_type==1">
					<label class="lableitem flex ali-c" v-for="item of listissetkill" :key="index">
						<view>
							<checkbox color="#FF6900" :value="item.value" :checked="item.checked" />
						</view>
						<view class="titles">{{item.name}}</view>
					</label>
				</view>	
			</checkbox-group>
			
			
			<label class="lableitem flex ali-c" style="margin-top: 20upx;" >
				<view>
					<checkbox-group @change="changetuijian">
						<checkbox color="#FF6900" value="1" :checked="form.is_tuijian==1" />
					</checkbox-group>
				</view>
				<view class="titles">是否首页展示</view>
			</label>
			
		</view>
		<view v-if="isshowsetkilltime && activity_type==1">
			<view class="noecellbox">
				<view class="title">秒杀价格</view>
				<view class="inputbox flex">
					<input class="input flex1"  type="text" v-model="form.activity_price" value="" placeholder-class="plclass" placeholder="请填写产品价格"  />
					
				</view>
			</view>
			
			<view class="noecellbox">
				<view class="title">限购数量</view>
				<view class="inputbox flex">
					<input class="input flex1"  type="number" v-model="form.limit_num" value="" placeholder-class="plclass" placeholder="请填写产品价格" @input="isInt" />
				</view>
			</view>
			
			<view class="noecellbox">
				<view class="title">秒杀库存</view>
				<view class="inputbox flex">
					<input class="input flex1"  type="number" v-model="form.store_count" value="" placeholder-class="plclass" placeholder="请填写产品价格" @input="isInt" />
					
				</view>
			</view>
		</view>
		<view class="checkboxs" v-if="isshowsetkilltime && activity_type==1">
			<view class="title">选择秒杀时段:</view>
			<picker-view :value="ischeckedtime" indicator-style="height: 50px;" style="width: 100%; height: 200px;"   @change="pickerChange">
			      <picker-view-column >
					<view v-for="(item,index) in seckilltimelist" :key="index"  style="line-height: 50px; text-align: center;">{{item.title}}</view>
				  </picker-view-column>
			</picker-view>
		</view>
	</view>
		<view class="submitbtn active" @tap="getForm">提交</view>
		
	</view>
</template>

<script>
	import QSApp from '@/components/QS-inputs-split/js/app.js';
	import {addEditEleProduct,typeManager,eleProductInfo,findEleProduct} from "@/utils/api/api.js";
	import{getskipShop,getshopclass} from "@/utils/api/merchant.js";
	
	import robbyImageUpload from '@/components/plan-image-upload/up_img';//上传资质图片组件
	import {getActivityList} from '@/utils/api/merchant.js';
	export default {
		components:{
			robbyImageUpload
		},
		data() {
			return {
				
				linkage_id:'',
				is_datashow:true,
				bools:'',
				linkage_product_id:0,
				classValue:'',
				ordinary :[],
				 weigh :[],
				classData:[
					['普通商品','称重商品'],
					[]
					],
				classDataValue:[0,0],
				is_bld:'',
				isadd:0,  //0 填写商品库存  1修改库存 
				stock_number:'',
				stockType:1,
				qualitYears:"",
				qualityMonths:"",
				qualityDays:"",
				sellType: [{
                    value: '1',
                    name: '计件（件）',
					checked:'1'
                }, {
                    value: '2',
                    name: '计重（kg）',
					checked:'2'
                }],
				
				 mandatoryType: [{
				    value: '1',
				    name: '必选品',
					checked:'1'
				}, {
				    value: '2',
				    name: '非必选',
					checked:'2'
				}],
				
				storeNumber: [{
				    value: '1',
				    name: '增加库存',
					checked:'1'
				}, {
				    value: '2',
				    name: '减少库存',
					checked:'2'
				}],
				ischeckedtime:[0],//默认选中，
				name: 'product',
				result:[],
				form: {
					mandatory:'2',
					 linkage_id:'',
					//cost_price 成本价 stock 商品库存purchase 进货价钱code 条形编码commission 返佣比例original_name 原始商品名
					specifications:'',//商品规格
					stock:'', //商品库存
					cost_price:'', //进货价钱
					code:'' ,//条形编码
					commission:'', //返佣比例
					sell_type:0,// 售卖类型
					commodity_data:{}, //原始商品名
					quality_guarantee_period:0, //保质期（月）
					manufacture_date:'' ,    //生产日期
					manufacturer :'',    ///生产厂商
					brand  :'',     // 品牌 
					checkbox: [],//断选
					product_id:"",//修改的时候的产品id
					product_name:"",//产品名称
					desc:"",//产品描述
					cate_id:"",//产品分类id
					photo:"",//产品图片
					lunch_box_fee:'',//餐盒费
					orderby:100,//排序
					is_new:"",//是否新产品
					is_hot:"",//是否热卖产品
					is_tuijian:"0",//0 1是否首页推荐 
					action:"add",//	方式（添加：add，修改:edit）
					price:"",//价格
					activity_price:"",//秒杀价
					store_count:""	,// 秒杀库存
					is_seckill:"0",//0 1 是否秒杀产品
					activity_id:'0',//秒杀activity_id
					activity_list:'',//秒杀列表
					limit_num:"0" //秒杀限购数量 0 不限制 
				},
				timeList:[
					{}
				],
				isShow:false,
				chindformList:[],
				myProps:{
					label:'cate_name',
					value: 'cate_id',
					children: '',
				},
				
				//上传图片相关的
				c_pics: [],
				c_pics1:[],
				c_pics2:[],
				c_formData: { //请求接口得参数
					model:"shopphoto",
				},
				product_id:"",//修改产品时候用的修改id
				defaultinfo:{},//修改的时候的默认初始数据
				listchind:[
					{name:"是否新产品",value:"is_new",checked:false},
					{name:"是否热卖产品",value:"is_hot",checked:false},
				],
				isshowsetkilltime:false,//是否显示秒杀时间
				listissetkill:[{name:"是否秒杀产品",value:"is_seckill",checked:false}],
				activity_type:"",//判断是否可以秒杀
				seckilltimelist:[],//秒杀时段列表
				selchildList:[],
				
				index:0,
				isScanCode:true,//是不是点击了扫码 
				codeDisabled:false,//条形码是否能输入
				update:true,
				detail_photos:[],//详情图片
				video_photos:[],//轮播图片
				
				cate_name:"", //分类名
				
			}
		},
		computed: {
			uploadurl1(){
				return this.$store.state.uploadurl1;
			},
			staticUrl(){
				return this.$store.state.staticUrl;
			},
		},
		onLoad(opdata) {
			getskipShop({
				type:'bld'
			}).then(res=>{
				if(res.code == 0){
					this.is_bld = res.data.is_bld
				}
			})
			getshopclass({}).then(res=>{
				if(res.code == 0){
					this.ordinary = res.data.ordinary
					this.weigh = res.data.weigh
					this.classData[1] = Array.from(res.data.ordinary)
					if(this.ordinary.length!=[]){
						for(let i=0;i<res.data.ordinary.length;i++){
							this.classData[1][i] = res.data.ordinary[i].product_name						
						}
					}
				}
			})
			
			if(opdata.isadd=="0" || opdata.isadd=="1"){
				this.isadd = opdata.isadd
			}
			
			this.c_formData.user_token = this.$store.state.token;
			this.activity_type = opdata.activity_type,
			this.isShow = this.activity_type==1?true:false
			if(opdata.id!=undefined){
				this.product_id = opdata.id;
				uni.setNavigationBarTitle({
					title:"修改外卖产品"
				})
			}else{
				uni.setNavigationBarTitle({
					title:"添加外卖产品"
				})
			}
			this.typeManagerfun();
			this.getActivityListfun(); //获取数据列表

			if(opdata.results){
				// return;JSON.parse(opdata.results).errMsg == "request:fail abort statusCode:-1"
				if(JSON.parse(opdata.results).errMsg == "request:fail abort statusCode:-1"){
					let results = JSON.parse(opdata.results);
					this.form.code = results.code
					this.findEleProduct(results)
				}else{
					if(JSON.parse(opdata.results).data.code==1){
						let results=JSON.parse(opdata.results);//扫描得到得商品信息
						this.form.code = results.data.data.barcode;
						this.findEleProduct(results);
					}else{
						let results = JSON.parse(opdata.results);
						this.form.code = results.code
						this.findEleProduct(results)
					}
				}
			}
		},
		methods: {
			//是否推荐
			changetuijian(e){
				console.info(e,"eee");
				if(e.target.value.indexOf("1")!=-1){//选中了
					this.form.is_tuijian = "1";
				}else{
					this.form.is_tuijian = "0";
				}
			},
			columnbindData(e){		
				this.classDataValue[e.detail.column]=e.detail.value;
				
				if(e.detail.column == 0){ 
					
					if(e.detail.value == 0){
						console.log('我滑动到普通商品')
						
						this.$set(this.classData,1,[]);
						if(this.ordinary.length!=0){
							this.ordinary.map(item=>{
								this.classData[1].push(item.product_name);
							})
						}
						// console.log(this.classData[1])
					}else {
						console.log('我滑动到称重商品')
						// this.classData[1] = [];
						this.$set(this.classData,1,[]);
						if(this.weigh.length!=0){
							this.weigh.map(item=>{
								this.classData[1].push(item.product_name);
							})
						}
						
					}
				}
			},
			bindData(e){
				let that = this
				console.log(e)
				if(e.detail.value[0] == 0){
					console.log(that.ordinary.length,'左边')
					if(that.ordinary.length != 0){
						that.linkage_id = that.ordinary[e.detail.value[1]].product_id
						// that.product_id = that.ordinary[e.detail.value[1]].product_id
						that.linkage_product_id = that.linkage_id
						that.classValue = that.ordinary[e.detail.value[1]].product_name
					}else{AZ
						uni.showToast({
							title:'没有选中商品',
							icon:'none'
						})
						return false;
					}
				}else{
					console.log(that.weigh.length,'右边')
					if(that.weigh.length != 0){
						that.linkage_id = that.weigh[e.detail.value[1]].product_id
						// that.product_id = that.weigh[e.detail.value[1]].product_id
						that.linkage_product_id = that.linkage_id
						that.classValue = that.weigh[e.detail.value[1]].product_name
					}else{
						uni.showToast({
							title:'没有选中商品',
							icon:'none'
						})
						return false;
					}	
				}
				that.eleProductInfofun(that.linkage_id,2);
				this.is_datashow = false;
				console.log(this.is_datashow)
				
			},
			
			bingInput(e){
				let stock_number=e.detail.value;
				this.stock_number=stock_number;
				let stock=Number(this.form.stock);//库存
				let checked=this.storeNumber[1].checked;
				if(checked==1){
					if(stock-stock_number < 0 ){
						//this.$set(this,'stock_number',0);
						this.stock_number=0;
						
						this.$api.msg('库存不足')
					}
				}
				
			},
			bindDateChange: function(e) {
			      this.form.manufacture_date = e.target.value
			 },
			
			
			onCodeFocus(){  //条形码输入框聚焦事件
				if(this.codeDisabled){
					this.$api.msg('不能修改条形编码');
				}
			},
			async findEleProduct(results){
				uni.showLoading({title:'请稍后'});
				let res=await findEleProduct({code:results.code});
				console.info("res1",res);
				uni.hideLoading();
				if(res.code==-1){ //没有就录入
					if(results.data.msg=='暂未收录此商品'){
						this.$set(this.form,'code',results.code);
					}else{
						this.$set(this,'isadd',0);
						this.$set(this.form,'manufacturer',results.data.data.supplier);
						this.$set(this.form,'brand',results.data.data.brand);
						this.$set(this.form,'original_name',results.data.data.goodsName);
						this.$set(this.form,'product_name',results.data.data.goodsName);
						this.$set(this.form,'commodity_data',results.data.data);
						this.$set(this.form,'price',results.data.data.price);
						this.$set(this,'isScanCode',results.isScanCode);
					}
					this.$set(this,'codeDisabled',false);
				
				}else if(res.code==0){ //有就把信息展示
					this.isadd=1;
					this.form.quality_guarantee_period = res.data.quality_guarantee_period
					this.qualitYears = parseInt(res.data.quality_guarantee_period/365)
					this.qualityMonths = parseInt((res.data.quality_guarantee_period%365)/30)
					this.qualityDays = parseInt((res.data.quality_guarantee_period%365)%30)
					this.form.manufacture_date = res.data.manufacture_date
					this.form.manufacturer = res.data.manufacturer
					this.form.brand = res.data.brand
					this.form.sell_type = res.data.sell_type	
					this.form.stock=res.data.stock //商品库存
					this.form.cost_price=res.data.cost_price //进货价钱
					this.form.code=res.data.code //条形编码
					this.form.commission=res.data.commission //返佣比例
					this.form.is_tuijian = res.data.is_tuijian?res.data.is_tuijian:'0';//是否首页显示
					
					if(res.data.commodity_data == "" ){
						this.form.commodity_data= res.data.commodity_data
					}else{
						this.form.commodity_data= typeof(res.data.commodity_data) == 'string'?JSON.parse(res.data.commodity_data):res.data.commodity_data //原始商品名
					}
					
					this.form.product_id=res.data.product_id//修改的时候的产品id
					this.form.product_name=res.data.product_name//产品名称
					this.form.desc=res.data.desc//产品描述
					this.form.cate_id=res.data.cate_id//产品分类id
					this.form.lunch_box_fee=res.data.lunch_box_fee//餐盒费
					this.form.orderby = res.data.orderby;//排序
					this.form.is_new=res.data.is_new//是否新产品
					this.form.is_hot=res.data.is_hot//是否热卖产品
					
					this.form.price=res.data.price//价格
					this.form.activity_price=res.data.activity_price//秒杀价
					this.form.store_count=res.data.store_count	// 秒杀库存
					this.form.activity_id=res.data.activity_id//秒杀activity_id
					this.form.activity_list=res.data.activity_list//秒杀列表
					this.form.limit_num=res.data.limit_num//秒杀限购数量 0 不限制 
					this.isScanCode=false
					this.codeDisabled=true //条形码输入框是否禁止输入
					this.c_pics=[{code:0,data:res.data.photo,msg:"success",time:"1587101904"}];
					
					
					// console.log(this.form.product_name,12131321314312423142123321);
					// console.log(this.chindformList);
		
					for(var i = 0; i < this.chindformList.length; i++) {
						 if(this.chindformList[i].cate_id==res.data.cate_id){
						 	this.cate_name=this.chindformList[i].cate_name;
							break;
						 }
					}
					
					
				}
			},
			saoma(e){
				uni.scanCode({
				    success:(res) => {
						var code =  res.result; 
						this.form.code = res.result;
						uni.request({
							url: 'https://www.mxnzp.com/api/barcode/goods/details', //仅为示例，并非真实接口地址。
							data: {
							    barcode:code,
								needImg: true,
								app_id:'qkkbptetyohxoiod',
								app_secret:'Wkp2a3NiNjAzTFJLRmwrZXN3QW1jZz09'
							},
							method:'GET',
							success: (results) => {
								console.log(results)
								if(results.data.code==1){
									results.code=code;
									results.isScanCode=false;
									console.info(results,"111");
									this.findEleProduct(results);
								}else{
									results.code=code;
									results.isScanCode=false;
									this.findEleProduct(results);
								}
								
							
							 }
						})
				    },
					fail:(err)=>{
						console.log(err)
					}
				});
			},
			
			radioChange(e){
				// console.log(this.isType)
				 this.form.sell_type = e.detail.value
				 console.log(this.form.sell_type)
			},
			mandatoryradioChange(e){
				this.form.mandatory = e.detail.value
				 console.log(this.form.mandatory)
			},
			
			radioChanges(e){	
				
				let index=Number(e.detail.value)-1;
				let storeNumber=this.storeNumber;
				storeNumber.map(item=>{
					item.checked=2;
				})
				storeNumber[index].checked=1;
				this.$set(this,'storeNumber',storeNumber);
				
				 
			},
			confirm(e){
				this.cate_name = e.item.cate_name;
				this.form.cate_id =e.item.cate_id;
				this.index = e.index;
			},
			
			pickerone(){
				this.$refs.picker.show() // 显示
			},
			
			isInt(e){
				if(!this.isInteger(e.detail.value)){
					this.$api.msg("秒杀库存或限购数量不能为小数");
				}
			},
			//分类选中
			bindPickerChange(e){
				console.info(e.detail.value);
				console.log(this.chindformList)
				this.cate_name = this.chindformList[e.detail.value].cate_name;
				this.form.cate_id = this.chindformList[e.detail.value].cate_id;
				this.index = e.detail.value;
				
			},
			//标记选中属性列表
			checkboxChange(e){
				this.selchildList = e.detail.value;
				this.isshowsetkilltime = e.detail.value.indexOf('is_seckill') ==-1? false:true;
				if(this.isshowsetkilltime){
					this.form.activity_list ="49,"
				}else{
					this.form.activity_list =""
				}
				this.selchildList = e.detail.value;
				
			},
			//修改的时候赋初始值
		 	async eleProductInfofun(product_id,second=1){
				let that=this;
				let res = await eleProductInfo({
					product_id:product_id,
				});
				if(res.code==0){	
					this.form.cate_id = res.data.cate_id;//分类id
					for(var i = 0; i < this.chindformList.length; i++) {
						 if(this.chindformList[i].cate_id==res.data.cate_id){
						 	this.cate_name=this.chindformList[i].cate_name;
							break;
						 }
					}
					
					if(second==1){
						console.log('第一次')
						this.linkage_product_id = res.data.linkage_product_id
					}
					
					this.form.is_tuijian = res.data.is_tuijian?res.data.is_tuijian:'0';//是否首页显示
					this.bools = res.data.product_name;
					this.defaultinfo = res.data;
					this.form.product_name = res.data.product_name;//名称
					this.form.desc = res.data.desc;//描述
					this.form.lunch_box_fee = res.data.lunch_box_fee/100;//餐盒费
					this.form.orderby = res.data.orderby;
					this.form.price = res.data.price;//价格
					this.form.photo = res.data.photo;//图片
					this.form.activity_price = res.data.activity_price //秒杀价
					this.form.store_count = res.data.store_count //秒杀库存
					this.form.activity_id = res.data.activity_id//秒杀时段id
					this.form.limit_num = res.data.limit_num
					this.form.specifications = res.data.gram
					this.form.quality_guarantee_period = res.data.quality_guarantee_period
					this.qualitYears = parseInt(res.data.quality_guarantee_period/365)
					this.qualityMonths = parseInt((res.data.quality_guarantee_period%365)/30)
					this.qualityDays = parseInt((res.data.quality_guarantee_period%365)%30)
					this.form.manufacture_date = res.data.manufacture_date
					this.form.manufacturer = res.data.manufacturer
					this.form.brand = res.data.brand
					this.form.stock = res.data.stock, 					//商品库存
					this.form.cost_price  =  res.data.cost_price/100, 				//进货价钱
					this.form.code  =  res.data.code ,						//条形编码
					this.form.commission  = res.data.commission, 				//返佣比例
					this.form.sell_type = res.data.sell_type,				// 售卖类型
					this.form.mandatory = res.data.mandatory
					
					if(typeof res.data.video_photos == 'object'){
						this.video_photos=res.data.video_photos;//轮播
						for(let i in res.data.video_photos){
							this.c_pics1.push({
								code:0,
								data:res.data.video_photos[i],
								msg:"success",
								time:"1587101904"
							});
						}
					}
					
					
					if(typeof res.data.detail_photos == 'object'){
						this.detail_photos=res.data.detail_photos;//详情
						for(let i in res.data.detail_photos){
							this.c_pics2.push({
								code:0,
								data:res.data.detail_photos[i],
								msg:"success",
								time:"1587101904"
							});
						}
					}
					
					//下拉分类 初始值
					this.chindformList.forEach((item,index)=>{
						if(item.cate_id==res.data.cate_id){
							this.index =index;
							this.cate_name = item.cate_name;
						}
					});
					
					
					
					if(res.data.commodity_type == 'ordinary') {
						this.ordinary.map(item=>{
							if(this.linkage_product_id == item.product_id){
								this.classValue = item.product_name
							}
						}) 
					}else if(res.data.commodity_type == 'weigh'){
						this.weigh.map(item=>{
							if(this.linkage_product_id == item.product_id){
								this.classValue = item.product_name
							}
						})
						
					}else{
						this.classValue = '';
					}
					
					//属性选默认值
					if(res.data.is_new==1){
						this.selchildList.push("is_new");
						this.listchind[0].checked = true;
					}else{
						this.listchind[0].checked = false;
					}
					if(res.data.is_hot==1){
						this.selchildList.push("is_hot");
						this.listchind[1].checked = true;
					}else{
						this.listchind[1].checked = false;
					}
					
					if(res.data.activity_list == '49,'){
						this.listissetkill[0].checked = true
						this.isshowsetkilltime = true
						this.form.activity_list = res.data.activity_list
						
					let indexlist =	this.seckilltimelist.filter((item,index)=>{
						if(item.activity_id==this.form.activity_id){
							return item
						}
					})
					let temparr = indexlist[0] 
					let index = this.seckilltimelist.indexOf(temparr)
						this.ischeckedtime[0] = index
					}
					//处理上传的图片默认值
					this.c_pics = [{code:0,data:res.data.photo,msg:"success",time:"1587101904"}];
					this.form.photo = res.data.photo;
					
				}else{
					this.$api.msg(res.msg);
				}
			},
			getForm() {
				// if(this.isshowsetkilltime && (this.form.activity_price==""||this.form.store_count==""||this.form.limit_num=="") ){
				// 	this.$api.msg("请填写完整秒杀数据");
				// 	 return false;
				// }
				
				// console.log(this.form.limit_num,this.form.store_count)
				// if(!this.isInteger(this.form.limit_num) || !this.isInteger(this.form.store_count)){
				// 	this.$api.msg("秒杀库存或限购数量不能为小数");
				// 	return false;
				// }
				
				console.log(this.form.product_id)
				console.log(this.product_id)
				
				let can = {
					action:this.product_id==''?'add':'edit',
					linkage_id:this.linkage_id,
					mandatory:this.form.mandatory,
					gram:this.form.specifications, //商品规格
					quality_guarantee_period : this.qualitYears*365+this.qualityMonths*30+this.qualityDays*1, //保质期（月）
					manufacture_date :this.form.manufacture_date,    //生产日期
					manufacturer: this.form.manufacturer,    ///生产厂商
					brand  : this.form.brand,     // 品牌 
					// stock:this.form.stock, //商品库存
					cost_price:this.form.cost_price, //进货价钱
					code:this.form.code,//条形编码
					sell_type:this.form.sell_type,
					commission:this.form.commission, //返佣比例
					commodity_data:this.form.commodity_data, //产品数据
					product_name:this.form.product_name,//产品名称
					desc:this.form.desc,//产品描述
					lunch_box_fee:this.form.lunch_box_fee,//餐盒费
					orderby:this.form.orderby,//排序
					price:this.form.price,//价格
					photo: this.c_pics.length == 0?'': this.c_pics[0].data, //图片
					activity_price:this.form.activity_price,//秒杀价
					store_count:this.form.store_count ,//秒杀库存
					activity_id:this.form.activity_id,//秒杀时间id
					activity_list:this.form.activity_list,
					limit_num:this.form.limit_num ,//秒杀限购数量	
					detail_photos:this.detail_photos,//详情图
					video_photos:this.video_photos,//轮播图
					cate_id:this.form.cate_id,
					is_tuijian:this.form.is_tuijian,//是否首页显示
				};
				
				if(can.action=='edit'){
					can.product_id=this.product_id
				}
				
				if(this.c_pics.length > 0){
					can.photo = this.c_pics[0].data; //图片
				}
				
				this.storeNumber.map((item,index)=>{
					if(item.checked==1){
						if(index==0){
							can.stock = this.stock_number
						}else{
							can.stock = '-'+ this.stock_number
						}
						
					}
				})
					
				if(this.selchildList.includes("is_new")){
					can.is_new = 1;
				}else{
					can.is_new = 0;
				}
				if(this.selchildList.includes("is_hot")){
					can.is_hot = 1;
				}else{
					can.is_hot = 0;
				}
				if(this.product_id!="" && this.is_datashow !=false ){ 
					can.product_id = this.product_id;
				}
				//添加修改外卖产品
				console.log(can);
				addEditEleProduct(can).then((res1)=>{
					// console.log(res1,'成功了');
					console.log("res1",res1);
					if(res1.code==0){
						this.$api.msg(res1.msg);
						setTimeout(()=>{
							uni.navigateBack({});
						},1000)
					}else{
						this.$api.msg(res1.msg);
					}
				}).catch(err=>{
					console.log(err,'失败了');
				})
			},
			
			pickerChange(e){
				console.log(e)
				this.form.activity_id  = this.seckilltimelist[e.detail.value[0]].activity_id;
			},
			// 秒杀列表
			async getActivityListfun(){
				let res = await getActivityList({
					audit:2,
				})
				if(res.code==0){
					this.seckilltimelist =  res.data.head
				}
			},
			//获取外卖分类列表 用于下拉选择
			async typeManagerfun(){
				let res = await typeManager({});
				if(res.code==0){
					this.chindformList = res.data;
					
					if(this.product_id!=undefined && this.product_id!=""){
						this.eleProductInfofun(this.product_id);
					}
				}else{
					this.$api.msg(res.msg);
				}
			},
			// 判断是否为整数
			isInteger(obj){
				return  obj%1 === 0;
			},
			c_onImg(e) { //上传缩略图
				this.isScanCode=true;
				this.c_pics= e.allImages
				
			},
			c_onImg1(e) { //上传轮播图
				this.isScanCode=true;
				this.c_pics1 = e.allImages;
				e.allImages.map((item,index)=>{
					this.video_photos[index] = item.data
				})
			},
			c_onImg2(e) { //上传详情图
				this.isScanCode=true;
				this.c_pics2 = e.allImages;
				e.allImages.map((item,index)=>{
					this.detail_photos[index] = item.data
				})
			},
			c_delImage(e) { //删除产品缩略图图片
				this.c_pics=[];
			},
			c_delImage1(e) { //删除轮播某个图片
				let arr=[];
				e.allImages.map(item=>{
					arr.push(item.data);
				});
				this.video_photos=arr;
			},
			c_delImage2(e) { //删除产品详情某个图片
				let arr=[];
				e.allImages.map(item=>{
					arr.push(item.data);
				})
				this.detail_photos=arr;
			},
		},
	}
</script>


<style lang="scss">
	@import  "../edit/product/addProjuct.scss";
	page{
		background: #fff;
	}
	.productpages{
		background: #FFFFFF;
	}
	
	.submitbtn{
		margin: 60upx 24upx;
		height:88upx;
		line-height: 88upx;
		text-align: center;
		background:rgba(254,197,156,1);
		border-radius:6upx;
		font-size:32upx;
		color:rgba(255,255,255,1);
	}
	
	.submitbtn.active{
		background: #FF6900;
	}
	.briefIntroduction,.Specificationsbox,.addmigs,.checkboxs{
		border-bottom:1px solid #F5F2F2;
		border-radius: 0 !important;
	}
	.img{
		width: 100upx;height: 100upx;
	}
	.input1::-ms-input-placeholder {
	    text-align: center;
	}
	 
	.input1::-webkit-input-placeholder {
	    text-align: center;
	}
</style>