fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
<template>
  <el-col :span="24" class="form inner-bg-style">
    <el-form size="mini" ref="form" label-width="140px" :model="form" class="product"
             :disabled="$route.query.pageTag === 'detail'" :rules="formRules">
      <!-- <div v-show="showCategory">
        <p class="category">选择品类发布商品</p>
        <el-form-item label="选择品类:">
          <el-cascader ref="cascaderAddr" :options="categoryList" :props="categoryProp"
                       @change="handleChange" style="width: 50%" clearable>
            <div slot-scope="scope" @click="clickCategory('cascaderAddr',$event)">
              {{scope.data.catName}}</div>
          </el-cascader>
        </el-form-item>
      </div> -->
      <div v-show="!showCategory && !showSkuMetas">
        <p>商品信息</p>
        <div class="formBlock">
          <el-row>
            <el-col :span="12">
              <div v-if="pageTag === 'add' || (pageTag === 'edit' && form.prodSpu.spuType === '3')">
                <el-form-item label="选择品类:" prop="categoryArr">
                  <el-cascader ref="cascaderAddr" v-model="form.categoryArr" :options="categoryList"
                               :props="categoryProp" @change="handleChange" clearable>
                    <div slot-scope="scope" @click="clickCategory('cascaderAddr',$event)">
                      {{scope.data.catName}}</div>
                  </el-cascader>
                </el-form-item>
              </div>
              <div v-else>
                <span>{{this.form.prodSpu.cascaderLabel}}</span>
                <!-- <el-button type="text" @click="againChoice" v-if="!spuId">重选品类</el-button> -->
              </div>
            </el-col>
          </el-row>
        </div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商品主编码:" prop="prodSpu.spuNum">
              <!-- <el-input placeholder="请输入与主数据商品编号一致的商品编号" v-model="form.prodSpu.spuNum" clearable>
                              </el-input> -->
              <el-autocomplete v-model.trim="form.prodSpu.spuNum" :disabled="!!$route.query.spuId"
                               :fetch-suggestions="querySearchAsync"
                               placeholder="请输入与主数据商品编号一致的商品编号" @select="handleSelect"
                               @change="changeSpuNum" :trigger-on-focus="false" style="width: 100%"
                               oninput="value=value.replace(/[^\w]/g,'')">
                <template slot-scope="{ item }">
                  <div :class="item.isExist ? 'is-disabled' : ''">
                    <div class="spuNum">{{ item.spuNum }}</div>
                    <span class="content">{{ item.spuName }} <span
                            class="exist">{{item.isExist ? '【已存在】' : ''}}</span></span>
                  </div>
                </template>
              </el-autocomplete>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.shopSpu.packageCode">
            <el-form-item label="平台套餐编码:">
              {{form.shopSpu.packageCode}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商品名称:" prop="prodSpu.spuName">
              <el-input placeholder="请输入商品名称" v-model="form.prodSpu.spuName" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商品类型:" prop="prodSpu.spuCls">
              <el-select placeholder="请选择商品类型" v-model="form.prodSpu.spuCls" clearable>
                <el-option label="酒类" value="1" key="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商品品牌:" prop="prodSpu.brandId">
              <el-select ref="brandLabel" placeholder="请选择商品品牌" v-model="form.prodSpu.brandId"
                         clearable @change="getBrandLabel">
                <el-option v-for="item in brandArray" :key="item.brandId" :value="item.brandId"
                           :label="item.brandName"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="展示分类:">
              <el-cascader ref="displayCascader" :options="displayCategoryArray"
                           :props="displayCategoryProp" v-model="catIdSaleArray" clearable>
                <!-- <div slot-scope="scope" @click="clickCategory('displayCascader',$event)">{{scope.data.catName}}</div> -->
              </el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计量单位:" prop="prodSpu.spuUnit">
              <el-input placeholder="请输入计量单位" :disabled="form.skuMetasArray.length ? true : false"
                        v-model="form.prodSpu.spuUnit" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="广告词:" prop="prodSpu.spuAdWords">
              <el-input placeholder="请输入广告词" v-model="form.prodSpu.spuAdWords" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="商品标签:" prop="prodSpu.spuTags">
              <el-input placeholder="请输入商品标签" v-model="form.prodSpu.spuTags" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分享描述:" prop="prodSpu.spuShare">
              <el-input placeholder="请输入分享描述" v-model="form.prodSpu.spuShare" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="12">
                        <el-form-item label="商品负库存:" prop="prodSpu.negativeStockType">
                            <el-radio-group v-model="form.prodSpu.negativeStockType">
                              <el-radio label="1">允许</el-radio>
                              <el-radio label="0">不允许</el-radio>
                            </el-radio-group>
                        </el-form-item>
                     </el-col> -->
          <el-col :span="12">
            <el-form-item label="展示到推荐:" prop="prodSpu.isRecommend">
              <el-radio-group v-model="form.prodSpu.isRecommend">
                <el-radio label="1">推荐</el-radio>
                <el-radio label="0">不推荐</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-form-item label="优先展示:" prop="firstDisplay">
                      <el-radio-group v-model="form.firstDisplay" @change="changeFirstDisplay">
                        <el-radio label="1">是</el-radio>
                        <el-radio label="0">否</el-radio>
                      </el-radio-group>
                  </el-form-item> -->
        <!-- <el-row>
                     <el-col :span="12">
                        <el-form-item label="展示顺序:" v-if="form.firstDisplay==='1'" prop="prodSpu.hotProduct">
                            <el-select v-model="form.prodSpu.hotProduct">
                                <el-option label="1" value="3"></el-option>
                                <el-option label="2" value="2"></el-option>
                                <el-option label="3" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                     </el-col>
                  </el-row> -->
        <div v-if="showSpecifications && form.prodSpu.spuType !== '3'">
          <div class="formBlock">
            <span>价格库存</span>
          </div>
          <div v-if="isTip" class="itemTip">温馨提示:销售价格不应低于红线价格</div>
          <el-row>
            <el-col :span="12">
              <el-form-item label="销售价格:" prop="shopSpu.prodPrice.salePrice">
                <el-input-number v-model="form.shopSpu.prodPrice.salePrice"
                                 @keydown.native="limiInputType" clearable
                                 @change="changeProdSalePrice">
                </el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="挂牌价格:" prop="shopSpu.prodPrice.listPrice">
                <el-input-number v-model="form.shopSpu.prodPrice.listPrice"
                                 @keydown.native="limiInputType" clearable></el-input-number>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="shopSpu.prodPrice.redLinePrice">
                <template slot="label">
                  <span>红线价格(瓶)
                    <el-popover placement="top" trigger="click">
                      1.指该商品规格最低销售价格,不得低于红线价<br />
                      2.该价统一由工管部规划
                      <i class="el-icon-question" style="cursor:pointer;" slot="reference"></i>
                    </el-popover>
                    <span>:</span>
                  </span>
                </template>
                <el-input-number v-if="form.shopSpu.prodPrice.redLinePrice" disabled
                                 v-model="form.shopSpu.prodPrice.redLinePrice"
                                 @keydown.native="limiInputType" clearable>
                </el-input-number>
                <span v-else>-</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="商品库存:" prop="shopSpu.spuStorage">
                <el-input-number disabled v-model="form.shopSpu.spuStorage" :min='0'
                                 @keydown.native="limiInputType" clearable></el-input-number>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="预警库存:" prop="shopSpu.spuFreezeStorage">
                <el-input-number disabled v-model="form.shopSpu.spuFreezeStorage" :min='0'
                                 @keydown.native="limiInputType" clearable></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="扣减方式:" prop="shopSpu.storageMinusType">
                下单后扣减
                <!-- <el-select placeholder="请选择扣减方式" v-model="form.shopSpu.storageMinusType" clearable>
                                    <el-option v-for="item in reduceArray" :key="item.id" :value="item.id" :label="item.name"></el-option>
                                  </el-select> -->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="商品扣减数:" prop="shopSpu.skuReduceStorage"
                            :rules="formRules.skuReduceStorage">
                <el-input-number disabled v-model="form.shopSpu.skuReduceStorage" :min='0'
                                 @keydown.native="limiInputType" clearable></el-input-number>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <sku-metas-info v-else ref="skuMetas" :reduceArray="reduceArray" :form="form"
                        :showSkuMetas="showSkuMetas" :formRules='formRules'></sku-metas-info>
        <!-- <div class="formBlock">
                        <span>商品属性</span>
                  </div>
                  <div>
                     <span v-for="(item,index) in form.categoryPropArray" class="categoryPropStyle" :key="index">
                        <el-form-item :label="item.productProp.propName+':'" :prop="'categoryPropArray.'+index+'.temporaryId'" v-if="item.productProp.propShow !== '0'"  :rules="{required: item.productProp.propRequired ? true : false, message: `请输入${item.productProp.propName}`}">
                            <el-select :placeholder="'请选择'+item.productProp.propName" v-model="item.temporaryId" clearable >
                                 <el-option v-for="itemProp in item.propMetaValues" :key="itemProp.propValueId" :value="itemProp.propValueId" :label="itemProp.propValue"></el-option>
                              </el-select>
                        </el-form-item>
                        <el-form-item :label="item.productProp.propName+':'" :prop="'categoryPropArray.'+index+'.customPropValue'" v-if="item.productProp.propShow === '0'" :rules="[{required: item.productProp.propRequired ? true : false, message: `请输入${item.productProp.propName}`},{max:128,message:`${item.productProp.propName}最多只能输入 128 个字`}]">
                            <el-input :placeholder="'请输入'+item.productProp.propName" v-model="item.customPropValue" clearable></el-input>
                        </el-form-item>
                     </span>
                  </div> -->
        <div class="formBlock">
          <span>商品详情</span>
        </div>
        <el-form-item label="商品轮播图片:" prop="prodImgs">
          <custom-upload-img :limitNumber="5"
                             :accept='".jpg,.jpeg,.png,.JPG,.JPEG,.PBG,.gif,.GIF,.mp4"'
                             @handle-file-data="handleFileData" :draggable="true"
                             @handle-success="handleSuccess" @handle-remove="handleRemove"
                             :isHideDelete="$route.query.pageTag !== 'detail'"
                             :imageSize="'754 * 754'" :fileList="form.prodImgs"></custom-upload-img>
        </el-form-item>
        <el-form-item v-if="$route.query.pageTag === 'detail'" label="商品描述:">
          <div class="content" v-html="form.spuDetails[0].spuContent"></div>
        </el-form-item>
        <el-form-item v-else label="商品描述:" prop="spuDetails[0].spuContent">
          <!-- <tinymce @get-context="getContext" :contentTxt ="form.spuDetails[0].spuContent" ></tinymce> -->
          <Editor ref="editor" :content.sync="form.spuDetails[0].spuContent"></Editor>
        </el-form-item>
      </div>
      <!-- <sku-metas-info ref="skuMetas" :reduceArray="reduceArray" :form="form" :showSkuMetas="showSkuMetas" :formRules='formRules'></sku-metas-info> -->
    </el-form>
    <el-row class="buttonPosition">
      <!-- <el-button type="primary" v-show="showSkuMetas " size="mini" @click="upStep">上一步</el-button> -->
      <!-- <el-button type="primary" v-show="showCategory && categoryId" size="mini" @click="nextStep">
        下一步</el-button> -->
      <!-- <el-button type="primary" v-show="!showCategory&&form.skuMetasArray.length&&!showSkuMetas" size="mini" @click="nextStepTwo">下一步</el-button> -->
      <el-button type="primary" v-show="!showCategory && $route.query.pageTag !== 'detail'"
                 size="mini" :loading="loading" @click="submit">保存</el-button>
      <el-button size="mini" @click="cancel">取消</el-button>
    </el-row>
  </el-col>
</template>
<script>
import productListApi from '@/api/productmanagement/productList'
import productCategoryApi from '@/api/productmanagement/productCategory'
import productExhibitionApi from '@/api/productmanagement/productExhibition'
import skuMetasInfo from '@/views/product/components/skuMetasInfo.vue'
// import tinymce from '@/components/tinymce/index.vue'
import Editor from '@/components/editor/editor.vue'
import { getStrLength } from '@/utils/getStrLength'
import { limiInputType } from '@/utils/limiInputType'
import { limitNumType, validatePrice, inputNumberValid } from '@/utils/validator'
 
export default {
  components: {
    skuMetasInfo,
    Editor
    //  tinymce
  },
  data() {
    var validateType = (rule, value, callback) => {
      if (((!this.showCategory && !this.form.skuMetasArray.length) || this.showSkuMetas) && !value) {
        callback(new Error('请选择扣减方式'))
      } else {
        callback()
      }
    }
    // var validateSpuStorage = (rule, value, callback) => {
    //   if (((!this.showCategory && !this.form.skuMetasArray.length) || this.showSkuMetas) && value === null && value === '') {
    //     callback(new Error('请输入商品库存'))
    //   } else {
    //     callback()
    //   }
    // }
    // var validateSpuFreezeStorage = (rule, value, callback) => {
    //   // if (((!this.showCategory && !this.form.skuMetasArray.length) || this.showSkuMetas) && value === null && value === '') {
    //   //   callback(new Error('请输入预警库存'))
    //   // }
    //   const reg = /^[0-9]*$/ // 只能输入正整数
    //   if (value && !reg.test(value)) {
    //     callback(new Error('请输入大于等于0的整数'))
    //   } else if (((!this.showCategory && !this.form.skuMetasArray.length) || this.showSkuMetas) && value >= this.form.shopSpu.spuStorage) {
    //     callback(new Error('预警库存应小于商品库存'))
    //   } else {
    //     callback()
    //   }
    // }
    // const inputStorgeNumberValid = (rule, value, callback) => {
    //   const reg = /^[0-9]*$/ // 只能输入正整数
    //   if (((!this.showCategory && !this.form.skuMetasArray.length) || this.showSkuMetas) && (!value || !reg.test(value))) {
    //     callback(new Error('请输入大于0的整数'))
    //   } else {
    //     callback()
    //   }
    // }
    return {
      dialogImageUrl: '',
      dialogVisible: false,
      showSkuMetas: false,
      showSpecifications: false, // 是否展示商品规格
      isTip: false, // 超过红线价格提示
      form: {
        tableLabel: null,
        firstDisplay: '0',
        categoryArr: [], // 选中的品类
        prodSpu: {
          brandId: null,
          spuNum: null,
          spuPriceCls: 1,
          cascaderLabel: null,
          brandName: null,
          spuLibraryType: '1',
          negativeStockType: '0',
          isRecommend: '0',
          spuUnit: null,
          hotProduct: null,
          catId: null
        },
        shopSpu: {
          prodPrice: {
            listPrice: null,
            salePrice: null,
            redLinePrice: null
          },
          // prodStorages: [{
          //   skuFreezeStorage: null,
          //   skuStorage: null
          // }],
          spuFreezeStorage: null,
          spuStorage: null,
          skuReduceStorage: 1,
          storageMinusType: '0',
          oldSkuId: null,
          packageCode: null
        },
        spuDetails: [{
          spuContent: '',
          spuShowType: '2'
        }],
        prodImgs: [],
        categoryPropArray: [], // 属性数组
        skuMetasArray: [] // 单品数组
      },
      formRules: {
        categoryArr: [{ required: true, message: '请选择品类', trigger: 'change' }],
        'prodSpu.spuNum': [
          { required: true, message: '请输入与主数据商品编号一致的商品编号', trigger: 'change' },
          { max: 32, message: '商品主编码最多只能输入 32 个字' },
          { validator: limitNumType }
        ],
        'prodSpu.spuName': [{ required: true, message: '请输入商品名称', trigger: 'change' }, {
          validator: (rule, value, callback) => {
            callback(getStrLength(rule, value, callback, 255, '商品名称'))
          }
        }],
        'prodSpu.spuCls': [{ required: true, message: '请选择商品类型', trigger: 'change' }],
        'prodSpu.spuLibraryType': [{ required: true, message: '请选择商品是否添加商品库', trigger: 'change' }],
        'prodSpu.isRecommend': [{ required: true, message: '请选择商品是否展示到推荐', trigger: 'change' }],
        firstDisplay: [{ required: true, message: '请选择商品是否优先展示', trigger: 'change' }],
        'prodSpu.negativeStockType': [{ required: true, message: '请选择是否负库存', trigger: 'change' }],
        'prodSpu.hotProduct': [{ required: true, message: '请选择商品展示顺序', trigger: 'change' }],
        'prodSpu.brandId': [{ required: true, message: '请选择商品品牌', trigger: 'change' }],
        // 'prodSpu.catIdSale': [{ required: true, message: '请选择展示分类' }],
        'prodSpu.spuUnit': [{ required: true, message: '请输入计量单位', trigger: 'change' }, {
          validator: (rule, value, callback) => {
            callback(getStrLength(rule, value, callback, 8, '计量单位'))
          }
        }],
        'shopSpu.prodPrice.salePrice': [
          { required: true, message: '请输入销售价格', trigger: 'change' },
          { validator: validatePrice }
        ],
        'shopSpu.prodPrice.listPrice': [
          { required: true, message: '请输入挂牌价格', trigger: 'change' },
          { validator: validatePrice }
        ],
        'spuDetails[0].spuContent': [{ required: true, message: '请输入商品描述', trigger: 'change' }, {
          validator: (rule, value, callback) => {
            callback(getStrLength(rule, value, callback, 4194304, '商品描述'))
          }
        }],
        'shopSpu.storageMinusType': [{ required: true, validator: validateType }],
        prodImgs: [{ type: 'array', required: true, message: '请上传商品轮播图片' }],
        'prodSpu.spuAdWords': [{
          validator: (rule, value, callback) => {
            callback(getStrLength(rule, value, callback, 512, '广告词'))
          }
        }],
        'prodSpu.spuTags': [{
          validator: (rule, value, callback) => {
            callback(getStrLength(rule, value, callback, 15, '商品标签'))
          }
        }],
        'prodSpu.spuShare': [{
          validator: (rule, value, callback) => {
            callback(getStrLength(rule, value, callback, 1024, '分享描述'))
          }
        }],
        salePrice: [
          { required: true, message: '请输入销售价格', trigger: 'change' },
          { validator: validatePrice }
        ],
        listPrice: [{ required: true, message: '请输入挂牌价格', trigger: 'change' }, { validator: validatePrice }],
        // skuStorage: [
        //   { required: true, message: '请输入商品库存', trigger: 'change' },
        //   { validator: inputNumberValid }
        // ],
        // skuFreezeStorage: [
        //   { required: true, message: '请输入预警库存', trigger: 'change' },
        //   { validator: inputNumberValid }
        // ],
        // 'shopSpu.spuStorage': [
        //   { required: true, validator: validateSpuStorage },
        //   { validator: inputStorgeNumberValid }
        // ],
        // 'shopSpu.spuFreezeStorage': [
        //   { validator: validateSpuFreezeStorage }
        //   // { validator: inputStorgeNumberValid }
        // ],
        skuReduceStorage: [
          { required: true, message: '请输入扣减库存', trigger: 'change' },
          { validator: inputNumberValid }
        ],
        skuPropValueId: [{ required: true, message: '请选择规格', trigger: 'change' }]
      },
      showCategory: false,
      reduceArray: [
        {
          name: '下单后',
          id: '0'
        },
        {
          name: '支付后',
          id: '1'
        },
        {
          name: '到货后',
          id: '2'
        },
        {
          name: '不扣减库存',
          id: '3'
        }
      ],
      categoryList: [], // 品类数组
      categoryProp: {
        value: 'catId',
        label: 'catName',
        children: 'childrens',
        checkStrictly: true
      },
      displayCategoryProp: {
        value: 'catId',
        label: 'catName',
        children: 'childrens',
        multiple: true
      },
      brandArray: [], // 商品品牌数组
      displayCategoryArray: [], // 展示分类数组
      catIdSaleArray: [], // 展示分类数组
      spuId: null, // 商品Id
      pageTag: 'add', // 页面标识
      loading: false,
      spuNumArr: [], // 搜索主数据编码
      oldSpuNum: null // 存一个每次点击前的spuNum
    }
  },
  created() {
    this.spuId = this.$route.query.spuId
    this.pageTag = this.$route.query.pageTag
    if (this.spuId) {
      // this.showCategory = false
      this.getFormDetails()
      this.form.prodSpu.cascaderLabel = null
    } else {
      this.initForm()
    }
    this.getCategory() // 获取分类树
  },
  watch: {
    'form.spuDetails': {
      handler: function (newValue) {
        if (newValue[0].spuContent) {
          this.$refs.form.clearValidate('spuDetails[0].spuContent')
        }
      },
      deep: true
    }
  },
  methods: {
    // 当主数据编码失去焦点的时候,遍历查询到的主数据,获取商品名称
    changeSpuNum(value) {
      if (value !== this.oldSpuNum && this.oldSpuNum !== 'custom') {
        if (this.showSkuMetas) {
          this.$refs.skuMetas.skuMetaForm.tableData = []
          // 是自己输入的商品主编码
          this.oldSpuNum = 'custom'
        }
        // 非单品
        if (this.form.skuMetasArray.length === 0) {
          this.getNotSingleRedLinePrice(value)
        }
      }
      const row = this.spuNumArr.find(item => item.spuNum === this.form.prodSpu.spuNum)
      if (row && !row.isExist) {
        this.$set(this.form.prodSpu, 'spuName', row.spuName)
        this.$set(this.form.shopSpu, 'spuStorage', row.stock || 0)
        this.$set(this.form.shopSpu, 'spuFreezeStorage', row.warningStock || 0)
      } else if (!row) {
        this.$set(this.form.shopSpu, 'spuStorage', 0)
        this.$set(this.form.shopSpu, 'spuFreezeStorage', 0)
      }
    },
    // 非单品的情况获取红线价格
    getNotSingleRedLinePrice(spuNum) {
      productListApi.getRedLinePrice({ spuNum: spuNum }).then(res => {
        // data为空,则主商品未关联红线价格
        this.form.shopSpu.prodPrice.redLinePrice = res.data ? res.data.redLinePrice : null
        this.isTip = !!(this.form.shopSpu.prodPrice.redLinePrice !== null && this.form.shopSpu.prodPrice.salePrice < this.form.shopSpu.prodPrice.redLinePrice)
      })
    },
    // 模糊搜索主数据编码
    querySearchAsync(queryString, cb) {
      if (queryString) {
        clearTimeout(this.timeout)
        this.timeout = setTimeout(async () => {
          const res = queryString ? await productListApi.queryStockSpuInfoByAssociate({ spuNum: queryString }) : null
          let results = []
          if (res.data) {
            results = res.data
          }
          this.spuNumArr = results
          cb(results)
        }, 3000 * Math.random())
      }
    },
    handleSelect(item) {
      if (!item.isExist) {
        if (this.form.prodSpu.spuNum !== item.spuNum && this.showSkuMetas) {
          this.$refs.skuMetas.skuMetaForm.tableData = []
        }
        this.form.prodSpu.spuNum = item.spuNum
        this.form.prodSpu.spuName = item.spuName
        this.form.shopSpu.spuStorage = item.stock
        this.form.shopSpu.spuFreezeStorage = item.warningStock
        this.oldSpuNum = this.form.prodSpu.spuNum
        // 非单品
        if (this.form.skuMetasArray.length === 0) {
          this.getNotSingleRedLinePrice(this.form.prodSpu.spuNum)
        }
      }
    },
    // 点击分类时获取值(点击即改变)
    clickCategory(name, event) {
      event.target.parentElement.parentElement.firstChild.click()
      // // 点击文字 关闭选择框
      // if (this.$refs[name].toggleDropDownVisible) {
      //   this.$refs[name].toggleDropDownVisible(false)
      // } else {
      //   this.$refs[name][0].toggleDropDownVisible(false)
      // }
    },
    // 数组更新时重新获取数据
    handleFileData(arr) {
      this.form.prodImgs = arr
    },
    /**
     * 当优先展示值改变时触发
     */
    changeFirstDisplay(val) {
      this.$set(this.form.prodSpu, 'hotProduct', null)
    },
    /**
     * 获取上传成功的图片
     */
    handleSuccess(data) {
      this.form.prodImgs.push({
        url: data.url,
        uid: data.id
      })
      this.$refs.form.validateField('prodImgs')
    },
    /**
     * 移除图片
     */
    handleRemove(file, data) {
      this.form.prodImgs = this.form.prodImgs.filter(v => {
        return v.uid !== file.uid
      })
    },
    /**
     * 限制不能输入数字
     */
    limiInputType(e) {
      limiInputType(e)
    },
    /**
 * 销售价格改变
 */
    changeProdSalePrice() {
      if (this.form.shopSpu.prodPrice.redLinePrice !== null && this.form.shopSpu.prodPrice.salePrice < this.form.shopSpu.prodPrice.redLinePrice) {
        this.isTip = true
      } else {
        this.isTip = false
      }
    },
    /**
     * 获取表单详情
     */
    getFormDetails() {
      productListApi.detailsInfo({ spuId: this.spuId }).then(res => {
        if (res.data) {
          // const spuFreezeStorage = res.data.spuInfo[0].spuFreezeStorage
          // res.data.spuInfo[0].spuFreezeStorage = spuFreezeStorage === null || spuFreezeStorage === '' ? undefined : spuFreezeStorage
          this.form.prodSpu = res.data.spuInfo
          if (!res.data.spuInfo.hotProduct || res.data.spuInfo.hotProduct === '0') {
            res.data.spuInfo.hotProduct = null
            this.$set(this.form, 'firstDisplay', '0')
            this.$set(this.form.prodSpu, 'hotProduct', null)
          } else {
            this.$set(this.form, 'firstDisplay', '1')
          }
          this.form.prodSpu.brandName = res.data.spuInfo.brandName
          this.form.prodSpu.cascaderLabel = this.getCascader(res.data.categories, 2).join('/')
          this.catIdSaleArray = []
          res.data.saleCategories.forEach(item => {
            const arr = this.getCascader(item, 1)
            this.catIdSaleArray.push(arr)
          })
          const arr = JSON.parse(JSON.stringify(this.form.categoryArr))
          const cId = arr ? arr[0] : null
          this.getBrandByCategory(cId)
          this.getDisplayCategory() // 获取展示品类
          // this.form.shopSpu.prodStorages = res.data.defaultSkuInfo ? res.data.defaultSkuInfo.prodStorages : [{}]
          const defaultSkuInfo = res.data.defaultSkuInfo
          this.form.shopSpu.spuStorage = defaultSkuInfo ? defaultSkuInfo.spuStorage : null
          this.form.shopSpu.spuFreezeStorage = defaultSkuInfo && defaultSkuInfo.spuFreezeStorage !== null && defaultSkuInfo.spuFreezeStorage !== '' ? defaultSkuInfo.spuFreezeStorage : undefined
          this.form.shopSpu.skuReduceStorage = 1
          this.form.shopSpu.oldSkuId = defaultSkuInfo && defaultSkuInfo.skuId
          this.form.shopSpu.packageCode = defaultSkuInfo && defaultSkuInfo.packageCode
 
          this.form.categoryPropArray = res.data.spuProps.normalMetas || []
          const spuPropList = JSON.parse(res.data.spuInfo.spuPropList)
          this.form.categoryPropArray.forEach(item => {
            this.$set(item, 'temporaryId', null)
            this.$set(item, 'customPropValue', null)
            spuPropList.spuProps.forEach(itemProp => {
              if (item.productProp.propId === itemProp.propId) {
                item.temporaryId = itemProp.propValues[0].valuekey
                if ((item.productProp.propShow === '1' && item.temporaryId === 'null') || item.productProp.propShow === '0') {
                  item.temporaryId = null
                }
                item.customPropValue = itemProp.propValues[0].value
              }
            })
          })
          this.form.prodImgs = res.data.images.map(item => { return { url: item.imgUrl, uid: item.imgId } })
          if (res.data?.spuProps?.skuMetas) {
            res.data.spuProps.skuMetas.forEach(item => {
              item.checkList = []
              item.propsLable = []
            })
          }
          this.form.skuMetasArray = res.data?.spuProps?.skuMetas ? res.data.spuProps.skuMetas : []
          // this.form.prodSpu.spuUnit = this.form.skuMetasArray.length ? '瓶' : res.data.spuInfo.spuUnit
          this.form.tableLabel = ''
          this.form.skuMetasArray.forEach(item => {
            // this.form.tableLabel += item.productProp.propName + '/'
            item.propId = item.productProp.propId
            item.checkList = []
          })
          this.form.tableLabel = this.form.tableLabel.substring(0, this.form.tableLabel.length - 1)
 
          this.form.shopSpu.storageMinusType = res.data.defaultSkuInfo ? res.data.defaultSkuInfo.storageMinusType : null
          this.form.spuDetails[0].spuContent = res.data.details[0]?.spuContent
          this.showSpecifications = !this.form.skuMetasArray.length
          if (this.showSpecifications) {
            this.form.shopSpu.prodPrice.salePrice = res.data.defaultSkuInfo ? res.data.defaultSkuInfo.fixedPrice.salePrice : null
            this.form.shopSpu.prodPrice.listPrice = res.data.defaultSkuInfo ? res.data.defaultSkuInfo.fixedPrice.listPrice : null
            this.form.shopSpu.prodPrice.redLinePrice = res.data.defaultSkuInfo ? res.data.defaultSkuInfo.fixedPrice.redLinePrice : null
            this.isTip = !!(this.form.shopSpu.prodPrice.redLinePrice !== null && this.form.shopSpu.prodPrice.salePrice < this.form.shopSpu.prodPrice.redLinePrice)
          }
          if (this.form.prodSpu.spuType === '3' && res.data?.suiteQuerySpu) {
            this.inventedGroupDetails(res.data.suiteQuerySpu)
            this.showSpecifications = false
          }
          // 存在单品时
          if (this.form.skuMetasArray?.length) {
            this.getSkuMaintenance(res.data)
          }
        }
      })
    },
    // 虚拟组套详情
    inventedGroupDetails(data) {
      this.form.shopSpu.storageMinusType = data.storageMinusType
      this.form.shopSpu.spuStorage = data.spuStorage || 0
      this.form.shopSpu.spuFreezeStorage = data.spuFreezeStorage || 0
      this.form.shopSpu.prodPrice.salePrice = data.fixedPrice.salePrice || null
      this.form.shopSpu.prodPrice.listPrice = data.fixedPrice.listPrice || null
      data.suiteProds.forEach(item => {
        this.setSkuMetasTable(item)
      })
    },
    /**
     * 获取单品信息
     */
    getSkuMaintenance(productBaseInfo) {
      productListApi.getSkuMaintenance({ spuId: this.spuId }).then(res => {
        if (res.data) {
          res.data.shopSpus.forEach(item => {
            this.form.shopSpu.storageMinusType = item.storageMinusType
            this.form.shopSpu.spuStorage = item.spuStorage || 0
            this.form.shopSpu.spuFreezeStorage = item.spuFreezeStorage || 0
            item.prodSkus.forEach((itemProp, index) => {
              // 获取选中的单品属性
              const size = itemProp.skuPropValuesId.length
              this.form.skuMetasArray.forEach((skuItem, skuIndex) => {
                skuItem.propMetaValues.forEach((val) => {
                  for (let i = 0; i < size; i++) {
                    if (val.propValueId === itemProp.skuPropValuesId[i]) {
                      this.form.skuMetasArray[skuIndex].checkList.push(itemProp.skuPropValuesId[i])
                      this.form.skuMetasArray[skuIndex].propsLable.push(itemProp.skuPropValuesName[i])
                    }
                  }
                })
              })
              // 给第二阶段table赋值
 
              this.$refs.skuMetas.$nextTick(() => {
                this.$refs.skuMetas.showTable = true
                if (productBaseInfo.defaultSku && this.form.skuMetasArray.length) {
                  this.$refs.skuMetas.skuMetaForm.tableData = []
                } else {
                  if (this.form.prodSpu.spuType !== '3') {
                    this.setSkuMetasTable(itemProp)
                  }
                }
              })
            })
          })
          /**
           * 去除重复数据
           */
          this.form.skuMetasArray.forEach(item => {
            item.checkList = [...new Set(item.checkList)]
            item.propsLable = [...new Set(item.propsLable)]
          })
        }
      })
    },
    // 单品套组商品复制
    setSkuMetasTable(itemProp) {
      const _fixedPrice = itemProp.fixedPrice
      this.$refs.skuMetas.skuMetaForm.tableData.push({
        columnsText: itemProp.skuPropValuesName.join('/'),
        salePrice: itemProp.fixedPrice.salePrice,
        listPrice: itemProp.fixedPrice.listPrice,
        propValueId: itemProp.skuPropValuesId && itemProp.skuPropValuesId[0],
        fileList: itemProp.listProdImg ? itemProp.listProdImg.map(item => { return { url: item.imgUrl, id: item.imgId, imgNum: item.imgNum } }) : [],
        skuReduceStorage: itemProp.skuReduceStorage,
        packageCode: itemProp.packageCode,
        skuId: itemProp.skuId,
        spuNum: itemProp.spuNum,
        spuName: itemProp.spuName,
        spuTypeName: itemProp.spuTypeName,
        redLinePrice: itemProp.fixedPrice.redLinePrice,
        skuStorage: itemProp.listProdStorage ? itemProp.listProdStorage[0].skuStorage : 0,
        options: [{
          propValueId: itemProp.skuPropValuesId && itemProp.skuPropValuesId[0],
          propValue: itemProp.skuPropValuesName && itemProp.skuPropValuesName[0]
        }],
        isTip: !!(_fixedPrice.redLinePrice !== null && _fixedPrice.salePrice < _fixedPrice.redLinePrice)
        // skuFreezeStorage: itemProp.listProdStorage ? itemProp.listProdStorage[0].skuFreezeStorage : 0
      })
    },
    /**
     * 获取返回的级联数据
     */
    getCascader(data, val) {
      const arr = []
      for (const key in data) {
        if (!data[key]) {
          continue
        }
        if (val === 1) {
          arr.push(data[key].catId)
        } else {
          arr.push(data[key].catName)
          this.form.categoryArr = [data[key].catId]
        }
      }
      return arr
    },
    getContext(value) {
      this.form.spuDetails[0].spuContent = value
    },
    /**
     * 获取分类树
     */
    getCategory() {
      productCategoryApi.getList({ bizId: 'B02' }).then(res => {
        if (res.data) {
          this.categoryList = res.data
        }
      })
    },
    /**
     * 上一步
     */
    upStep() {
      this.showSkuMetas = false
    },
    /**
      * 下一步
      */
    nextStep() {
      const arr = JSON.parse(JSON.stringify(this.form.categoryArr))
      const cId = arr ? arr[0] : null
      this.getByCategoryProp(cId)
      this.getBrandByCategory(cId)
      this.getDisplayCategory()
      this.$refs.cascaderAddr.$nextTick(() => {
        this.form.prodSpu.cascaderLabel = this.$refs.cascaderAddr.presentText
        this.form.prodSpu.catId = cId
      })
    },
    /**
     *前往下一阶段
     */
    nextStepTwo() {
      this.form.spuDetails[0].spuContent = this.$refs.editor.getData()
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.showSkuMetas = true
        } else {
          this.$message({
            message: '请完善商品信息',
            type: 'warning'
          })
        }
      })
    },
    /**
     * 初始化表单
     */
    initForm() {
      this.form = {
        firstDisplay: '0',
        categoryArr: [], // 选中的品类
        prodSpu: {
          spuPriceCls: 1,
          spuLibraryType: '1',
          negativeStockType: '0',
          isRecommend: '0',
          spuUnit: null,
          hotProduct: null
        },
        shopSpu: {
          prodPrice: {
            listPrice: null,
            salePrice: null
          },
          // prodStorages: [{
          //   skuFreezeStorage: null,
          //   skuStorage: null
          // }],
          spuFreezeStorage: null,
          spuStorage: null,
          skuReduceStorage: 1,
          storageMinusType: '0'
        },
        spuDetails: [{
          spuContent: null,
          spuShowType: '2'
        }],
        prodImgs: [],
        categoryPropArray: [], // 属性数组
        skuMetasArray: [] // 单品数组
      }
      this.catIdSaleArray = []
 
      this.$nextTick(() => {
        this.$refs.skuMetas.initTable()
        this.$refs.form.clearValidate()
      })
    },
    /**
      * 重新选择品类
      */
    againChoice() {
      this.showCategory = true
    },
    /**
     * 选择展示分类
     */
    handleDisplayCategory(val) {
      // if (val.length > 0) {
      //   this.form.prodSpu.catIdSale = val[val.length - 1]
      // } else {
      //   this.form.prodSpu.catIdSale = null
      // }
    },
    /**
      * 选择品类
      */
    handleChange(val) {
      if (this.pageTag === 'add' || (this.pageTag === 'edit' && this.form.prodSpu.spuType === '3')) {
        this.initFormData()
        if (val.length) {
          this.nextStep()
        }
      }
    },
    /**
 * 品类选中项改变---部分数据初始化
 */
    initFormData() {
      this.form.categoryPropArray = []
      this.showCategory = false
      this.showSpecifications = false
      this.form.skuMetasArray = []
      // 商品品牌
      this.form.prodSpu.brandId = null
      this.brandArray = []
      // 展示分类
      this.catIdSaleArray = []
      // this.displayCategoryArray = []
      // 计量单位
      this.form.prodSpu.spuUnit = null
      this.$refs.cascaderAddr.$nextTick(() => {
        this.form.prodSpu.cascaderLabel = null
        this.form.prodSpu.catId = null
      })
      this.$nextTick(() => {
        this.$refs.form.clearValidate(['prodSpu.brandId', 'prodSpu.spuUnit'])
      })
    },
    /**
     * 选择品牌时
     */
    getBrandLabel(val) {
      const data = this.brandArray.find(item => {
        if (item.brandId === val) {
          return item
        }
      })
      if (data) {
        this.$set(this.form.prodSpu, 'brandName', data.brandName)
      }
    },
    /**
     * 通过商品
     */
    getBrandByCategory(categoryId) {
      productCategoryApi.getCategoryBrandList({ categoryId }).then(res => {
        if (res.data) {
          this.brandArray = res.data
        }
      })
    },
    /**
     * 获取展示品类
     */
    getDisplayCategory() {
      productExhibitionApi.getList({ bizId: 'B02' }).then(res => {
        if (res.data) {
          this.displayCategoryArray = res.data
        }
      })
    },
    /**
     * 通过分类获取产品属性
     */
    getByCategoryProp(catId) {
      productCategoryApi.getByCategoryProp({ catId }).then(res => {
        // if (!res.data.normalMetas) {
        //   this.$message({
        //     type: 'info',
        //     message: ' 此品类暂无商品属性,请重新选择!'
        //   })
        //   return
        // }
        this.form.categoryPropArray = res.data.normalMetas
        if (res.data.skuMetas) {
          res.data.skuMetas.forEach(item => {
            item.checkList = []
          })
        }
        // skuMetas为null非单品,不为null为单品
        this.form.skuMetasArray = res.data.skuMetas ? res.data.skuMetas : []
        this.showCategory = false
        this.showSpecifications = !res.data.skuMetas
        this.form.prodSpu.spuUnit = res.data.skuMetas ? '瓶' : null
        // 品类发生改变,非单品并且主编码存在的情况下这里需要调用获取红线价格的接口
        if (this.form.skuMetasArray.length === 0 && this.form.prodSpu.spuNum) {
          this.getNotSingleRedLinePrice(this.form.prodSpu.spuNum)
        }
      })
    },
    /**
     * 处理表单数据
     */
    handFormData() {
      let formData = {}
      const { spuDetails, shopSpu } = this.form
      const arr = JSON.parse(JSON.stringify(this.form.categoryArr))
      formData = { spuDetails, shopSpu }
      formData.prodSpu = JSON.parse(JSON.stringify(this.form.prodSpu))
      formData.prodSpu.catId = arr ? arr[0] : null
      formData.prodSpu.catIdSaleList = this.catIdSaleArray.map(item => item[item.length - 1])
      if (this.form.firstDisplay === '0') formData.prodSpu.hotProduct = '0'
      formData.prodImgs = this.form.prodImgs.map((item, index) => { return { imgId: item.uid, imgNum: index + 1, imgUrl: item.url } })
      formData.spuProps = []
      this.form.categoryPropArray.map(item => {
        if (((!item.productProp.propShow || item.productProp.propShow === '1') && item.temporaryId) || (item.productProp.propShow === '0' && item.customPropValue)) {
          formData.spuProps.push({
            metaValues: [{ propValueId: item.temporaryId ? item.temporaryId : 'null', customPropValue: item.customPropValue }],
            propCustom: '0',
            propId: item.productProp.propId,
            propName: item.productProp.propName
          })
        }
      })
      return formData
    },
    /**
     * 当是商品时
     */
    productSave() {
      let resDate = null
      if (this.spuId) {
        resDate = productListApi.updateInfo(this.handFormData())
      } else {
        resDate = productListApi.addInfo(this.handFormData())
      }
      return resDate
    },
    /**
     *提交
     */
    submit() {
      this.form.shopSpu.storageMinusType = '0'
      this.form.spuDetails[0].spuContent = this.$refs.editor.getData()
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.loading = true
          if (this.form.prodSpu.spuType === '3') {
            this.inventedGroupEdit()
          } else {
            if (this.form.skuMetasArray.length) {
              this.hasSkuMetas()// 当是单品时
            } else {
              // 当是商品时
              this.productSave().then(res => {
                if (res.data) {
                  this.$message({
                    message: '操作成功',
                    type: 'success'
                  })
                  this.loading = false
                  this.$router.push({ name: 'productList' })
                  this.$parent.queryList()
                } else {
                  this.loading = false
                }
              }).catch(() => {
                this.loading = false
              })
            }
          }
        } else {
          this.loading = false
          this.$message({
            message: '请完善商品信息',
            type: 'warning'
          })
        }
      })
    },
    /**
     * 第一阶段发布
     */
    firstPublish() {
      return new Promise(resolve => {
        let resUrl = null
        if (this.spuId) {
          resUrl = productListApi.skuSaveInfoFirst(this.handFormData())
        } else {
          resUrl = productListApi.skuAddInfoFirst(this.handFormData())
        }
        resUrl.then(res => {
          if (res.data) {
            resolve(res.data)
          } else {
            this.loading = false
          }
        }).catch(() => {
          this.loading = false
        })
      })
    },
    /**
     * 第二阶段发布
     */
    twoPublish(spuId) {
      if (!this.$refs.skuMetas.skuMetaForm.tableData.length) {
        this.$message({
          message: '请选择以上商品属性(至少选择一种属性)',
          type: 'info'
        })
        this.loading = false
        return
      }
      let resDate = null
      resDate = this.$refs.skuMetas.handFormData()
      resDate.spuId = spuId
      const prodSpu = this.form.prodSpu
      resDate.spuName = prodSpu.spuName
      resDate.spuNum = prodSpu.spuNum
      productListApi.skuAddInfoTwo(resDate).then(res => {
        if (res.data) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.loading = false
          this.$router.push({ name: 'productList' })
          this.$parent.queryList()
        } else {
          this.loading = false
        }
      }).catch(() => {
        this.loading = false
      })
    },
    // 编辑虚拟组套商品
    async inventedGroupEdit() {
      this.loading = true
      const res = await productListApi.inventedGroupEdit(this.handFormData())
      if (res.data) {
        this.$message({
          message: '操作成功',
          type: 'success'
        })
        this.loading = false
        this.$router.push({ name: 'productList' })
        // this.$parent.queryList()
      }
    },
    /**
     * 当是单品属性时
     */
    hasSkuMetas() {
      this.$refs.skuMetas.$refs.skuMetaForm.validate().then(async (res) => {
        this.loading = true
        const p = await this.firstPublish()
        await this.twoPublish(p)
      }).catch(res => {
        this.loading = false
        this.$message({
          message: '请完善单品信息',
          type: 'warning'
        })
      })
    },
    /**
     * 取消
     */
    cancel() {
      this.$router.push({ name: 'productList' })
    }
  }
}
</script>
<style lang="scss">
.inputTip {
  border: 1px solid #d70012;
  border-radius: 4px;
}
.itemTip {
  margin-bottom: 15px;
  margin-left: 52px;
}
.el-scrollbar .el-autocomplete-suggestion__list {
  .content {
    font-size: 12px;
    .exist {
      color: red;
    }
  }
  li:has(.is-disabled) {
    pointer-events: none;
  }
  .is-disabled {
    cursor: not-allowed;
    color: #c0c4cc;
  }
}
 
.form {
  padding: 20px;
}
.product {
  .el-select {
    width: 100%;
  }
  .buttonPosition {
    text-align: center;
  }
  // p{
  //     border-bottom:1px solid #000000;
  //     font-weight: bold;
  //     font-size: 20px;
  //     padding-bottom: 10px;
  //  }
  .category {
    margin-bottom: 20px;
  }
  .el-cascader {
    width: 100%;
  }
  .formBlock {
    border-bottom: 1px solid #cccccc;
    margin-top: 20px;
    padding-bottom: 10px;
    margin-bottom: 20px;
  }
  .categoryPropStyle {
    width: 50%;
    display: inline-block;
  }
  .content {
    width: 100%;
    max-height: 600px;
    border: 1px solid #cccccc;
    padding: 25px;
    overflow-y: auto;
    overflow-x: hidden;
    .image,
    .video {
      text-align: center;
    }
    img,
    video {
      width: auto;
      height: auto;
      max-width: 100%;
    }
    div,
    p {
      width: 100% !important;
    }
  }
}
</style>