|
@@ -1,372 +1,192 @@
|
|
|
-const Radio = createnRadio();
|
|
|
-const Select = createSelect();
|
|
|
-const Option = createOption();
|
|
|
-const UploadImage = createUploadImage();
|
|
|
-const Editor = createEditorComponent();
|
|
|
-const InputGroup = createInputGroup();
|
|
|
-const QuestionGroup = createQuestionGroup();
|
|
|
-
|
|
|
-new Vue({
|
|
|
- el: '#productEdit',
|
|
|
- mixins: [validFormMixin],
|
|
|
+const Editor = window.createEditorComponent()
|
|
|
+
|
|
|
+const app = new Vue({
|
|
|
components: {
|
|
|
- 'cm-radio': Radio,
|
|
|
- 'cm-select': Select,
|
|
|
- 'cm-option': Option,
|
|
|
- 'cm-upload-image': UploadImage,
|
|
|
- 'cm-editor': Editor,
|
|
|
- 'cm-input-group': InputGroup,
|
|
|
- 'cm-question-group': QuestionGroup
|
|
|
+ Editor,
|
|
|
},
|
|
|
- data: {
|
|
|
- // 商品类型 1: 产品 2: 仪器
|
|
|
- productId: 0,
|
|
|
- commodityType: 2,
|
|
|
- shopId: GLOBAL_SHOP_ID,
|
|
|
- formData: {
|
|
|
- // 产品名称
|
|
|
- name: '',
|
|
|
- // 产品别名
|
|
|
- alias: '',
|
|
|
- // 产品概述
|
|
|
- discription: '',
|
|
|
- // 产品图片
|
|
|
- image: '',
|
|
|
- // 认证链接
|
|
|
- authLink: '',
|
|
|
- // 认证二维码
|
|
|
- authQrCode: '',
|
|
|
- // 产品参数
|
|
|
- paramList: [],
|
|
|
- // 产品优点
|
|
|
- advantage: '',
|
|
|
- // 产品缺点
|
|
|
- disadvantage: '',
|
|
|
- // 产品原理
|
|
|
- principle: '',
|
|
|
- // 品牌
|
|
|
- brand: '',
|
|
|
- // 产地
|
|
|
- producePlace: '',
|
|
|
- // 上市时间
|
|
|
- marketTime: '',
|
|
|
- // 公司/厂商
|
|
|
- company: '',
|
|
|
- // NMPA认证时间
|
|
|
- nmpaTime: '',
|
|
|
- // 产品认证
|
|
|
+
|
|
|
+ data() {
|
|
|
+ var validateQuestionList = (rule, value, callback) => {
|
|
|
+ if (!value) {
|
|
|
+ callback(new Error('问答列表不能为空'))
|
|
|
+ } else if (value < this.minLimitQuestions) {
|
|
|
+ callback(new Error(`请填写至少${this.minLimitQuestions}条问答`))
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var validateParamList = (rule, value, callback) => {
|
|
|
+ if (!value) {
|
|
|
+ callback(new Error('参数列表不能为空'))
|
|
|
+ } else if (value < this.minLimitParams) {
|
|
|
+ callback(new Error(`请填写至少${this.minLimitParams}条参数`))
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+
|
|
|
+ productId: 0,
|
|
|
+ commodityType: 2, // 商品类型 1: 产品 2: 仪器
|
|
|
+ shopId: GLOBAL_SHOP_ID,
|
|
|
+
|
|
|
+ action: $('#coreServer').val() + '/tools/image/upload/multi',
|
|
|
+
|
|
|
+ formData: {
|
|
|
+ // 仪器名称
|
|
|
+ name: '',
|
|
|
+ // 仪器别名
|
|
|
+ alias: '',
|
|
|
+ // 仪器概述
|
|
|
+ discription: '',
|
|
|
+ // 仪器图片
|
|
|
+ image: '',
|
|
|
+ // 认证链接
|
|
|
+ authLink: '',
|
|
|
+ // 认证二维码
|
|
|
+ authQrCode: '',
|
|
|
+ // 仪器参数
|
|
|
+ paramList: '',
|
|
|
+ // 仪器优点
|
|
|
+ advantage: '',
|
|
|
+ // 仪器缺点
|
|
|
+ disadvantage: '',
|
|
|
+ // 仪器原理
|
|
|
+ principle: '',
|
|
|
+ // 品牌
|
|
|
+ brand: '',
|
|
|
+ // 产地
|
|
|
+ producePlace: '',
|
|
|
+ // 上市时间
|
|
|
+ marketTime: '',
|
|
|
+ // 公司/厂商
|
|
|
+ company: '',
|
|
|
+ // NMPA认证时间
|
|
|
+ nmpaTime: '',
|
|
|
+ // 仪器认证
|
|
|
+ authImageList: '',
|
|
|
+ // 适应人群
|
|
|
+ adaptiveMan: '',
|
|
|
+ // 不适应人群
|
|
|
+ unAdaptiveMan: '',
|
|
|
+ // 术前术后
|
|
|
+ aroundOperation: '',
|
|
|
+ // 效果展示图片列表
|
|
|
+ displayImageList: '',
|
|
|
+ // 常见问题
|
|
|
+ questionList: '',
|
|
|
+ // 仪器类别
|
|
|
+ typeId: '',
|
|
|
+ // 仪器状态
|
|
|
+ status: 1,
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ // 仪器名称
|
|
|
+ name: [{required: true, message: '仪器名称不能为空', trigger: ['change', 'blur']}],
|
|
|
+ // 仪器别名
|
|
|
+ alias: [{required: true, message: '仪器别名不能为空', trigger: ['change', 'blur']}],
|
|
|
+ // 仪器概述
|
|
|
+ discription: [{required: true, message: '仪器概述不能为空', trigger: ['change', 'blur']}],
|
|
|
+ // 仪器图片
|
|
|
+ image: [{required: true, message: '请上传仪器图片', trigger: 'change'}],
|
|
|
+ // 认证链接
|
|
|
+ authLink: [{required: true, message: '请输入认证链接', trigger: ['change', 'blur']}],
|
|
|
+ // 认证二维码
|
|
|
+ authQrCode: [{required: true, message: '请上传证二维码', trigger: 'change'}],
|
|
|
+ // 产仪器参数
|
|
|
+ paramList: [{required: true, validator: validateParamList, trigger: 'change'}],
|
|
|
+ // 仪器优点
|
|
|
+ advantage: [{required: true, message: '仪器优点不能为空', trigger: 'change'}],
|
|
|
+ // 仪器缺点
|
|
|
+ disadvantage: [{required: true, message: '仪器缺点不能为空', trigger: 'change'}],
|
|
|
+ // 仪器原理
|
|
|
+ principle: [{required: true, message: '仪器原理不能为空', trigger: 'change'}],
|
|
|
+ // 品牌
|
|
|
+ brand: [{required: true, message: '请输入仪器品牌', trigger: ['change', 'blur']}],
|
|
|
+ // 产地
|
|
|
+ producePlace: [{required: true, message: '仪器产地不能为空', trigger: ['change', 'blur']}],
|
|
|
+ // 上市时间
|
|
|
+ marketTime: [{required: true, message: '请填写上市时间', trigger: 'change'}],
|
|
|
+ // 公司/厂商
|
|
|
+ company: [{required: true, message: '公司/厂商不能为空', trigger: ['change', 'blur']}],
|
|
|
+ // NMPA认证时间
|
|
|
+ nmpaTime: [{required: true, message: '请填写NMPA认证时间', trigger: 'change'}],
|
|
|
+ // 仪器认证
|
|
|
+ authImageList: [{required: true, message: '请上传仪器认证图片', trigger: 'change'}],
|
|
|
+ // 适应人群
|
|
|
+ adaptiveMan: [{required: true, message: '适应人群不能为空', trigger: 'change'}],
|
|
|
+ // 不适应人群
|
|
|
+ unAdaptiveMan: [{required: true, message: '不适应人群不能为空', trigger: 'change'}],
|
|
|
+ // 术前术后
|
|
|
+ aroundOperation: [{required: true, message: '术前术后不能为空', trigger: 'change'}],
|
|
|
+ // 效果展示图片列表
|
|
|
+ displayImageList: [{required: true, message: '请上传效果展示图片', trigger: 'change'}],
|
|
|
+ // 常见问题
|
|
|
+ questionList: [{required: true, validator: validateQuestionList, trigger: 'change'}],
|
|
|
+ // 仪器类别
|
|
|
+ typeId: [{required: true, message: '请选择仪器类别', trigger: 'change'}],
|
|
|
+ // 仪器状态
|
|
|
+ status: [{required: true, message: '请选择仪器状态', trigger: 'change'}],
|
|
|
+ },
|
|
|
+
|
|
|
+ // 仪器类别列表
|
|
|
+ typeList: [],
|
|
|
+
|
|
|
+ // 仪器参数
|
|
|
+ // paramList: [],
|
|
|
+ paramEmptyList: [], // 占位
|
|
|
+ minLimitParams: 2,
|
|
|
+ // 常见问题
|
|
|
+ questionEmptyList: [], // 占位
|
|
|
+ minLimitQuestions: 2,
|
|
|
+ // 仪器认证
|
|
|
authImageList: [],
|
|
|
- // 适应人群
|
|
|
- adaptiveMan: '',
|
|
|
- // 不适应人群
|
|
|
- unAdaptiveMan: '',
|
|
|
- // 术前术后
|
|
|
- aroundOperation: '',
|
|
|
// 效果展示图片列表
|
|
|
- displayImageList: [],
|
|
|
- // 常见问题
|
|
|
- questionList: [],
|
|
|
- // 产品类别
|
|
|
- typeId: '',
|
|
|
- // 产品状态
|
|
|
- status: 1,
|
|
|
- },
|
|
|
- // 预览图片列表
|
|
|
- imageList: [],
|
|
|
- authImageList: [],
|
|
|
- displayImageList: [],
|
|
|
- authQrCodeList: [],
|
|
|
- // 产品分类
|
|
|
- typeList: [],
|
|
|
-
|
|
|
- // 产品参数表单数据
|
|
|
- paramsPlaceholderList: [{
|
|
|
- label: '例如:名牌',
|
|
|
- value: '请输入名牌信息'
|
|
|
- }],
|
|
|
- paramsMinLimit: 2,
|
|
|
- paramskeyMap: {
|
|
|
- key: 'name',
|
|
|
- value: 'content'
|
|
|
- },
|
|
|
-
|
|
|
- // 问题数据表单列表
|
|
|
- questionPlaceHolderList: [{
|
|
|
- label: '请输入问题',
|
|
|
- value: '请输入回答'
|
|
|
- }],
|
|
|
- questionMinLimit: 2,
|
|
|
- questionkeyMap: {
|
|
|
- key: 'question',
|
|
|
- value: 'answer'
|
|
|
+ displayImageList: [], // 初始化列表
|
|
|
+ dialogVisible: false,
|
|
|
+ dialogImageUrl: '',
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ // 仪器参数
|
|
|
+ paramList() {
|
|
|
+ const filter = this.paramEmptyList.filter(param => param.content !== '' && param.name !== '')
|
|
|
+ if (filter.length > 0) return filter.map(param => ({name: param.name, content: param.content}))
|
|
|
+ return []
|
|
|
},
|
|
|
- // 表单校验规则
|
|
|
- rules: {
|
|
|
- // 产品名称
|
|
|
- name: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '名称不能为空',
|
|
|
- trigger: ['blur','change']
|
|
|
- }],
|
|
|
- // 产品别名
|
|
|
- alias: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '别名不能为空',
|
|
|
- trigger: ['blur','change']
|
|
|
- }],
|
|
|
- // 产品概述
|
|
|
- discription: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '概述不能为空',
|
|
|
- trigger: ['blur','change']
|
|
|
- }],
|
|
|
- // 产品图片
|
|
|
- image: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '图片不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 认证链接
|
|
|
- authLink: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '认证链接不能为空',
|
|
|
- trigger: ['change', 'blur']
|
|
|
- }],
|
|
|
- // 认证二维码
|
|
|
- authQrCode: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '认证二维码不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 产品参数
|
|
|
- paramList: [{
|
|
|
- type: 'array',
|
|
|
- required: true,
|
|
|
- message: '参数信息不能为空',
|
|
|
- trigger: ['change', 'blur'],
|
|
|
- valid: ['name', 'content']
|
|
|
- }],
|
|
|
- // 产品优点
|
|
|
- advantage: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '优点不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 产品缺点
|
|
|
- disadvantage: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '缺点不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 产品原理
|
|
|
- principle: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '原理不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 品牌
|
|
|
- brand: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '品牌不能为空',
|
|
|
- trigger: ['change','blur']
|
|
|
- }],
|
|
|
- // 产地
|
|
|
- producePlace: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '产地不能为空',
|
|
|
- trigger: ['change','blur']
|
|
|
- }],
|
|
|
- // 上市时间
|
|
|
- marketTime: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '上市时间不能为空',
|
|
|
- trigger: ['change','blur']
|
|
|
- }],
|
|
|
- // 公司/厂商
|
|
|
- company: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '公司/厂商不能为空',
|
|
|
- trigger: ['change','blur']
|
|
|
- }],
|
|
|
- // NMPA认证时间
|
|
|
- nmpaTime: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: 'NMPA认证时间不能为空',
|
|
|
- trigger: ['change','blur']
|
|
|
- }],
|
|
|
- // 产品认证
|
|
|
- authImageList: [{
|
|
|
- type: 'array',
|
|
|
- required: true,
|
|
|
- message: '仪器认证图片不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 适应人群
|
|
|
- adaptiveMan: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '适应人群不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 不适应人群
|
|
|
- unAdaptiveMan: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '不适应人群不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 术前术后
|
|
|
- aroundOperation: [{
|
|
|
- type: 'string',
|
|
|
- required: true,
|
|
|
- message: '术前术后内容不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 效果展示
|
|
|
- displayImageList: [{
|
|
|
- type: 'array',
|
|
|
- required: true,
|
|
|
- message: '效果展示图片不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 常见问题
|
|
|
- questionList: [{
|
|
|
- type: 'array',
|
|
|
- required: true,
|
|
|
- message: '常见问题不能为空',
|
|
|
- trigger: ['change','blur'],
|
|
|
- valid: ['question', 'answer']
|
|
|
- }],
|
|
|
- // 产品类别
|
|
|
- typeId: [{
|
|
|
- type: 'number',
|
|
|
- required: true,
|
|
|
- message: '仪器类别不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
- // 产品状态
|
|
|
- status: [{
|
|
|
- type: 'number',
|
|
|
- required: true,
|
|
|
- message: '状态不能为空',
|
|
|
- trigger: 'change'
|
|
|
- }],
|
|
|
+ // 常见问题
|
|
|
+ questionList() {
|
|
|
+ const filter = this.questionEmptyList.filter(item => item.question !== '' && item.answer !== '')
|
|
|
+ if (filter.length > 0) return filter.map(item => ({question: item.question, answer: item.answer}))
|
|
|
+ return []
|
|
|
},
|
|
|
},
|
|
|
created() {
|
|
|
this.getTypeList();
|
|
|
+ this.watchArrayStatus(['paramList', 'questionList', 'authImageList', 'displayImageList']);
|
|
|
this.getProductFormData();
|
|
|
- this.resetQuestionListLimit();
|
|
|
- this.resetParamsListLimit();
|
|
|
- this.registerForm(this.formData, this.rules);
|
|
|
- },
|
|
|
- mounted: function () {
|
|
|
- $('.navLayout').find('.navList').removeClass("on").find('.con').hide().find('a').removeClass("on");
|
|
|
- $('.navLayout').find('.navList').eq(3).addClass("on").find('.con').show().find('a').eq(1).addClass("on");
|
|
|
+
|
|
|
},
|
|
|
- methods: {
|
|
|
- // 获取分类列表
|
|
|
- getTypeList() {
|
|
|
- const that = this;
|
|
|
- SupplierApi.ShopBaikeProductTypeList({commodityType: this.commodityType}, function (res) {
|
|
|
- that.typeList = res.data;
|
|
|
- console.log(res);
|
|
|
- })
|
|
|
- },
|
|
|
|
|
|
- // 初始化表单数据
|
|
|
- initFormData(formData){
|
|
|
- console.log(formData);
|
|
|
- // 初始化this.formData
|
|
|
- for (var key in this.formData) {
|
|
|
- if (formData.hasOwnProperty(key)) {
|
|
|
- // this.$set(this.formData, key, formData[key]);
|
|
|
- this.formData[key] = formData[key];
|
|
|
- }
|
|
|
- }
|
|
|
+ methods: {
|
|
|
|
|
|
- this.formData.marketTime = dateFormat(new Date(this.formData.marketTime), 'yyyy-MM-dd');
|
|
|
- this.formData.nmpaTime = dateFormat(new Date(this.formData.nmpaTime), 'yyyy-MM-dd');
|
|
|
-
|
|
|
- // 初始化图片列表 imageList authImageList displayImageList
|
|
|
- this.imageList = this.initPreviewImageList([formData.image], { name: '授权图片' });
|
|
|
- this.authImageList = this.initPreviewImageList(formData.authImageList, { name: '授权图片' });
|
|
|
- this.displayImageList = this.initPreviewImageList(formData.displayImageList, { name: '效果图' });
|
|
|
-
|
|
|
- // 初始化参数列表
|
|
|
- if (formData.questionList.length < this.questionMinLimit) {
|
|
|
- const newQuestionList = [];
|
|
|
- for (var i = 0; i < this.questionMinLimit; i++) {
|
|
|
- if (formData.questionList[i]) {
|
|
|
- newQuestionList[i] = formData.questionList[i]
|
|
|
- } else {
|
|
|
- newQuestionList[i] = {question: '', answer: '',}
|
|
|
- }
|
|
|
- }
|
|
|
- this.formData.questionList = newQuestionList
|
|
|
- }
|
|
|
- // 初始化问题列表
|
|
|
- if (formData.paramList.length < this.paramsMinLimit) {
|
|
|
- const newParamList = [];
|
|
|
- for (var i = 0; i < this.paramsMinLimit; i++) {
|
|
|
- if (formData.paramList[i]) {
|
|
|
- newParamList[i] = formData.paramList[i]
|
|
|
- } else {
|
|
|
- newParamList[i] = {name: '', content: '',}
|
|
|
- }
|
|
|
- }
|
|
|
- this.formData.paramList = newParamList
|
|
|
- }
|
|
|
+ // 返回文章列表页面
|
|
|
+ handleBack: function handleBack() {
|
|
|
+ localStorage.removeItem('target-name');
|
|
|
+ window.open('/supplier/encyclopedia/instrument-list.html', 'supplier-instrument-list');
|
|
|
+ window.close();
|
|
|
},
|
|
|
-
|
|
|
- // 初始化图片
|
|
|
- initPreviewImageList(imageList, options){
|
|
|
- if(!options){
|
|
|
- options.name = '图片'
|
|
|
- }
|
|
|
-
|
|
|
- return imageList.map(function(item){
|
|
|
- return {
|
|
|
- name: options.name,
|
|
|
- url: item
|
|
|
- }
|
|
|
- });
|
|
|
+ // 保存事件
|
|
|
+ handleSave() {
|
|
|
+ this.$refs.ruleForm.validate(valide => {
|
|
|
+ console.log(valide);
|
|
|
+ if (!valide) return;
|
|
|
+ this.saveFormData()
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
-
|
|
|
- // 获取表单数据
|
|
|
- getProductFormData() {
|
|
|
- this.productId = localStorage.getItem('productId');
|
|
|
- localStorage.removeItem('productId');
|
|
|
-
|
|
|
- if(!this.productId) return;
|
|
|
-
|
|
|
- const that = this;
|
|
|
- SupplierApi.GetShopBaikeProductForm({ productId: this.productId }, function(res){
|
|
|
- if(res.code === 0){
|
|
|
- that.initFormData(res.data);
|
|
|
- }else{
|
|
|
- CAIMEI.dialog('获取产品数据失败', false);
|
|
|
- setTimeout(function () {
|
|
|
- that.handleBack();
|
|
|
- }, 2000);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
// 保存表单数据
|
|
|
saveFormData() {
|
|
|
const that = this;
|
|
@@ -374,177 +194,243 @@ new Vue({
|
|
|
...this.formData,
|
|
|
shopId: this.shopId,
|
|
|
commodityType: this.commodityType,
|
|
|
- paramList: JSON.stringify(this.formData.paramList),
|
|
|
- questionList: JSON.stringify(this.formData.questionList)
|
|
|
+ paramList: JSON.stringify(this.paramList),
|
|
|
+ questionList: JSON.stringify(this.questionList),
|
|
|
+ marketTime: dateFormat(this.formData.marketTime, 'yyyy-MM-dd'),
|
|
|
+ nmpaTime: dateFormat(this.formData.nmpaTime, 'yyyy-MM-dd'),
|
|
|
+ authImageList: this.authImageList.map(image => (image.response ? image.response.data : image.url)),
|
|
|
+ displayImageList: this.displayImageList.map(image => (image.response ? image.response.data : image.url))
|
|
|
};
|
|
|
|
|
|
- if(this.productId) params.productId = this.productId;
|
|
|
-
|
|
|
- SupplierApi.ShopBaikeProductSave(params, function(res){
|
|
|
- if(res.code === 0) {
|
|
|
+ if (this.productId) params.productId = this.productId;
|
|
|
+ console.log(params);
|
|
|
+ SupplierApi.ShopBaikeProductSave(params, function (res) {
|
|
|
+ if (res.code === 0) {
|
|
|
CAIMEI.dialog('保存成功', false);
|
|
|
setTimeout(function () {
|
|
|
that.handleBack();
|
|
|
}, 2000);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
CAIMEI.Alert(res.msg, '确认', false)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- // 返回文章列表页面
|
|
|
- handleBack: function handleBack() {
|
|
|
- localStorage.removeItem('target-name');
|
|
|
- window.open('/supplier/encyclopedia/instrument-list.html', 'supplier-instrument-list');
|
|
|
- window.close();
|
|
|
+ initFormData: function(formData){
|
|
|
+ console.log(formData);
|
|
|
+ // 初始化this.formData
|
|
|
+ for (var key in this.formData) {
|
|
|
+ if (formData.hasOwnProperty(key)) {
|
|
|
+ // 如果是数组 就取值length
|
|
|
+ if(formData[key] instanceof Array){
|
|
|
+ const len = formData[key].length
|
|
|
+ this.formData[key] = len > 0 ? len : ''
|
|
|
+ } else if(['marketTime', 'nmpaTime'].includes(key)){
|
|
|
+ this.formData[key] = new Date(formData[key])
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.formData[key] = formData[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理参数
|
|
|
+ this.resetEmptyListData(formData.paramList, formData.questionList);
|
|
|
+ // 处理图片
|
|
|
+ this.authImageList = formData.authImageList.map(image => ({ url: image, name: 'authImage'}))
|
|
|
+ this.displayImageList = formData.displayImageList.map(image => ({ url: image, name: 'authImage'}))
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // 获取表单数据
|
|
|
+ getProductFormData() {
|
|
|
+ this.productId = localStorage.getItem('productId') || 0;
|
|
|
+ localStorage.removeItem('productId');
|
|
|
+ if (this.productId > 0) {
|
|
|
+ const that = this;
|
|
|
+ SupplierApi.GetShopBaikeProductForm({productId: this.productId}, function (res) {
|
|
|
+ if (res.code === 0) {
|
|
|
+ that.initFormData(res.data);
|
|
|
+ } else {
|
|
|
+ CAIMEI.dialog('获取仪器数据失败', false);
|
|
|
+ setTimeout(function () {
|
|
|
+ that.handleBack();
|
|
|
+ }, 2000);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ this.resetEmptyListData([],[])
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- // 保存事件
|
|
|
- handleSave() {
|
|
|
+ // 获取分类列表
|
|
|
+ getTypeList() {
|
|
|
const that = this;
|
|
|
- // that.saveFormData();
|
|
|
- this.validFormData(this.formData, this.rules).then(res=>{
|
|
|
+ SupplierApi.ShopBaikeProductTypeList({commodityType: this.commodityType}, function (res) {
|
|
|
+ that.typeList = res.data;
|
|
|
console.log(res);
|
|
|
- that.saveFormData()
|
|
|
- }).catch(()=>{
|
|
|
- CAIMEI.dialog('必填项不能为空', false)
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- // 上传封面图片
|
|
|
- handleUploadProductImage(files){
|
|
|
- this.uploadImage(files[0]).then(res=>{
|
|
|
- this.formData.image = res;
|
|
|
- this.imageList.push({ url: res , name: '封面'})
|
|
|
- }).catch(err=>{
|
|
|
- console.log(err)
|
|
|
+ //添加一条参数
|
|
|
+ addParam() {
|
|
|
+ this.paramEmptyList.push({
|
|
|
+ name: '',
|
|
|
+ content: '',
|
|
|
+ p1: '参数名',
|
|
|
+ p2: '参数信息',
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- // 删除上传的封面图片
|
|
|
- handleRemoveProductImage(){
|
|
|
- this.formData.image = '';
|
|
|
- this.imageList = [];
|
|
|
+ // 删除一条参数
|
|
|
+ removeParam(index) {
|
|
|
+ this.paramEmptyList.splice(index, 1)
|
|
|
},
|
|
|
|
|
|
- // 上传授权图片
|
|
|
- handleUploadAuthImage(files){
|
|
|
- const that = this;
|
|
|
- files.forEach(function (file) {
|
|
|
- if(file.type){
|
|
|
- // resultFiles 是 input 中选中的文件列表
|
|
|
- // insertImgFn 是获取图片 url 后,插入到编辑器的方法
|
|
|
- that.uploadImage(file).then(function (res) {
|
|
|
- that.formData.authImageList.push(res);
|
|
|
- that.authImageList.push({ url: res, name: '图片' })
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- // 删除上传的授权图片
|
|
|
- handleRemoveAuthImage(index){
|
|
|
- this.formData.authImageList.splice(index, 1);
|
|
|
- this.authImageList.splice(index, 1);
|
|
|
- console.log(this.formData.authImageList);
|
|
|
- console.log(this.authImageList);
|
|
|
+ //添加一条问答
|
|
|
+ addQuestion() {
|
|
|
+ this.questionEmptyList.push({
|
|
|
+ question: '',
|
|
|
+ answer: '',
|
|
|
+ p1: '请输入问题内容',
|
|
|
+ p2: '请输入问题解答内容',
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- // 上传效果展示图片
|
|
|
- handleUploadDisplayImageList(files){
|
|
|
- const that = this;
|
|
|
- files.forEach(function (file) {
|
|
|
- if(file.type){
|
|
|
- // resultFiles 是 input 中选中的文件列表
|
|
|
- // insertImgFn 是获取图片 url 后,插入到编辑器的方法
|
|
|
- that.uploadImage(file).then(function (res) {
|
|
|
- that.formData.displayImageList.push(res);
|
|
|
- that.displayImageList.push({ url: res, name: '图片' })
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
+ // 删除一条问答
|
|
|
+ removeQuestion(index) {
|
|
|
+ this.questionEmptyList.splice(index, 1)
|
|
|
},
|
|
|
- // 删除上传的效果展示图片
|
|
|
- handleRemoveDisplayImageList(index){
|
|
|
- this.formData.displayImageList.splice(index, 1);
|
|
|
- this.displayImageList.splice(index, 1);
|
|
|
- },
|
|
|
-
|
|
|
|
|
|
- // 上传封面图片
|
|
|
- handleUploadAuthQrCode(files){
|
|
|
- this.uploadImage(files[0]).then(res=>{
|
|
|
- this.formData.authQrCode = res;
|
|
|
- this.authQrCodeList.push({ url: res , name: '封面'})
|
|
|
- }).catch(err=>{
|
|
|
- console.log(err)
|
|
|
+ // 初始化可变表单数据
|
|
|
+ resetEmptyListData(paramSource, questionSource) {
|
|
|
+ this.makeEmptyList({
|
|
|
+ target: this.paramEmptyList,
|
|
|
+ source: paramSource,
|
|
|
+ limit: this.minLimitParams,
|
|
|
+ key: 'name',
|
|
|
+ value: 'content',
|
|
|
+ })
|
|
|
+ this.makeEmptyList({
|
|
|
+ target: this.questionEmptyList,
|
|
|
+ source: questionSource,
|
|
|
+ limit: this.minLimitQuestions,
|
|
|
+ key: 'question',
|
|
|
+ value: 'answer',
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- // 删除上传的封面图片
|
|
|
- handleRemoveAuthQrCode(){
|
|
|
- this.formData.authQrCode = '';
|
|
|
- this.authQrCodeList = [];
|
|
|
+ // 创建可变表单占位列表
|
|
|
+ makeEmptyList(options) {
|
|
|
+ options = {
|
|
|
+ target: [], // 目标数组
|
|
|
+ source: [], // 数据源数组
|
|
|
+ key: '',
|
|
|
+ value: '',
|
|
|
+ limit: 0, // 最小条数
|
|
|
+ argsList: ['参数', '品牌'], // placeholder文本
|
|
|
+ ...options,
|
|
|
+ }
|
|
|
+ let {target, source, limit, argsList, key, value} = options
|
|
|
+ let len = 0
|
|
|
+
|
|
|
+ target.push(
|
|
|
+ ...source.map(v => {
|
|
|
+ v.p1 = `例如:${argsList[0]}`
|
|
|
+ v.p2 = `请输入:${argsList[0]}信息`
|
|
|
+ return v
|
|
|
+ })
|
|
|
+ )
|
|
|
+
|
|
|
+ len = limit - target.length
|
|
|
+ for (let i = 0; i < len; i++) {
|
|
|
+ const obj = {}
|
|
|
+ obj[key] = ''
|
|
|
+ obj[value] = ''
|
|
|
+ if (i <= argsList.length - 1) {
|
|
|
+ obj.p1 = `例如:${argsList[i]}`
|
|
|
+ obj.p2 = `请输入:${argsList[i]}信息`
|
|
|
+ } else {
|
|
|
+ obj.p1 = `例如:${argsList[0]}`
|
|
|
+ obj.p2 = `请输入:${argsList[0]}信息`
|
|
|
+ }
|
|
|
+ target.push(obj)
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
+ handleAuthQrCodeSuccess(response){
|
|
|
+ this.$refs.authQrCodeUploader.clearFiles();
|
|
|
+ this.formData.authQrCode = response.data
|
|
|
+ },
|
|
|
|
|
|
- // 上传图片
|
|
|
- uploadImage: function uploadImage(file) {
|
|
|
- var formData = new FormData();
|
|
|
- formData.append('file', file);
|
|
|
- return new Promise(function (resolve, reject) {
|
|
|
- PublicApi.uploadimg(formData, function (res) {
|
|
|
- if (res.code === 0) {
|
|
|
- resolve(res.data);
|
|
|
- }
|
|
|
- reject();
|
|
|
- });
|
|
|
- });
|
|
|
+ // 仪器图片上传成功的回调
|
|
|
+ handleImageSuccess(response) {
|
|
|
+ this.$refs.coverUploader.clearFiles();
|
|
|
+ this.formData.image = response.data
|
|
|
},
|
|
|
|
|
|
- // 初始化问题表单个数
|
|
|
- resetParamsListLimit() {
|
|
|
- for (let i = 0; i < this.paramsMinLimit; i++) {
|
|
|
- this.formData.paramList.push({
|
|
|
- name: '',
|
|
|
- content: ''
|
|
|
- });
|
|
|
- }
|
|
|
+ // 认证图片上传成功的回调
|
|
|
+ handleAuthImageSuccess(response, file, fileList) {
|
|
|
+ this.authImageList = fileList
|
|
|
},
|
|
|
- // 移除参数
|
|
|
- handleRemoveParams(params) {
|
|
|
- console.log(params);
|
|
|
- this.formData.paramList.splice(params.index, 1);
|
|
|
+
|
|
|
+ // 移除认证图片
|
|
|
+ handleAuthImageRemove(file, fileList) {
|
|
|
+ // console.log(fileList)
|
|
|
+ this.authImageList = fileList
|
|
|
},
|
|
|
- // 添加参数
|
|
|
- handleAddParams() {
|
|
|
- this.formData.paramList.push({
|
|
|
- name: '',
|
|
|
- content: ''
|
|
|
- });
|
|
|
- this.registerForm(this.formData, this.rules);
|
|
|
+
|
|
|
+ // 效果图片上传成功的回调
|
|
|
+ handleDisplayImageSuccess(response, file, fileList) {
|
|
|
+ this.displayImageList = fileList
|
|
|
},
|
|
|
|
|
|
+ // 移除效果图片
|
|
|
+ handleDisplayImageRemove(file, fileList) {
|
|
|
+ this.displayImageList = fileList
|
|
|
+ },
|
|
|
|
|
|
- // 初始化问题表单个数
|
|
|
- resetQuestionListLimit() {
|
|
|
- for (let i = 0; i < this.questionMinLimit; i++) {
|
|
|
- this.formData.questionList.push({
|
|
|
- question: '',
|
|
|
- answer: '',
|
|
|
- });
|
|
|
+ // 图片上传前的回调
|
|
|
+ beforeImageUpload(file) {
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2
|
|
|
+ if (!isLt2M) {
|
|
|
+ this.$message.error('上传头像图片大小不能超过 2MB!')
|
|
|
}
|
|
|
+ return isLt2M
|
|
|
},
|
|
|
- // 移除问题
|
|
|
- handleRemoveQuestion(question) {
|
|
|
- this.formData.questionList.splice(question.index, 1);
|
|
|
+
|
|
|
+ // 预览图片
|
|
|
+ handlePictureCardPreview(file) {
|
|
|
+ this.dialogImageUrl = file.url
|
|
|
+ this.dialogVisible = true
|
|
|
},
|
|
|
- // 添加问题
|
|
|
- handleAddQuestion() {
|
|
|
- this.formData.questionList.push({
|
|
|
- question: '',
|
|
|
- answer: '',
|
|
|
- });
|
|
|
- this.registerForm(this.formData, this.rules);
|
|
|
+
|
|
|
+ // 预览图片弹窗
|
|
|
+ handlePictureCardPreview(file) {
|
|
|
+ this.dialogImageUrl = file.url
|
|
|
+ this.dialogVisible = true
|
|
|
},
|
|
|
- }
|
|
|
-});
|
|
|
+
|
|
|
+ // 监听formData中类型为数组的数据状态
|
|
|
+ watchArrayStatus(args = []) {
|
|
|
+ args.forEach(arg => {
|
|
|
+ if (this[arg] instanceof Array) {
|
|
|
+ this.$watch(
|
|
|
+ arg,
|
|
|
+ (nval, oval) => {
|
|
|
+ console.log(arg, nval.length);
|
|
|
+ console.log(this[arg]);
|
|
|
+ if(nval.length > 0){
|
|
|
+ this.formData[arg] = nval.length
|
|
|
+ } else{
|
|
|
+ this.formData[arg] = ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {deep: true}
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ },
|
|
|
+})
|
|
|
+
|
|
|
+app.$mount('#instrumentEdit')
|