<template>
	<div class="article-manager video-icon form-submit" id="shopp-manager">
		<div class="i-layout-page-header">
			<PageHeader class="product_tabs" hidden-breadcrumb>
				<div slot="title" class="acea-row row-middle">
					<router-link :to="{ path: `${roterPre}/erp/product` }">
						<div class="font-sm after-line">
							<span class="iconfont iconfanhui"></span>
							<span class="pl10">返回</span>
						</div>
					</router-link>
					<span v-text="$route.query.id ? '编辑商品' : '添加商品'" class="mr20 ml16"></span>
				</div>
			</PageHeader>
		</div>
		<Card :bordered="false" dis-hover class="ivu-mt mh">
			<Form class="formValidate mt20" ref="formValidate" :rules="ruleValidate" :model="formValidate"
				:label-width="labelWidth" :label-position="labelPosition" @submit.native.prevent>
				<Row :gutter="24" type="flex">
					<!-- 商品信息-->
					<Col span="24">
					<FormItem label="商品类型：" props="product_type">
						<div class="productType" :class="formValidate.product_type == item.id ? 'on' : ''"
							v-for="(item, index) in productType" :key="item.id" @click="productTypeTap(1,item)">
							<div class="name">{{ item.name }}</div>
							<!-- <div class="title">({{ item.title }})</div> -->
							<div v-if="formValidate.product_type == item.id" class="jiao"></div>
							<div v-if="formValidate.product_type == item.id" class="iconfont iconduihao"></div>
						</div>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品分类：" prop="cate_id">
						<el-cascader placeholder="请选择商品分类" v-width="'50%'" size="mini" v-model="formValidate.cate_id"
							:options="treeSelect" :props="props" filterable clearable>
						</el-cascader>
						<span class="addClass" @click="addClass" v-if="merchantType!=1">新增分类</span>

					</FormItem>
					</Col>
					<Col span="24" class="brandName">
					<FormItem label="商品品牌：" prop="">
						<Cascader :data="brandData" placeholder="请选择商品品牌" change-on-select
							v-model="formValidate.brand_id" filterable v-width="'50%'"></Cascader>
						<span class="addClass" @click="addBrand" >新增品牌</span>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品名称：" prop="store_name">
						<Input v-model="formValidate.store_name" placeholder="请输入商品名称" v-width="'50%'" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品简介：" prop="">
						<Input v-model="formValidate.store_info" type="textarea" :rows="3" placeholder="请输入商品简介"
							v-width="'50%'" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品关键字：" prop="">
						<Input v-model="formValidate.keyword" placeholder="请输入商品关键字" v-width="'50%'" />
						<div class="tips">通过命中关键字搜索对应商品，方便用户查找</div>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="单位：" prop="unit_name">
						<Select v-model="formValidate.unit_name" clearable filterable v-width="'50%'"
							placeholder="请输入单位">
							<Option v-for="(item, index) in unitNameList" :value="item.name" :key="item.id">
								{{ item.name }}
							</Option>
						</Select>
						<span class="addClass" @click="addUnit" v-if="merchantType!=1">新增单位</span>
					</FormItem>
					</Col>

					<Col span="24">
					<FormItem label="大单位：" prop="unit_name_1">
						<Select v-model="formValidate.unit_name_1" clearable filterable v-width="'50%'"
							placeholder="请输入大单位">
							<Option v-for="(item, index) in unitNameList" :value="item.name" :key="item.id">
								{{ item.name }}
							</Option>
						</Select>
						<span class="addClass" @click="addUnit" v-if="merchantType!=1">新增单位</span>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="大单位转化率：" prop="unit_rate_1" v-if="formValidate.unit_name_1">
						<Input v-model="formValidate.unit_rate_1" placeholder="请输入大单位转化率" v-width="'50%'" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="超大单位：" prop="unit_name_2">
						<Select v-model="formValidate.unit_name_2" clearable filterable v-width="'50%'"
							placeholder="请输入超大单位">
							<Option v-for="(item, index) in unitNameList" :value="item.name" :key="item.id">
								{{ item.name }}
							</Option>
						</Select>
						<span class="addClass" @click="addUnit" v-if="merchantType!=1">新增单位</span>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="超大单位转化率：" prop="unit_rate_2" v-if="formValidate.unit_name_2">
						<Input v-model="formValidate.unit_rate_2" placeholder="请输入超大单位转化率" v-width="'50%'" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品推荐图：">
						<div class="acea-row">
							<div v-if="formValidate.recommend_image" class="pictrue">
								<img v-lazy="formValidate.recommend_image" />
								<Button shape="circle" icon="md-close" @click.native="formValidate.recommend_image = ''"
									class="btndel"></Button>
							</div>
							<div v-else class="upLoad acea-row row-center-wrapper"
								@click="modalPicTap('dan', 'recommend_image')">
								<Icon type="ios-camera-outline" size="26" />
							</div>
							<Input v-model="formValidate.recommend_image" class="input-display"></Input>
						</div>
						<div class="tips">在特殊的商品分类样式中显示(建议图片比例5:2)
							<Poptip placement="bottom" trigger="hover" width="256" transfer padding="8px">
								<a>查看示例</a>
								<div class="exampleImg" slot="content">
									<img :src="`${baseURL}/statics/system/productRecommendImage.png`" alt="" />
								</div>
							</Poptip>
						</div>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品轮播图：" prop="slider_image">
						<div class="acea-row">
							<div class="pictrue" v-for="(item, index) in formValidate.slider_image" :key="index+'img'"
								draggable="true" @dragstart="handleDragStart($event, item)"
								@dragover.prevent="handleDragOver($event, item)"
								@dragenter="handleDragEnter($event, item)" @dragend="handleDragEnd($event, item)">
								<img v-lazy="item" />
								<Button shape="circle" icon="md-close" @click.native="handleRemove(index)"
									class="btndel"></Button>
							</div>
							<div v-if="formValidate.slider_image.length < 10" class="upLoad acea-row row-center-wrapper"
								@click="modalPicTap('duo')">
								<Icon type="ios-camera-outline" size="26" />
							</div>
							<Input v-model="formValidate.slider_image[0]" class="input-display"></Input>
						</div>
						<div class="tips"> 建议尺寸：800 * 800px，可拖拽改变图片顺序，默认首张图为主图，最多上传10张</div>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="排序：">
						<InputNumber :min="0" :max="999999" v-width="'50%'" v-model="formValidate.sort"
							placeholder="请输入排序" />
					</FormItem>
					</Col>
					<Col span="24" class="goodsShow">
					<FormItem label="是否上架：">
						<Switch v-model="formValidate.is_show" :true-value="1" :false-value="0" size="large"
							@on-change="goodsOff">
							<span slot="open">是</span>
							<span slot="close">否</span>
						</Switch>
					</FormItem>
					</Col>
					<Col span="24" class="goodsShow">
					<FormItem label="是否称重：">
						<Switch v-model="formValidate.is_weigh" :true-value="1" :false-value="0" size="large"
							@on-change="goodsOff">
							<span slot="open">是</span>
							<span slot="close">否</span>
						</Switch>
					</FormItem>
					</Col>
					<Col span="24" class="goodsShow">
					<FormItem label="是否可调价：">
						<Switch v-model="formValidate.is_dicker" :true-value="1" :false-value="0" size="large"
							@on-change="goodsOff">
							<span slot="open">是</span>
							<span slot="close">否</span>
						</Switch>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品详情：" prop="description">
						<Input v-model="formValidate.description" type="textarea" :rows="3" placeholder="请输入商品详情"
							v-width="'50%'" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品条形码：" prop="bar_code">
						<Input v-model="formValidate.bar_code" placeholder="请输入商品条形码" v-width="'50%'" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="价格：" prop="price">
						<Input v-model="formValidate.price" placeholder="请输入价格" v-width="'50%'" type="number" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="VIP价格：" prop="vip_price">
						<Input v-model="formValidate.vip_price" placeholder="请输入VIP价格" v-width="'50%'" type="number" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="成本价：" prop="cost">
						<Input v-model="formValidate.cost" placeholder="请输入成本价" v-width="'50%'" type="number" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="保质期(天)：" prop="shelf_life">
						<Input v-model="formValidate.shelf_life" placeholder="请输入成本价" v-width="'50%'" type="number" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="商品编码：" prop="">
						<Input v-model="formValidate.code" placeholder="请输入商品编码" v-width="'50%'" />
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="仅会员可见：">
						<i-switch v-model="formValidate.is_vip_product" :true-value="1" :false-value="0" size="large">
							<span slot="open">开启</span>
							<span slot="close">关闭</span>
						</i-switch>
						<div class="tips">开启后仅付费会员可以看见并购买此商品</div>
					</FormItem>
					</Col>
					<Col span="24">
					<FormItem label="是否限购：">
						<i-switch v-model="formValidate.is_limit" :true-value="1" :false-value="0" size="large"
							@on-change="limitTap">
							<span slot="open">开启</span>
							<span slot="close">关闭</span>
						</i-switch>
					</FormItem>
					</Col>
					<Col span="24" v-if="formValidate.is_limit">
					<FormItem label="限购类型：">
						<RadioGroup v-model="formValidate.limit_type">
							<Radio :label="1">单次限购</Radio>
							<Radio :label="2">长期限购</Radio>
						</RadioGroup>
						<div class="tips">
							单次限购是限制每次下单最多购买的数量，长期限购是限制一个用户总共可以购买的数量
						</div>
					</FormItem>
					</Col>
					<Col span="24" v-if="formValidate.is_limit">
					<FormItem label="限购数量：">
						<InputNumber :min="1" v-model="formValidate.limit_num" placeholder="请输入限购数量"
							class="perW20 maxW" />
					</FormItem>
					</Col>
				</Row>
			</Form>
			<Modal v-model="modalPic" width="960px" scrollable footer-hide closable title="上传商品图" :mask-closable="false"
				:z-index="1">
				<uploadPictures :isChoice="isChoice" @getPic="getPic" @getPicD="getPicD" :gridBtn="gridBtn"
					:gridPic="gridPic" v-if="modalPic"></uploadPictures>
			</Modal>
			<menus-from :formValidate="formBrand" :fromName='1' ref="menusFrom" @reload="getBrandList"></menus-from>
		</Card>
		<Card :bordered="false" dis-hover class="fixed-card"
			:style="{ left: `${!menuCollapse ? '200px' : isMobile ? '0' : '80px'}` }">
			<Form>
				<FormItem>
					<Button type="primary" class="submission" @click="handleSubmit('formValidate')">保存</Button>
				</FormItem>
			</Form>
		</Card>
	</div>
</template>

<script>
	// import COS from 'cos-js-sdk-v5'
	import {
		mapState,
		mapMutations
	} from "vuex";
	import Setting from "@/setting";
	import util from "@/libs/util";
	import vuedraggable from "vuedraggable";
	import uploadPictures from "@/components/uploadPictures";
	import freightTemplate from "@/components/freightTemplate";
	import wangeditor from "@/components/wangEditor/index.vue";
	import storeList from "@/components/storeList";
	import menusFrom from "../../product/productBrand/components/menusFrom";
	import userLabel from "@/components/labelList";
	import storeLabelList from "@/components/storeLabelList";
	import couponList from "@/components/couponList";
	import goodsList from '@/components/goodsList/index';
	// import addAttr from "../productAttr/addAttr";
	// import attrList from "../components/attrList";
	// import addCarMy from "../components/addCarMy";
	// import taoBao from './taoBao'

	import {
		addProduct,
		getGoodInfo
	} from "@/api/erp"
	import {
		productInfoApi,
		cascaderListApi,
		productAddApi,
		generateAttrApi,
		productGetRuleApi,
		productGetTemplateApi,
		productGetTempKeysApi,
		checkActivityApi,
		labelListApi,
		productCache,
		cacheDelete,
		brandList,
		productCreateApi,
		productAllUnit,
		productUnitCreate,
		uploadType,
		productAllEnsure,
		productLabelAdd,
		productAllSpecs,
		allSystemForm
	} from "@/api/product";
	import {
		erpGoods
	} from '@/api/erp'
	import {
		systemFormInfo
	} from '@/api/setting'
	import {
		getSupplierList
	} from '@/api/supplier'
	import {
		erpConfig
	} from "@/api/erp";
	import {
		uploadByPieces
	} from "@/utils/upload"; //引入uploadByPieces方法
	export default {
		name: "addProduct",
		components: {
			storeList,
			uploadPictures,
			freightTemplate,
			goodsList,
			// addAttr,
			couponList,
			// taoBao,
			userLabel,
			menusFrom,
			// attrList,
			// addCarMy,
			storeLabelList,
			wangeditor,
			draggable: vuedraggable,
		},
		data() {
			return {
				formTypeList: [],
				storesList: [],
				tableData: [],
				storeModals: false,
				roterPre: Setting.roterPre,
				specsList: [],
				supplierList: [],
				productType: [{
						name: "普通商品",
						// title: "物流发货",
						id: 0
					},
					{
						name: "生鲜",
						// title: "到店核销",
						id: 5
					},
				],
				virtualList: [],
				carMyShow: false, //是否开启卡密弹窗
				recommend: [], //商品推荐
				customBtn: false, //自定义留言开关
				attrShow: false,
				content: "",
				contents: "",
				seletVideo: 0,
				fileUrl: Setting.apiBaseURL + "/file/upload",
				fileUrl2: Setting.apiBaseURL + "/file/video_upload",
				baseURL: Setting.apiBaseURL.replace(/adminapi/, ''),
				upload_type: "", //视频上传类型 1 本地上传 2 3 4 OSS上传
				uploadData: {}, // 上传参数
				header: {},
				dataLabel: [],
				storeDataLabel: [],
				labelShow: false,
				storeLabelShow: false,
				props: {
					emitPath: false,
					multiple: true,
					checkStrictly: true
				},
				type: 0,
				goodsModals: false,
				off_show: 0,
				modals: false,
				spinShow: false,
				openSubimit: false,
				grid2: {
					xl: 10,
					lg: 12,
					md: 12,
					sm: 24,
					xs: 24,
				},
				grid3: {
					xl: 18,
					lg: 18,
					md: 20,
					sm: 24,
					xs: 24,
				},
				// 批量设置表格data
				oneFormBatch: [{
					attr: "全部",
					pic: "",
					price: 0,
					settle_price: 0,
					cost: 0,
					ot_price: 0,
					erp_product_id: 0,
					unit: 0,
					uint_to_erp_unit: 0,
					// stock: 0,
					bar_code: "",
					code: "",
					weight: 0,
					volume: 0,
				}, ],
				// 规格数据
				formDynamic: {
					attrsName: "",
					attrsVal: "",
				},
				formDynamicNameData: [],
				gridPic: {
					xl: 6,
					lg: 8,
					md: 12,
					sm: 12,
					xs: 12,
				},
				gridBtn: {
					xl: 4,
					lg: 8,
					md: 8,
					sm: 8,
					xs: 8,
				},
				formValidate: {
					product_type: 0,
					cate_id: [],
					store_name: '',
					store_info: '',
					keyword: '',
					unit_name: '',
					recommend_image: '',
					slider_image: [],
					sort: 0,
					is_show: 0,
					is_dicker: 1,
					description: "",
					brand_id: [],
					bar_code: "",
					is_vip_product: 0,
					vip_price: "",
					is_weigh: 0,
					price: "",
					cost: "",
					unit_name: "",
					unit_name_1: "",
					unit_name_2: "",
					unit_rate_1: "",
					unit_rate_2: "",
					shelf_life: "",
					is_limit: 0, //是否限购
					limit_type: 0, //限购类型
					limit_num: 0, //限购数量
				},
				images: [],
				imagesTable: "",
				currentTab: "1",
				isChoice: "",
				grid: {
					xl: 8,
					lg: 8,
					md: 12,
					sm: 24,
					xs: 24,
				},
				loading: false,
				modalPic: false,
				template: false,
				uploadList: [],
				treeSelect: [],
				labelSelect: [],
				ensureData: [],
				specsData: [],
				picTit: "",
				tableIndex: 0,
				ruleValidate: {
					store_name: [{
						required: true,
						message: "请输入商品名称",
						trigger: "blur"
					}, ],
					keyword: [{
						required: true,
						message: "请输入商品关键字",
						trigger: "blur"
					}, ],
					unit_name: [{
						required: true,
						message: "请输入单位",
						trigger: "change",
					}, ],
					store_info: [{
						required: true,
						message: "请输入商品简介",
						trigger: "blur"
					}, ],
					//image: [{ required: true, message: "请上传商品图", trigger: "change" }],
					slider_image: [{
						required: true,
						message: "请上传商品轮播图",
						type: "array",
						trigger: "change",
					}, ],
					spec_type: [{
						required: true,
						message: "请选择商品规格",
						trigger: "change"
					}, ],
					selectRule: [{
						required: true,
						message: "请选择商品规格属性",
						trigger: "change"
					}, ],
					give_integral: [{
						type: "integer",
						message: "请输入整数"
					}],
					bar_code: [{
						required: true,
						message: "请选择输入条形码",
					}],
					price: [{
						required: true,
						message: "请选择输入条形码",
					}],
					vip_price: [{
						required: true,
						message: "请选择输入条形码",
					}],
					cost: [{
						required: true,
						message: "请选择输入条形码",
					}],
					unit_rate_1: [{
						required: true,
						message: "请输入大单位转化率",
					}],
					unit_rate_2: [{
						required: true,
						message: "请输入超大单位转化率",
					}]
					// delivery_type:[
					//   { required: true, type: 'array', min: 1, message: '请选择配送方式', trigger: 'change' },
					// ]
				},
				manyBrokerage: 0,
				manyBrokerageTwo: 0,
				manyVipPrice: 0,
				upload: {
					videoIng: false, // 是否显示进度条；
				},
				videoIng: false, // 是否显示进度条；
				progress: 0, // 进度条默认0
				videoLink: "",
				attrs: [],
				activity: {
					默认: "colorBlue",
					秒杀: "colorBlue",
					砍价: "colorBlue",
					拼团: "colorBlue"
				},
				couponName: [],
				updateIds: [],
				updateName: [],
				rakeBack: [{
						title: "一级返佣",
						slot: "brokerage",
						align: "center",
						width: 95,
					},
					{
						title: "二级返佣",
						slot: "brokerage_two",
						align: "center",
						width: 95,
					},
				],
				member: [{
					title: "会员价",
					slot: "vip_price",
					align: "center",
					width: 95,
				}, ],
				headerCarMy: {
					title: "卡密设置",
					slot: "fictitious",
					align: "center",
					width: 95,
				},
				columnsInstalM: [],
				moveIndex: "",
				goodsData: [],
				brandData: [],
				unitNameList: [],
				formBrand: {},
				attrsList: [],
				activeAtter: [],
				tabIndex: 0,
				tabName: "",
				attrData: [],
				datePickerOptions: {
					disabledDate(date) {
						return date && date.valueOf() < Date.now() - 86400000;
					}
				},
				openErp: false,
				merchantType: 0, //0:平台商品；1:门店商品；2:供应商商品
				formList: [],
				storeColumns: [{
						title: "ID",
						key: "id",
						width: 60,
					},
					{
						title: "门店图片",
						slot: "image",
						minWidth: 80,
					},
					{
						title: "门店分类",
						key: "cate_name",
						minWidth: 80,
					},
					{
						title: "门店名称",
						key: "name",
						minWidth: 80,
					},
					{
						title: "联系电话",
						key: "phone",
						minWidth: 90,
					},
					{
						title: "门店地址",
						key: "address",
						ellipsis: true,
						minWidth: 150,
					},
					{
						title: "营业时间",
						key: "day_time",
						minWidth: 120,
					},
					{
						title: "营业状态",
						key: "status_name",
						minWidth: 80,
					},
					{
						title: "操作",
						slot: "action",
						width: 100,
					}
				],
				// 仓库查询商品列表
				warehouseList: [],
				// 是否载入中
				warehouseListLoding: false
			};
		},
		computed: {
			...mapState("admin/layout", ["isMobile", "menuCollapse"]),
			labelWidth() {
				return this.isMobile ? undefined : 120;
			},
			labelPosition() {
				return this.isMobile ? "top" : "right";
			},
			labelBottom() {
				return this.isMobile ? undefined : 15;
			},
		},
		created() {
			// this.getSupplierList();
			// this.columns = this.columns2.slice(1, 10);
			// let data = JSON.parse(JSON.stringify(this.columns2));
			// data.splice(8, 2, this.headerCarMy);
			// this.columnsCarMy = data;
			// let fictitious = JSON.parse(JSON.stringify(this.columns2));
			// fictitious.splice(8, 2);
			// this.columnsFictitious = fictitious;
			this.getToken();
			this.getErpConfig();
			// this.columnsInstall = this.columns2.slice(0, 4).concat(this.columnsInstall);
			// this.columnsInsta8 = this.columns2.slice(0, 4).concat(this.columnsInsta8);
		},
		watch: {
			formValidate(n, o) {
				console.log(n, 'new');
			}
		},
		mounted() {

			this.goodsCategory();
			// this.productGetRule();
			// this.productGetTemplate();
			this.getBrandList();
			this.getAllUnit();
			// this.uploadType();
			// this.getProductAllEnsure();
			// this.getProductAllSpecs();
			if (this.$route.query.id != 0) {
				this.getGoodInfo(this.$route.query.id)
			}
		},
		destroyed() {
			this.setCopyrightShow({
				value: true
			});
		},
		methods: {
			...mapMutations('admin/layout', [
				'setCopyrightShow'
			]),
			getData() {
				// this.$refs.menusFrom.modals = false
				this.getBrandList()
			},
			getGoodInfo(id) {
				getGoodInfo(id).then(res => {
					let data = res.data
					this.formValidate = {
						product_type: data.product_type,
						cate_id: data.cate_id ? (data.cate_id + '').split(','): [],
						store_name: data.store_name,
						store_info: data.store_info,
						keyword: data.keyword,
						unit_name: data.unit_name,
						recommend_image: data.recommend_image,
						slider_image: data.slider_image ? data.slider_image.split(',') : [],
						sort: data.sort,
						is_show: data.is_show,
						is_dicker: data.is_dicker,
						description: data.description,
						brand_id: data.brand_id ? data.brand_id.split(','): [],
						bar_code: data.bar_code,
						is_vip_product: data.is_vip_product,
						vip_price: data.vip_price,
						is_weigh: data.is_weigh,
						price: data.price,
						cost: data.cost,
						unit_name: data.unit_name,
						unit_name_1: data.unit_name_1,
						unit_name_2: data.unit_name_2,
						unit_rate_1: data.unit_rate_1,
						unit_rate_2: data.unit_rate_2,
						shelf_life: data.shelf_life,
						is_limit: data.is_limit, //是否限购
						limit_type: data.limit_type, //限购类型
						limit_num: data.limit_num, //限购数量
					}
					console.log(this.formValidate, 'formValidate');
				})
			},
			changeForm(e) {
				this.getSystemFormInfo(e, {
					type: 1
				});
			},
			getSystemFormInfo(e, data) {
				systemFormInfo(e, data).then(res => {
					this.formTypeList = res.data.info;
				}).catch(err => {
					this.$Message.error(err.msg);
				})
			},
			//删除门店
			delte(index) {
				this.storesList.splice(index, 1)
			},
			//添加门店
			addStore() {
				this.storeModals = true;
			},
			//关闭门店弹窗
			cancelStore() {
				this.storeModals = false;
			},

			limitTap(e) {
				if (e) {
					this.formValidate.limit_type = (this.formValidate.is_limit && !this.formValidate.limit_type) ? 1 : 0
					this.formValidate.limit_num = (this.formValidate.is_limit && this.formValidate.limit_num == 0) ? 1 : 0
				} else {
					this.formValidate.limit_type = 0;
					this.formValidate.limit_num = 0;
				}
			},
			//erp配置
			getErpConfig() {
				erpConfig().then(res => {
					this.openErp = res.data.open_erp;
				}).catch(err => {
					this.$Message.error(err.msg);
				})
			},
			delSpecs(index) {
				this.specsList.splice(index, 1);
			},
			addSpecs() {
				let obj = {
					'name': '',
					'value': '',
					'sort': 0
				}
				this.specsList.push(obj)
			},
			specsInfo(e) {
				this.specsData.forEach(item => {
					if (item.id == e) {
						this.specsList = item.specs
					}
				})
			},
			getProductAllSpecs() {
				productAllSpecs().then(res => {
					this.specsData = res.data
				}).catch(err => {
					this.$Message.error(err.msg);
				})
			},
			getProductAllEnsure() {
				productAllEnsure().then(res => {
					this.ensureData = res.data
				}).catch(err => {
					this.$Message.error(err.msg);
				})
			},
			seeVirtual(data, name, index) {
				this.tabName = name;
				this.tabIndex = index;
				this.virtualListClear();
				this.$refs.addCarMy.fixedCar = {
					disk_info: '',
					// stock: 0
				}
				if (data.virtual_list && data.virtual_list.length) {
					this.$refs.addCarMy.cartMyType = 2;
					this.virtualList = data.virtual_list;
				} else if (data.disk_info) {
					this.$refs.addCarMy.cartMyType = 1;
					this.$refs.addCarMy.fixedCar.disk_info = data.disk_info;
					// this.$refs.addCarMy.fixedCar.stock = data.stock;
				}
				this.carMyShow = true;
			},
			//动态添加组件
			addAssembly() {
				this.formValidate.custom_form.push({
					title: "",
					label: "text",
					value: "",
					status: 0,
				});
			},
			customMessBtn(e) {
				if (!e) {
					this.formValidate.system_form_id = 0;
				}
			},
			addcustom() {
				if (this.formValidate.custom_form.length > 9) {
					this.$Message.warning("最多添加10条");
				} else {
					this.addAssembly();
				}
			},
			delcustom(index) {
				this.formValidate.custom_form.splice(index, 1);
			},
			doCombination(arr) {
				var count = arr.length - 1; //数组长度(从0开始)
				var tmp = [];
				var totalArr = []; // 总数组

				return doCombinationCallback(arr, 0); //从第一个开始
				//js 没有静态数据，为了避免和外部数据混淆，需要使用闭包的形式
				function doCombinationCallback(arr, curr_index) {
					for (let val of arr[curr_index]) {
						tmp[curr_index] = val; //以curr_index为索引，加入数组
						//当前循环下标小于数组总长度，则需要继续调用方法
						if (curr_index < count) {
							doCombinationCallback(arr, curr_index + 1); //继续调用
						} else {
							totalArr.push(tmp.join(',')); //(直接给push进去，push进去的不是值，而是值的地址)
						}

						//js  对象都是 地址引用(引用关系)，每次都需要重新初始化，否则 totalArr的数据都会是最后一次的 tmp 数据；
						let oldTmp = tmp;
						tmp = [];
						for (let index of oldTmp) {
							tmp.push(index);
						}
					}
					return totalArr;
				}
			},
			goodsOn(e) {
				if (e == 0 || e == 1) {
					this.formValidate.auto_on_time = '';
				}
			},
			goodsOff(e) {
				if (!e) {
					this.formValidate.auto_off_time = '';
				}
			},
			addBrand() {
				this.$refs.menusFrom.modals = true
				this.$refs.menusFrom.titleFrom = "添加品牌分类"
				this.formBrand = {
					sort: 0,
					is_show: 1
				}
				this.formBrand.fid = [0];
				this.$refs.menusFrom.type = 1
			},
			getAllUnit() {
				productAllUnit().then(res => {
					this.unitNameList = res.data;
				}).catch(err => {
					this.$Message.error(err.msg);
				})
			},
			addClass() {
				this.$modalForm(productCreateApi()).then(() => this.goodsCategory());
			},
			addUnit() {
				this.$modalForm(productUnitCreate()).then(() => this.getAllUnit());
			},
			addStoreLabel() {
				this.$modalForm(productLabelAdd()).then(() => {});
			},
			productTypeTap(num, item) {
				if (num == 1) {
					if (this.$route.params.id) return this.$Message.error('商品类型不能切换！');
					this.formValidate.product_type = item.id;
				}
				if (this.formValidate.product_type && this.formValidate.product_type != 4) {
					this.headTab = [{
							title: "基础信息",
							name: "1"
						},
						{
							title: "规格库存",
							name: "2"
						},
						{
							title: "商品详情",
							name: "3"
						},
						{
							title: "营销设置",
							name: "5"
						},
						{
							title: "其他设置",
							name: "6"
						},
					]
					this.formValidate.postage = 0;
					// this.formValidate.supplier_id = 0;
				} else if (this.formValidate.product_type == 4) {
					this.headTab = [{
							title: "基础信息",
							name: "1"
						},
						{
							title: "规格库存",
							name: "2"
						},
						{
							title: "商品详情",
							name: "3"
						},
						{
							title: "营销设置",
							name: "5"
						},
						{
							title: "其他设置",
							name: "6"
						},
						{
							title: "适用门店",
							name: "7"
						},
					]
				} else {
					this.headTab = [{
							title: "基础信息",
							name: "1"
						},
						{
							title: "规格库存",
							name: "2"
						},
						{
							title: "商品详情",
							name: "3"
						},
						{
							title: "物流设置",
							name: "4"
						},
						{
							title: "营销设置",
							name: "5"
						},
						{
							title: "其他设置",
							name: "6"
						},
						{
							title: "适用门店",
							name: "7"
						},
					]
				}
			},
			closeLabel(label) {
				let index = this.dataLabel.indexOf(this.dataLabel.filter(d => d.id == label.id)[0]);
				this.dataLabel.splice(index, 1);
			},
			activeData(dataLabel) {
				this.labelShow = false;
				this.dataLabel = dataLabel;
			},
			openLabel(row) {
				this.labelShow = true;
				this.$refs.userLabel.userLabel(JSON.parse(JSON.stringify(this.dataLabel)));
			},
			// 标签弹窗关闭
			labelClose() {
				this.labelShow = false;
			},
			closeStoreLabel(label) {
				let index = this.storeDataLabel.indexOf(this.storeDataLabel.filter(d => d.id == label.id)[0]);
				this.storeDataLabel.splice(index, 1);
			},
			activeStoreData(storeDataLabel) {
				this.storeLabelShow = false;
				this.storeDataLabel = storeDataLabel;
			},
			openStoreLabel(row) {
				this.storeLabelShow = true;
				this.$refs.storeLabel.storeLabel(JSON.parse(JSON.stringify(this.storeDataLabel)));
			},
			// 标签弹窗关闭
			storeLabelClose() {
				this.storeLabelShow = false;
			},
			// 品牌列表
			getBrandList() {
				brandList().then(res => {
					//initBran()函数作用iview中规定value必须是字符串，后台返回成了数字，用于处理这个，给了个递归；
					this.initBran(res.data);
					this.brandData = res.data
				}).catch(err => {
					this.$Message.error(err.msg);
				})
			},
			initBran(data) {
				data.map(item => {
					item.value = item.value.toString();
					if (item.children && item.children.length) {
						this.initBran(item.children);
					}
				})
			},
			getProductId(e) {
				this.goodsModals = false;
				let nArr = this.goodsData.concat(e).filter((element, index, self) => {
					return self.findIndex(x => x.product_id == element.product_id) == index
				})
				this.goodsData = nArr.slice(0, 12);
			},
			goodCancel() {
				this.goodsModals = false;
			},
			goodsTap() {
				this.goodsModals = true;
				this.$refs.goodslist.handleSelectAll();
			},
			bindDelete(index) {
				this.goodsData.splice(index, 1)
			},
			cancel() {
				this.$router.push({
					path: this.roterPre + '/product/product_list'
				});
			},

			videoSaveToUrl(file) {
				let imgTypeArr = ["video/mp4"];
				let imgType = imgTypeArr.indexOf(file.type) !== -1
				if (!imgType) {
					return this.$Message.warning({
						content: '文件  ' + file.name + '  格式不正确, 请选择格式正确的视频',
						duration: 5
					});
				}
				uploadByPieces({
					randoms: "", // 随机数，这里作为给后端处理分片的标识 根据项目看情况 是否要加
					file: file, // 视频实体
					pieceSize: 3, // 分片大小
					success: (data) => {
						this.formValidate.video_link = data.file_path;
						this.progress = 100;
					},
					error: (e) => {
						this.$Message.error(e.msg);
					},
					uploading: (chunk, allChunk) => {
						this.videoIng = true;
						let st = Math.floor((chunk / allChunk) * 100);
						this.progress = st;
					},
				});
				return false;
			},

			// 上传头部token
			getToken() {
				this.header["Authori-zation"] = "Bearer " + util.cookies.get("token");
			},
			// beforeUpload() {
			//   this.uploadData = {};
			//   let promise = new Promise((resolve) => {
			//     this.$nextTick(function () {
			//       resolve(true);
			//     });
			//   });
			//   return promise;
			// },
			// 上传成功
			handleSuccess(res, file, fileList) {
				if (res.status === 200) {
					this.formValidate.video_link = res.data.src;
					this.$Message.success(res.msg);
				} else {
					this.$Message.error(res.msg);
				}
			},

			getEditorContent(data) {
				this.content = data;
			},



			checkMove(evt) {
				this.moveIndex = evt.draggedContext.index;
			},
			end() {
				this.moveIndex = "";
			},
			checkAllGroupChange(data) {
				this.checkAllGroup(data);
			},
			checkAllGroup(data) {
				if (this.formValidate.spec_type === 0) {
					if (data.indexOf(0) > -1) {
						this.columnsInstall = this.columns2.slice(1, 5).concat(this.member);
					} else if (data.indexOf(1) > -1) {
						this.columnsInstall = this.columns2.slice(1, 5).concat(this.rakeBack);
					} else {
						this.columnsInstall = this.columns2.slice(1, 5);
					}
					if (data.length === 2) {
						this.columnsInstall = this.columns2
							.slice(1, 5)
							.concat(this.rakeBack)
							.concat(this.member);
					}
				} else {
					if (data.indexOf(0) > -1) {
						this.columnsInstal2 = this.columnsInstalM
							.slice(0, 4)
							.concat(this.member);
					} else if (data.indexOf(1) > -1) {
						this.columnsInstal2 = this.columnsInstalM
							.slice(0, 4)
							.concat(this.rakeBack);
					} else {
						this.columnsInstal2 = this.columnsInstalM.slice(0, 4);
					}
					if (data.length === 2) {
						this.columnsInstal2 = this.columnsInstalM
							.slice(0, 4)
							.concat(this.rakeBack)
							.concat(this.member);
					}
				}
			},
			// 添加优惠券
			addCoupon() {
				this.$refs.couponTemplates.isTemplate = true;
				this.$refs.couponTemplates.tableList();
			},
			//对象数组去重；
			unique(arr) {
				const res = new Map();
				return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1));
			},
			nameId(id, names) {
				this.formValidate.coupon_ids = id;
				this.couponName = this.unique(names);
			},
			handleClose(name) {
				let index = this.couponName.indexOf(name);
				this.couponName.splice(index, 1);
				let couponIds = this.formValidate.coupon_ids;
				couponIds.splice(index, 1);
				this.updateIds = couponIds;
				this.updateName = this.couponName;
			},
			getStoreId(data) {
				this.storeModals = false;
				let list = this.storesList.concat(data);
				let uni = this.unique(list);
				this.storesList = uni;
			},
			// 运费模板
			getList() {
				this.productGetTemplate();
			},
			// 添加运费模板
			addTemp() {
				this.$refs.templates.isTemplate = true;
			},
			//查看、编辑运费模板
			editTemp() {
				this.$refs.templates.isTemplate = true;
				this.$refs.templates.editFrom(this.formValidate.temp_id);
			},
			// 删除视频；
			delVideo() {
				let that = this;
				that.$set(that.formValidate, "video_link", "");
				that.$set(that, "progress", 0);
				that.videoIng = false;
				that.upload.videoIng = false;
				that.$refs.refid.value = '';
			},
			zh_uploadFile() {
				if (this.seletVideo == 1) {
					if (this.videoLink && this.$getFileType(this.videoLink) == 'video') {
						this.formValidate.video_link = this.videoLink;
					} else {
						return this.$Message.error("请输入正确的视频链接")
					}
				} else {
					this.$refs.refid.click();
				}
			},
			zh_uploadFile_change(evfile) {
				let that = this;
				let suffix = evfile.target.files[0].name.substr(
					evfile.target.files[0].name.indexOf(".")
				);
				if (suffix.indexOf(".mp4") === -1) {
					return that.$Message.error("只能上传MP4文件");
				}
				productGetTempKeysApi()
					.then((res) => {
						that.$videoCloud
							.videoUpload({
								type: res.data.type,
								evfile: evfile,
								res: res,
								uploading(status, progress) {
									that.upload.videoIng = status;
									if (res.status == 200) {
										that.progress = 100;
									}
								},
							})
							.then((res) => {
								that.formValidate.video_link = res.url;
								that.$Message.success("视频上传成功");
								that.upload.videoIng = false;
							})
							.catch((res) => {
								that.$Message.error(res);
							});
					})
					.catch((res) => {
						that.$Message.error(res.msg);
					});
			},
			// 上一页；
			upTab() {
				if (this.currentTab == 5 && this.formValidate.product_type != 0) {
					this.currentTab = (Number(this.currentTab) - 2).toString();
				} else {
					this.currentTab = (Number(this.currentTab) - 1).toString();
				}
			},
			// 下一页；
			downTab(name) {
				this.$refs[name].validate((valid) => {
					if (valid) {
						if (this.formValidate.is_show == 2 && !this.formValidate.auto_on_time) {
							return this.$Message.warning("请填写定时上架时间");
						}
						if (this.off_show == 1 && !this.formValidate.auto_off_time) {
							return this.$Message.warning("请填写定时下架时间");
						}
						if (this.currentTab == 4 && !this.formValidate.delivery_type.length) {
							return this.$Message.warning("请选择配送方式");
						}
						if (this.currentTab == 3 && this.formValidate.product_type != 0) {
							this.currentTab = (Number(this.currentTab) + 2).toString();
						} else {
							this.currentTab = (Number(this.currentTab) + 1).toString();
						}
					} else {
						this.$Message.warning("请完善数据");
					}
				})
			},
			// 属性弹窗回调函数；
			userSearchs() {
				this.productGetRule();
			},
			userSearchss(e) {
				console.log(e);
				this.formValidate.cate_id = e
			},
			// 添加规则；
			addRule() {
				this.$refs.addattr.modal = true;
			},
			// 批量设置分佣；
			brokerageSetUp() {
				let that = this;
				if (that.formValidate.is_sub.indexOf(1) > -1) {
					if (that.manyBrokerage <= 0 || that.manyBrokerageTwo <= 0) {
						return that.$Message.error("请填写返佣金额后进行批量添加");
					}
				} else if (that.formValidate.is_sub.indexOf(0) > -1) {
					if (that.manyVipPrice <= 0) {
						return that.$Message.error("请填写会员价后进行批量添加");
					}
				}
				if (this.formValidate.is_sub.length === 2) {
					if (
						that.manyBrokerage <= 0 ||
						that.manyBrokerageTwo <= 0 ||
						that.manyVipPrice <= 0
					) {
						return that.$Message.error("请填写完金额后进行批量添加");
					}
				}
				for (let val of that.manyFormValidate) {
					this.$set(val, "brokerage", that.manyBrokerage);
					this.$set(val, "brokerage_two", that.manyBrokerageTwo);
					this.$set(val, "vip_price", that.manyVipPrice);
				}
				// let that = this;
				// if (that.manyBrokerage <= 0 || that.manyBrokerageTwo <= 0) {
				//     return that.$Message.error('请填写返佣金额在进行批量添加');
				// } else {
				//     for (let val of that.manyFormValidate) {
				//         this.$set(val, 'brokerage', that.manyBrokerage);
				//         this.$set(val, 'brokerage_two', that.manyBrokerageTwo);
				//     }
				// }
			},
			// 批量设置会员价
			vipPriceSetUp() {
				let that = this;
				if (that.manyVipPrice <= 0) {
					return that.$Message.error("请填写会员价在进行批量添加");
				} else {
					for (let val of that.manyFormValidate) {
						this.$set(val, "vip_price", that.manyVipPrice);
					}
				}
			},
			batchDel() {
				this.oneFormBatch = [{
					attr: "全部",
					pic: "",
					price: 0,
					settle_price: 0,
					cost: 0,
					ot_price: 0,
					erp_product_id: 0,
					unit: '',
					uint_to_erp_unit: 0,
					// stock: 0,
					bar_code: "",
					code: "",
					weight: 0,
					volume: 0,
					virtualList: [],
					disk_info: ''
				}, ];
				this.activeAtter = [];
				for (let val of this.manyFormValidate) {
					val.select = true;
				}
			},
			confirm() {
				let that = this;
				that.createBnt = true;
				if (that.formValidate.selectRule.trim().length <= 0) {
					return that.$Message.error("请选择属性");
				}
				that.ruleList.forEach(function(item, index) {
					if (item.rule_name === that.formValidate.selectRule) {
						that.attrs = item.rule_value;
					}
				});
			},
			// 获取商品属性模板；
			productGetRule() {
				productGetRuleApi().then((res) => {
					this.ruleList = res.data;
				});
			},
			// 获取运费模板；
			productGetTemplate() {
				let id = this.$route.params.id;
				productGetTemplateApi({
					id: id
				}).then((res) => {
					this.templateList = res.data;
				});
			},
			// 删除表格中的属性
			delAttrTable(index) {
				let id = this.$route.params.id;
				if (id) {
					checkActivityApi(id)
						.then((res) => {
							this.manyFormValidate.splice(index, 1);
							this.$Message.success(res.msg);
						})
						.catch((res) => {
							this.$Message.error(res.msg);
						});
				} else {
					this.manyFormValidate.splice(index, 1);
				}
			},
			// 批量添加
			batchAdd() {
				for (let val of this.manyFormValidate) {
					//this.manyEmpty(val);
					if (val.select) {
						if (this.oneFormBatch[0].pic) {
							this.$set(val, "pic", this.oneFormBatch[0].pic);
						}
						if (this.oneFormBatch[0].price > 0) {
							this.$set(val, "price", this.oneFormBatch[0].price);
						}
						if (this.oneFormBatch[0].settle_price > 0 && this.merchantType == 2) {
							this.$set(val, "settle_price", this.oneFormBatch[0].settle_price);
						}
						if (this.oneFormBatch[0].cost > 0) {
							this.$set(val, "cost", this.oneFormBatch[0].cost);
						}
						if (this.oneFormBatch[0].ot_price > 0) {
							this.$set(val, "ot_price", this.oneFormBatch[0].ot_price);
						}
						if (this.oneFormBatch[0].erp_product_id > 0) {
							this.$set(val, "erp_product_id", this.oneFormBatch[0].erp_product_id);
						}
						if (this.oneFormBatch[0].unit) {
							this.$set(val, "unit", this.oneFormBatch[0].unit);
						}
						if (this.oneFormBatch[0].uint_to_erp_unit > 0) {
							this.$set(val, "uint_to_erp_unit", this.oneFormBatch[0].uint_to_erp_unit);
						}
						// if (this.oneFormBatch[0].stock > 0) {
						// 	this.$set(val, "stock", this.oneFormBatch[0].stock);
						// }
						if (this.oneFormBatch[0].bar_code !== "") {
							this.$set(val, "bar_code", this.oneFormBatch[0].bar_code);
						}
						if (this.oneFormBatch[0].code !== "") {
							this.$set(val, "code", this.oneFormBatch[0].code);
						}
						if (this.oneFormBatch[0].weight > 0) {
							this.$set(val, "weight", this.oneFormBatch[0].weight);
						}
						if (this.oneFormBatch[0].volume > 0) {
							this.$set(val, "volume", this.oneFormBatch[0].volume);
						}
						if (this.formValidate.product_type == 1) {
							if (this.oneFormBatch[0].virtual_list && this.oneFormBatch[0].virtual_list.length) {
								this.$set(val, "virtual_list", this.oneFormBatch[0].virtual_list);
							} else if (this.oneFormBatch[0].disk_info) {
								this.$refs.addCarMy.cartMyType = 1;
								this.$set(val, "disk_info", this.oneFormBatch[0].disk_info);
							}
						}
					}
				}
			},
			// 添加按钮
			addBtn() {
				let id = this.$route.params.id;
				checkActivityApi(id)
					.then((res) => {
						this.clearAttr();
						this.createBnt = false;
						this.showIput = true;
					})
					.catch((res) => {
						this.$Message.error(res.msg);
					});
			},
			addmanyData(data, type) {
				if (type == 1) {
					this.oneFormBatch[0].pic = this.formValidate.image
					data.forEach(item => {
						item.select = true,
							item.pic = this.formValidate.image
					})
				} else {
					data.forEach(item => {
						item.select = true
					})
				}
				this.manyFormValidate = data;
			},
			// 立即生成
			generate(type) {
				generateAttrApi({
						attrs: this.attrs,
						product_type: this.formValidate.product_type
					}, this.formValidate.id, type)
					.then((res) => {
						let info = res.data.info,
							header1 = JSON.parse(JSON.stringify(info.header));
						if ((this.$route.params.id !== "0" && this.type != -1) || type == 1) {
							this.addmanyData(info.value, type);
						}
						this.formValidate.header = header1;
						this.attrData = res.data.info.attr;
						let header = info.header;
						header.pop();
						this.columnsInstalM = info.header;
						this.checkAllGroup(this.formValidate.is_sub);
						if (!this.$route.params.id && this.formValidate.spec_type === 1 && this.type != -1) {
							this.manyFormValidate.map((item) => {
								item.pic = this.formValidate.slider_image[0];
							});
							this.oneFormBatch[0].pic = this.formValidate.slider_image[0];
						} else if (this.$route.params.id) {
							this.manyFormValidate.map((item) => {
								if (!item.pic) {
									item.pic = this.formValidate.slider_image[0];
								}
							});
							this.oneFormBatch[0].pic = this.formValidate.slider_image[0];
						}
						this.getAttr();
					})
					.catch((res) => {
						this.$Message.error(res.msg);
					});
			},
			// 取消
			offAttrName() {
				this.showIput = false;
				this.createBnt = true;
			},
			clearAttr() {
				this.formDynamic.attrsName = "";
				this.formDynamic.attrsVal = "";
			},
			// 添加规则名称
			createAttrName() {
				if (this.formDynamic.attrsName && this.formDynamic.attrsVal) {
					let data = {
						value: this.formDynamic.attrsName,
						detail: [this.formDynamic.attrsVal],
					};
					this.attrs.push(data);
					var hash = {};
					this.attrs = this.attrs.reduce(function(item, next) {
						/* eslint-disable */
						hash[next.value] ? "" : (hash[next.value] = true && item.push(next));
						return item;
					}, []);
					this.clearAttr();
					this.showIput = false;
					this.createBnt = true;
				} else {
					this.$Message.warning("请添加完整的规格！");
				}
			},
			// 添加属性
			createAttr(num, idx) {
				if (num) {
					this.attrs[idx].detail.push(num);
					var hash = {};
					this.attrs[idx].detail = this.attrs[idx].detail.reduce(function(
							item,
							next
						) {
							/* eslint-disable */
							hash[next] ? "" : (hash[next] = true && item.push(next));
							return item;
						},
						[]);
				} else {
					this.$Message.warning("请添加属性");
				}
			},
			// 商品分类；
			goodsCategory() {
				cascaderListApi(1)
					.then((res) => {
						this.treeSelect = res.data;
					})
					.catch((res) => {
						this.$Message.error(res.msg);
					});
			},
			//视视上传类型
			changeVideo(e) {
				this.formValidate.video_link = "";
				this.videoLink = "";
			},
			// 改变规格
			changeSpec() {
				this.formValidate.is_sub = [];
				let id = this.$route.params.id;
				if (id) {
					checkActivityApi(id)
						.then((res) => {})
						.catch((res) => {
							this.formValidate.spec_type = this.spec_type;
							this.$Message.error(res.msg);
						});
				}
			},
			// 详情
			getInfo() {
				let that = this;
				that.spinShow = true;
				productInfoApi(that.$route.params.id || this.$route.query.copy)
					.then(async (res) => {
						let data = res.data.productInfo;
						this.merchantType = parseInt(data.type);
						if (this.merchantType == 2) {
							let obj = {
								title: "结算价",
								slot: "settle_price",
								align: "center",
								minWidth: 95,
							}
							this.columns2.splice(3, 0, obj)
						}
						this.infoData(data);
						this.spinShow = false;
					})
					.catch((res) => {
						this.spinShow = false;
						this.$Message.error(res.msg);
					});
			},
			// tab切换
			onhangeTab(name) {
				this.currentTab = name;
			},
			handleRemove(i) {
				this.images.splice(i, 1);
				this.formValidate.slider_image.splice(i, 1);
				this.oneFormValidate[0].pic = this.formValidate.slider_image[0];
			},
			// 关闭图片上传模态框
			changeCancel(msg) {
				this.modalPic = false;
			},
			// 点击商品图
			modalPicTap(tit, picTit, index) {
				this.modalPic = true;
				this.isChoice = tit === "dan" ? "单选" : "多选";
				this.picTit = picTit;
				this.tableIndex = index;
			},
			// 获取单张图片信息
			getPic(pc) {
				switch (this.picTit) {
					case "danFrom":
						this.formValidate.image = pc.att_dir;
						if (!this.$route.params.id) {
							if (this.formValidate.spec_type === 0) {
								this.oneFormValidate[0].pic = pc.att_dir;
							} else {
								this.manyFormValidate.map((item) => {
									item.pic = pc.att_dir;
								});
								this.oneFormBatch[0].pic = pc.att_dir;
							}
						}
						break;
					case "danTable":
						this.oneFormValidate[this.tableIndex].pic = pc.att_dir;
						break;
					case "duopi":
						this.oneFormBatch[this.tableIndex].pic = pc.att_dir;
						break;
					case "recommend_image":
						this.formValidate.recommend_image = pc.att_dir;
						break;
					case "video":
						this.formValidate.video_link = pc.att_dir;
						break;
					default:
						this.manyFormValidate[this.tableIndex].pic = pc.att_dir;
				}
				this.modalPic = false;
			},
			// 获取多张图信息
			getPicD(pc) {
				this.images = pc;
				this.images.map((item) => {
					this.formValidate.slider_image.push(item.att_dir);
					this.formValidate.slider_image = this.formValidate.slider_image.splice(
						0,
						10
					);
				});
				// this.oneFormValidate[0].pic = this.formValidate.slider_image[0];
				this.modalPic = false;
			},
			// 提交
			handleSubmit(name) {
				this.$refs[name].validate((valid) => {
					if (valid) {
						if (!this.formValidate.store_name.trim()) {
							return this.$Message.warning("商品名称不能为空");
						}
						this.formValidate.id = this.$route.query.id
						console.log(this.formValidate);
						let pdata = JSON.parse(JSON.stringify(this.formValidate))
						try{
							pdata.cate_id = this.formValidate.cate_id.join(',')
							pdata.brand_id = this.formValidate.brand_id.length > 0 ? this.formValidate.brand_id.join(','): ""
							pdata.slider_image = this.formValidate.slider_image.join(',')
						}catch(e){
							//TODO handle the exception
							console.log(e,'err');
						}
						
						console.log('formValidate', pdata);
						addProduct(pdata.id, pdata)
							.then(async (res) => {
								this.openSubimit = true;
								this.$Message.success(res.msg);
								setTimeout(() => {
									this.$router.push({
										path: this.roterPre + "/erp/product"
									});
								}, 500);
							})
							.catch((res) => {
								this.openSubimit = false;
								this.$Message.error(res.msg);
							});
					} else {
						// if (!this.formValidate.store_name) {
						// 	return this.$Message.warning("基础信息-商品名称不能为空");
						// } else if (!this.formValidate.cate_id.length) {
						// 	return this.$Message.warning("基础信息-商品分类不能为空");
						// } else if (!this.formValidate.unit_name) {
						// 	return this.$Message.warning("基础信息-商品单位不能为空");
						// } else if (!this.formValidate.slider_image.length) {
						// 	return this.$Message.warning("基础信息-商品轮播图不能为空");
						// }
						//    if(!this.formValidate.store_name || !this.formValidate.cate_id || !this.formValidate.keyword
						//    || !this.formValidate.unit_name || !this.formValidate.store_info
						//        || !this.formValidate.image || !this.formValidate.slider_image){
						//        this.$Message.warning("请填写完整商品信息！");
						//    }
					}
				});
			},
			changeTemplate(msg) {
				this.template = msg;
			},
			// 表单验证
			validate(prop, status, error) {
				if (status === false) {
					this.$Message.warning(error);
				}
			},
			// 移动
			handleDragStart(e, item) {
				this.dragging = item;
			},
			handleDragEnd(e, item) {
				this.dragging = null;
			},
			handleDragOver(e) {
				e.dataTransfer.dropEffect = "move";
			},
			handleDragEnter(e, item) {
				e.dataTransfer.effectAllowed = "move";
				if (item === this.dragging) {
					return;
				}
				const newItems = [...this.formValidate.slider_image];
				const src = newItems.indexOf(this.dragging);
				const dst = newItems.indexOf(item);
				newItems.splice(dst, 0, ...newItems.splice(src, 1));
				this.formValidate.slider_image = newItems;
			},


		},
	};
</script>
<style scoped lang="stylus">
	.storeTable img {
		width 36px;
		height 36px;
	}

	.storeTable /deep/.ivu-table-wrapper {
		border: 0 !important
	}

	.radioGroup .ivu-radio-wrapper {
		margin-right 20px;
	}

	.video-style {
		width: 100%;
		height: 100% !important;
		border-radius: 10px;
	}

	.select-add {
		width: 200px;
		margin-left: 6px;
		margin-right: 10px
	}

	.input-display {
		display: none
	}

	.width-add {
		width: 200px;
	}

	.custom-input {
		width: 100px;
		margin-right: 10px
	}

	.asterisk {
		position relative;

		.asteriskInfo {
			position absolute;
			color #ed4014;
			left 73px;
			top 8px;

			&.on {
				left: 62px;
			}

			&.on2 {
				left: 50px;
			}
		}
	}

	.specsList {
		/deep/.ivu-table-header table {
			border: 0 !important
		}

		/deep/.ivu-table-header thead tr th {
			padding 0 !important background-color #EEEEEE !important;
		}

		/deep/.ivu-table-cell {
			padding 0 !important
		}

		/deep/.ivu-table-border th,
		/deep/.ivu-table-border td {
			border-right unset;
		}

		/deep/.ivu-table td {
			height 59px;
		}

		&.on {
			width 50% !important;

			/deep/.ivu-table {
				width 100% !important;
			}

			/deep/.ivu-table td {
				height 40px;
				padding 0 !important;
			}

			/deep/.ivu-table-cell {
				padding 0 16px !important;
			}
		}
	}

	.form-submit {
		/deep/.ivu-card {
			border-radius: 0;
		}

		margin-bottom: 79px;

		.fixed-card {
			position: fixed;
			right: 0;
			bottom: 0;
			left: 200px;
			z-index: 45;
			box-shadow: 0 -1px 2px rgb(240, 240, 240);

			/deep/ .ivu-card-body {
				padding: 15px 16px 14px;
			}

			.ivu-form-item {
				margin-bottom: 0;
			}

			/deep/ .ivu-form-item-content {
				margin-right: 124px;
				text-align: center;
			}

			.ivu-btn {
				height: 36px;
				padding: 0 20px;
			}
		}
	}

	.seeCatMy {
		color: #2d8cf0;
		cursor: pointer;
	}

	.addCustom_content {
		margin-top: 20px;

		.custom_box {
			margin-bottom: 10px;
		}

		.addfont {
			display: inline-block;
			font-size: 13px;
			font-weight: 400;
			color: #1890FF;
			cursor: pointer;
		}
	}

	.addCustomBox {
		margin-top: 12px;
		font-size: 13px;
		font-weight: 400;
		color: #1890FF;

		.btn {
			cursor: pointer;
			width: max-content;
		}
	}

	.checkAlls /deep/.ivu-checkbox-inner {
		width 14px;
		height 14px;
	}

	.checkAlls /deep/.ivu-checkbox-wrapper {
		font-size 12px;
	}

	.lines {
		border-bottom: 1px dashed #eee;
		margin-bottom: 20px;
	}

	.iosfont {
		font-size 20px !important;
	}

	.selectOn {
		color #2d8cf0;
	}

	.ifam {
		width: 344px;
		height: 644px;
		background: url('../../../assets/images/phonebg.png') no-repeat center top;
		background-size: 344px 644px;
		padding: 40px 20px;
		padding-top: 50px;
		margin: 0 auto 0 20px;

		.content {
			height: 560px;
			overflow: hidden;
			scrollbar-width: none;
			/* firefox */
			-ms-overflow-style: none;
			/* IE 10+ */
			overflow-x: hidden;
			overflow-y: auto;
		}

		.content::-webkit-scrollbar {
			display: none;
			/* Chrome Safari */
		}
	}

	.offShow {
		position absolute
	}

	.goodsShow /deep/.ivu-radio-group-vertical .ivu-radio-wrapper {
		height 35px;
		line-height 35px;
	}

	.videbox {
		width: 60px;
		height: 60px;
		background: rgba(0, 0, 0, 0.02);
		border-radius: 4px;
		border: 1px dashed #DDDDDD;
		line-height: 50px;
		text-align: center;
		color: #898989;
		font-size: 30px;
		font-weight: 400;
		cursor: pointer;
	}

	.brandName {
		/deep/.ivu-cascader {
			display inline-block
		}
	}

	.formValidate {
		.addClass {
			color: #1890FF;
			margin-left 14px;
			padding 9px 0;
			cursor pointer;
		}
	}

	.productType {
		width: 120px;
		height: 45px;
		background: #FFFFFF;
		border-radius: 3px;
		border: 1px solid #E7E7E7;
		float: left;
		text-align: center;
		padding-top: 8px;
		position: relative;
		cursor: pointer;
		line-height: 23px;
		margin-right 12px;

		&.on {
			border-color #1890FF;
		}

		.name {
			font-size: 14px;
			font-weight: 600;
			color: rgba(0, 0, 0, 0.85);
		}

		.title {
			font-size: 12px;
			font-weight: 400;
			color: #999999;
		}

		.jiao {
			position: absolute;
			bottom: 0;
			right: 0;
			width: 0;
			height: 0;
			border-bottom: 26px solid #1890FF;
			border-left: 26px solid transparent;
		}

		.iconfont {
			position: absolute;
			bottom: -3px;
			right: 1px;
			color: #FFFFFF;
			font-size 12px;
		}

	}

	.labelInput {
		border: 1px solid #dcdee2;
		width 50%;
		padding 0 5px;
		border-radius 5px;
		min-height 30px;
		cursor pointer;

		.span {
			color: #c5c8ce;
		}

		.iconxiayi {
			font-size 12px
		}
	}

	.labelClass {
		/deep/.ivu-form-item-content {
			line-height unset;
		}
	}

	.ivu-checkbox-wrapper {
		margin-right 19px;
	}

	.list-group {
		margin-left: -8px;
	}

	.borderStyle {
		border: 1px solid #ccc;
		padding: 8px;
		border-radius: 4px;
	}

	.drag {
		cursor: move;
	}

	.move-icon {
		width: 30px;
		cursor: move;
		margin-right: 10px;
	}

	.move-icon .icondrag2 {
		font-size: 26px;
		color: #d8d8d8;
	}

	.maxW /deep/.ivu-select-dropdown {
		max-width: 600px;
	}

	#shopp-manager .ivu-table-wrapper {
		border-left: 1px solid #dcdee2;
		border-top: 1px solid #dcdee2;
	}

	.noLeft {
		>>>.ivu-form-item-content {
			margin-left: 0 !important;
		}
	}

	.tips {
		display: inline-bolck;
		font-size: 12px;
		font-weight: 400;
		color: #999999;
		margin-top: 6px;
	}

	.iview-video-style {
		width: 40%;
		height: 180px;
		border-radius: 10px;
		background-color: #707070;
		margin-top: 10px;
		position: relative;
		overflow: hidden;
	}

	.iview-video-style .iconv {
		color: #fff;
		line-height: 180px;
		width: 50px;
		height: 50px;
		display: inherit;
		font-size: 26px;
		position: absolute;
		top: -74px;
		left: 50%;
		margin-left: -25px;
	}

	.iview-video-style .mark {
		position: absolute;
		width: 100%;
		height: 30px;
		top: 0;
		background-color: rgba(0, 0, 0, 0.5);
		text-align: center;
	}

	.uploadVideo {
		margin-left: 10px;
	}

	.submission {
		margin-left: 10px;
	}

	.form-submit .fixed-card .ivu-btn {
		height: 32px;
	}

	.color-list .tip {
		color: #c9c9c9;
	}

	.color-list .color-item {
		width 70px;
		height: 28px;
		line-height: 28px;
		color: #fff;
		margin-right: 10px;
		border-radius 2px;

		text-align center .num {
			color #1890FF;
			width 14px;
			height 14px;
			text-align center;
			line-height 14px;
			border-radius 50%;
			background-color #fff;
			margin-right 6px;
		}
	}

	.color-list .color-item.blue {
		background-color: #1E9FFF;
	}

	.color-list .color-item.yellow {
		background-color: rgb(254, 185, 0);
	}

	.color-list .color-item.green {
		background-color: #009688;
	}

	.color-list .color-item.red {
		background-color: #ed4014;
	}

	.color-list .color-item.colorBlue {
		background: linear-gradient(270deg, #5ECFFF 0%, #0084FF 100%);
	}

	.columnsBox {
		margin-right: 10px;
	}

	.priceBox {
		width: 100%;
	}

	.rulesBox {
		display: flex;
		flex-wrap: wrap;
	}

	.pictrueBox {
		display: inline-block;
	}

	.pictrueTab {
		width: 40px !important;
		height: 40px !important;
	}

	.pictrue {
		width: 60px;
		height: 60px;
		border: 1px dotted rgba(0, 0, 0, 0.1);
		margin-right: 15px;
		margin-bottom 10px;
		display: inline-block;
		position: relative;
		cursor: pointer;

		img {
			width: 100%;
			height: 100%;
		}

		.btndel {
			position: absolute;
			z-index: 1;
			width: 20px !important;
			height: 20px !important;
			left: 46px;
			top: -4px;
		}
	}

	.upLoad {
		width: 58px;
		height: 58px;
		line-height: 58px;
		border: 1px dotted rgba(0, 0, 0, 0.1);
		border-radius: 4px;
		background: rgba(0, 0, 0, 0.02);
		cursor: pointer;
	}

	.curs {
		cursor: pointer;
	}

	.inpWith {
		width: 60%;
	}

	.labeltop {
		>>>.ivu-form-item-label {
			float: none !important;
			display: inline-block !important;
			margin-left: 120px !important;
			width: auto !important;
		}

		.icondrop-down {
			font-size: 12px;
			margin-left: 5px;
		}
	}

	.video-icon {
		background-image: url('https://cdn.oss.9gt.net/prov1.1/1/icons.png'); // cdn.oss.9gt.net/prov1.1/1/icons.png);
		// background-color: #fff;
		background-position: -9999px;
		background-repeat: no-repeat;
	}

	.progress {
		margin-top: 10px;
	}

	.new_tab {
		>>>.ivu-tabs-nav .ivu-tabs-tab {
			padding: 4px 16px 20px !important;
			font-weight: 500;
		}
	}
</style>
<!-- product_type', 0],//商品类型
    cate_id', []],
    store_name', ''],
    store_info', ''],
    keyword', ''],
    unit_name', '件'],
    recommend_image', ''],
    slider_image', []],
    sort', 0],
    is_show', 0],
    is_dicker', 1],
    description', ''],
    brand_id', []],
    bar_code', ''],
    is_vip_product', 0],//是否付费会员商品
    vip_price', 0],
    is_weigh', 0],//是否称重
    price', 0],
    cost', 0],
    unit_name', ''],
    unit_name_1', ''],
    unit_name_2', ''],
    unit_rate_1', 1],
    unit_rate_2', 10],
    shelf_life', -1],
    is_limit', 0],//是否限购
    limit_type', 0],//限购类型
    limit_num', 0],//限购数量 -->