AddGoodsOneStore.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. <template>
  2. <view class="add-goods">
  3. <u-form :model="form" ref="goodsForm" label-width="160">
  4. <view class="form-title">基本信息</view>
  5. <view class="form-cont">
  6. <u-form-item required label="商品相册" label-position="top"><upload :images="form.images" @handleRemove="imgRemove" @uploadSuccess="uploadSuccess" /></u-form-item>
  7. <u-form-item required label="商品名称"><u-input input-align="right" v-model="form.title" /></u-form-item>
  8. <u-form-item required label="商品分类">
  9. <view class="form-main" @click="openSel('cate_show')">
  10. <text v-if="category_name">{{ category_name }}</text>
  11. <text class="input-pl" v-else>请选择商品分类</text>
  12. </view>
  13. <view slot="right"><u-icon name="arrow-down-fill" size="24"></u-icon></view>
  14. </u-form-item>
  15. <u-form-item label="商品品牌">
  16. <view class="form-main" @click="goPage('/pagesT/brand/selBrand')">
  17. <text v-if="brand_name">{{ brand_name }}</text>
  18. <text class="input-pl" v-else>请选择品牌</text>
  19. </view>
  20. <view slot="right"><u-icon name="arrow-down-fill" size="24"></u-icon></view>
  21. </u-form-item>
  22. <u-form-item label="商品卖点"><u-input input-align="right" v-model="form.describe" /></u-form-item>
  23. <u-form-item label="抄码商品">
  24. <view class="form-value">
  25. <u-switch style="transform: translateY(14rpx);" @change="switchChange" v-model="isEq" :active-value="5" :inactive-value="4" size="40"></u-switch>
  26. </view>
  27. </u-form-item>
  28. <u-form-item label="负库存销售">
  29. <view class="form-value">
  30. <u-switch
  31. style="transform: translateY(14rpx);"
  32. @change="distributionChange"
  33. v-model="isDistribution"
  34. :active-value="5"
  35. :inactive-value="4"
  36. size="40"
  37. ></u-switch>
  38. </view>
  39. </u-form-item>
  40. <u-form-item label="是否上架">
  41. <view class="form-value">
  42. <u-switch
  43. style="transform: translateY(14rpx);"
  44. @change="enableStatusChange"
  45. v-model="enableStatus"
  46. :active-value="5"
  47. :inactive-value="4"
  48. size="40"
  49. ></u-switch>
  50. </view>
  51. </u-form-item>
  52. <u-form-item label="保质期">
  53. <u-input input-align="right" v-model="form.expireTime" />
  54. <view slot="right">天</view>
  55. </u-form-item>
  56. <u-form-item label="关键词" label-position="top">
  57. <view class="top-value">
  58. <u-tag class="tag-li" v-for="(item, index) in form.tag" :key="index" :text="item" closeable type="primary" @close="deletTag(index)" />
  59. <u-button size="mini" @click="openSel('tag_show')">
  60. <u-icon name="plus" margin-right="20"></u-icon>
  61. 新增
  62. </u-button>
  63. </view>
  64. </u-form-item>
  65. </view>
  66. <view class="form-title">规格明细</view>
  67. <view class="form-cont">
  68. <u-form-item required label="基本单位">
  69. <view class="form-main" @click="openSel('m_unit_show')">
  70. <text v-if="master_unit">{{ master_unit }}</text>
  71. <text class="input-pl" v-else>请选择基本单位</text>
  72. </view>
  73. <view slot="right"><u-icon name="arrow-down-fill" size="24"></u-icon></view>
  74. </u-form-item>
  75. <u-form-item label="辅助单位" label-position="top">
  76. <view class="top-value">
  77. <block v-for="(item, index) in form.unitData" :key="index">
  78. <u-tag
  79. class="tag-li"
  80. v-if="item.isMaster === 4"
  81. :text="'1' + item.unitName + '=' + item.conversion + master_unit"
  82. :closeable="isEditSpec === 5 || isEq"
  83. type="primary"
  84. @close="deletUnit(index, item.unitName)"
  85. />
  86. </block>
  87. <u-button v-if="!isEq || (isEq && form.unitData.length < 1)" size="mini" @click="openSel('unit_show')">
  88. <u-icon name="plus" margin-right="20"></u-icon>
  89. 新增
  90. </u-button>
  91. </view>
  92. </u-form-item>
  93. <u-form-item label="商品规格">
  94. <view @click="editSku" slot="right" style="font-size: 28rpx; color: #007AFF;">
  95. <u-icon name="edit-pen" size="28"></u-icon>
  96. <text style="margin-left: 10rpx;">编辑</text>
  97. </view>
  98. </u-form-item>
  99. </view>
  100. <view class="form-title">物流设置</view>
  101. <view class="form-cont">
  102. <u-form-item label="快递运费">
  103. <view class="form-main" @click="openSel('expressType_show')">
  104. <text v-if="expressType_name">{{ expressType_name }}</text>
  105. <text class="input-pl" v-else>请选择</text>
  106. </view>
  107. <view slot="right"><u-icon name="arrow-down-fill" size="24"></u-icon></view>
  108. </u-form-item>
  109. <u-form-item label="运费模版" v-if="form.expressType === 2">
  110. <view class="form-main" @click="openSel('template_show')">
  111. <text v-if="template_name">{{ template_name }}</text>
  112. <text class="input-pl" v-else>请选择</text>
  113. </view>
  114. <view slot="right"><u-icon name="arrow-down-fill" size="24"></u-icon></view>
  115. </u-form-item>
  116. <u-form-item label="统一运费" v-if="form.expressType === 3">
  117. <u-input input-align="right" v-model="form.expressFee" />
  118. <view slot="right">元</view>
  119. </u-form-item>
  120. </view>
  121. <view class="form-title">商品详情</view>
  122. <view class="form-cont"><editorW :html="form.description" @editInput="editInput"></editorW></view>
  123. </u-form>
  124. <view class="submit-btn"><u-button class="handel-btn" @click="submit" :loading="sub_load" :ripple="true" type="primary">提交发布</u-button></view>
  125. <u-popup v-model="tag_show" border-radius="10" mode="center">
  126. <view class="pop-model">
  127. <view class="pop-tit">新增关键词</view>
  128. <input :focus="true" type="text" confirm-type="done" @confirm="tagConfirm" placeholder-class="input-pl" placeholder="请输入" v-model="tag_key" />
  129. <u-button type="primary" size="medium" @click="tagConfirm">确定</u-button>
  130. </view>
  131. </u-popup>
  132. <u-popup v-model="unit_show" mode="center" border-radius="10">
  133. <view class="pop-model">
  134. <view class="pop-tit">新增辅助单位</view>
  135. <view class="unit-model-main">
  136. <text>1</text>
  137. <view class="sel-view" @click="openSel('fz_unit_show')">
  138. <text v-if="pop_unit_obj.label">{{ pop_unit_obj.label }}</text>
  139. <text class="input-pl" v-else>请选择</text>
  140. </view>
  141. =
  142. <input class="uni-num-input" type="digit" v-model="conversion" />
  143. <text>{{ master_unit }}</text>
  144. </view>
  145. <view class="confirm-btn" @click="unitPopConfirm">确定</view>
  146. </view>
  147. </u-popup>
  148. <tki-tree ref="tkitree" :selectParent="true" :range="cate_list" rangeKey="title" @confirm="cateConfirm"></tki-tree>
  149. <u-select v-model="m_unit_show" mode="single-column" value-name="id" label-name="unitName" :list="unit_options" @confirm="unitConfirm"></u-select>
  150. <u-select z-index="10080" v-model="fz_unit_show" mode="single-column" value-name="id" label-name="unitName" :list="unit_options" @confirm="unitPopSelConfirm"></u-select>
  151. <u-select v-model="expressType_show" @confirm="expressTypeConfirm" :list="expressType_list"></u-select>
  152. <!-- 运费模版 -->
  153. <u-select v-model="template_show" @confirm="templateConfirm" label-name="title" value-name="id" :list="express_list"></u-select>
  154. </view>
  155. </template>
  156. <script>
  157. import editorW from '@/components/editor/editor.vue';
  158. import upload from '@/components/qiniu/QiniuUpload.vue';
  159. import tkiTree from '@/components/tki-tree/tki-tree.vue';
  160. const priceDataLi = {
  161. conversion: 0,
  162. unitName: '',
  163. unitId: 0,
  164. isMaster: 5,
  165. enabledLadder: 0,
  166. salePriceAreaType: 1,
  167. salePrice: 0,
  168. ladderPrice: [],
  169. marketPrice: 0,
  170. memberPrice: '',
  171. setNum: 1,
  172. specImage: '',
  173. barCode: '',
  174. weight: ''
  175. };
  176. export default {
  177. components: { editorW, upload, tkiTree },
  178. data() {
  179. return {
  180. sub_load: false,
  181. express_list: [],
  182. expressType_show: false,
  183. template_show: false,
  184. expressType_name: '包邮',
  185. isEq: false,
  186. isDistribution: false,
  187. enableStatus: true,
  188. shopData: '',
  189. conversion: '', //辅助单位换算比例
  190. master_unit: '', //基本单位
  191. pop_unit_obj: {}, // 弹窗辅助单位
  192. tag_show: false, //新增关键词弹窗
  193. tag_key: '', // 新增关键词
  194. brandData: {}, //品牌数据
  195. brand_name: '', //品牌名称
  196. category_name: '', //分类名称
  197. unit_options: [], //计量单位
  198. copy_unit_options: [], //计量单位
  199. expressType_list: [
  200. {
  201. label: '包邮',
  202. value: 1
  203. },
  204. {
  205. label: '运费模版',
  206. value: 2
  207. },
  208. {
  209. label: '统一运费',
  210. value: 3
  211. }
  212. ],
  213. unit_show: false, // 新增辅助弹窗
  214. cate_show: false, // 商品分类弹窗
  215. m_unit_show: false, // 单位弹窗
  216. fz_unit_show: false,
  217. brand_list: [],
  218. cate_list: [],
  219. isEditSpec: 5, // 5 表示此商品从未采购过,允许用户随意编辑单位和属性;4 表示商品已经采购过,隐藏添加属性按钮,避免skuid重组
  220. form: {
  221. merchantId: '',
  222. assistCategoryPath: [],
  223. assistCategoryId: '',
  224. delUnitIds: [],
  225. delSpecSkuIds: [],
  226. createUserName: '',
  227. isDistribution: '',
  228. isShield: '',
  229. deliverySupIds: '',
  230. expressType: '', //运费模版
  231. expressFee: '', // 统一运费
  232. showExpress: '',
  233. ruleId: '',
  234. notArea: [],
  235. notCustomerType: '',
  236. notCustomer: '',
  237. title: '', //商品名称
  238. storage: '', //货架编码
  239. specType: 1, // 是否启用多规格 1单规格 2多规格
  240. specGroup: [], //多规格数据
  241. specMultiple: [], //多规格明细
  242. unitData: [], //计量单位
  243. describe: '', //商品卖点
  244. code: '', //商品code
  245. barCode: '', //商品条码
  246. weight: '', //商品重量
  247. categoryId: '', //分类ID
  248. categoryPath: '', //分类路径
  249. expireTime: '', //保质期
  250. brandId: '', //品牌ID
  251. tag: [], //关键词
  252. description: '', //商品详情
  253. noSalesShop: '', //不销售店铺ID
  254. images: [], //商品图片
  255. enableStatus: 5, //是否上架
  256. isStore: false, //是否是商户后台上传商品
  257. isEq: 4 //超码商品 4否 5是
  258. }
  259. };
  260. },
  261. watch: {
  262. brandData(val) {
  263. if (val.id) {
  264. this.form.brandId = val.id;
  265. this.brand_name = val.title;
  266. }
  267. }
  268. },
  269. onLoad(options) {
  270. this.getAllExpressRule()
  271. if (options.id) {
  272. this.goods_id = options.id;
  273. this.getQuickGoodsInfo();
  274. uni.setNavigationBarTitle({
  275. title: '编辑商品'
  276. });
  277. }
  278. this.getAllCategory();
  279. this.getAllUnit();
  280. },
  281. methods: {
  282. //抄码商品
  283. switchChange(val) {
  284. this.form.isEq = val;
  285. },
  286. // 负库存销售
  287. distributionChange(val) {
  288. this.form.isDistribution = val;
  289. },
  290. // 是否上架
  291. enableStatusChange(val) {
  292. this.form.enableStatus = val;
  293. },
  294. templateConfirm(arr) {
  295. this.template_name = arr[0].label;
  296. this.form.ruleId = arr[0].value;
  297. },
  298. expressTypeConfirm(arr) {
  299. this.expressType_name = arr[0].label;
  300. this.form.expressType = arr[0].value;
  301. },
  302. //运费模版
  303. getAllExpressRule() {
  304. this.$u.api.getAllExpressRule().then(res => {
  305. this.express_list = res.data;
  306. });
  307. },
  308. cateConfirm(arr) {
  309. this.category_name = arr[0].title;
  310. this.form.categoryId = arr[0].id;
  311. if (arr[0].parents.length) {
  312. this.form.categoryPath = arr[0].parents.map(item => item.id).join(',') + ',' + arr[0].id;
  313. } else {
  314. this.form.categoryPath = arr[0].id;
  315. }
  316. },
  317. editInput(val) {
  318. this.form.description = val;
  319. },
  320. // 获取商品详情
  321. getQuickGoodsInfo() {
  322. this.$u.api.getQuickGoodsInfo(this.goods_id).then(res => {
  323. const data = res.data;
  324. this.category_name = data.categoryName;
  325. this.brand_name = data.brandName;
  326. this.isDistribution = data.isDistribution === 5;
  327. this.isEq = data.isEq === 5;
  328. this.enableStatus = data.enableStatus === 5;
  329. this.master_unit = data.unitData.find(item => item.isMaster === 5).unitName;
  330. const expressTypeData = this.expressType_list.find(item => item.value === data.expressType);
  331. this.expressType_name = expressTypeData ? expressTypeData.label : '';
  332. if (data.expressType === 2) {
  333. this.template_name = this.express_list.find(item => item.id === data.ruleId).title;
  334. }
  335. this.form = {
  336. basicGoodsId: data.basicGoodsId,
  337. merchantId: data.merchantId,
  338. assistCategoryPath: data.assistCategoryPath,
  339. assistCategoryId: data.assistCategoryId,
  340. delUnitIds: data.delUnitIds,
  341. delSpecSkuIds: data.delSpecSkuIds,
  342. createUserName: data.createUserName,
  343. isDistribution: data.isDistribution,
  344. isShield: data.isShield,
  345. deliverySupIds: data.deliverySupIds,
  346. expressType: data.expressType,
  347. expressFee: data.expressFee,
  348. showExpress: data.showExpress,
  349. ruleId: data.ruleId,
  350. notArea: data.notArea,
  351. notCustomerType: data.notCustomerType,
  352. notCustomer: data.notCustomer,
  353. title: data.title,
  354. storage: data.storage,
  355. specType: data.specType,
  356. specGroup: data.specGroup,
  357. specMultiple: data.specMultiple,
  358. unitData: data.unitData.map(item => {
  359. return {
  360. id: item.id,
  361. unitName: item.unitName,
  362. isMaster: item.isMaster,
  363. unitId: item.unitId,
  364. conversion: item.conversion || 0
  365. };
  366. }),
  367. describe: data.describe,
  368. code: data.code,
  369. barCode: data.barCode,
  370. weight: data.weight,
  371. categoryId: data.categoryId,
  372. categoryPath: data.categoryPath,
  373. expireTime: data.expireTime,
  374. brandId: data.brandId,
  375. tag: data.tag.filter(item => !!item),
  376. description: data.description,
  377. noSalesShop: data.noSalesShop,
  378. images: data.images,
  379. enableStatus: data.enableStatus,
  380. isStore: data.isStore,
  381. isEq: data.isEq
  382. };
  383. console.log(this.form);
  384. });
  385. },
  386. //基本单位选择
  387. unitConfirm(arr) {
  388. // 检查辅助单位是否包含当前选择的单位
  389. const isFu = this.form.unitData.find(item => item.unitName === arr[0].label);
  390. if (!!isFu) {
  391. this.$u.toast('基本单位不能与辅助单位用同一个');
  392. return;
  393. }
  394. this.master_unit = arr[0].label;
  395. const index = this.form.unitData.findIndex(item => item.isMaster === 5);
  396. const unit = {
  397. isMaster: 5,
  398. isDefault: 5,
  399. isNew: 5,
  400. specType: 1,
  401. barCode: '',
  402. weight: '',
  403. unitName: arr[0].label,
  404. unitId: arr[0].value
  405. };
  406. if (index === -1) {
  407. this.form.unitData.push(unit);
  408. } else {
  409. this.form.unitData[index] = {
  410. ...this.form.unitData[index],
  411. ...unit
  412. };
  413. }
  414. const skuIndex = this.form.specMultiple.findIndex(item => item.isMaster === 5);
  415. if (skuIndex > -1) {
  416. this.form.specMultiple[skuIndex].unitId = arr[0].value;
  417. this.form.specMultiple[skuIndex].unitName = arr[0].label;
  418. this.form.specMultiple[skuIndex].salePrice = {
  419. ...this.form.specMultiple[skuIndex].salePrice,
  420. unitName: arr[0].label,
  421. unitId: arr[0].value
  422. };
  423. }
  424. },
  425. editSku() {
  426. if (!this.master_unit) {
  427. this.$u.toast('请先选择基本单位');
  428. return;
  429. }
  430. let obj = [];
  431. if (this.form.specMultiple.length) {
  432. obj = this.form.specMultiple;
  433. } else {
  434. obj = this.form.unitData;
  435. }
  436. // console.log(obj)
  437. // console.log(this.form.specType);
  438. // return
  439. if (this.form.specType === 1) {
  440. this.goPage('/pages/goods/SkuOneStore?specType=' + this.form.specType + '&unitData=' + JSON.stringify(obj));
  441. } else {
  442. this.goPage(
  443. '/pages/goods/SkuOneStore?specType=' +
  444. this.form.specType +
  445. '&unitData=' +
  446. JSON.stringify(this.form.unitData) +
  447. '&specMultiple=' +
  448. JSON.stringify(this.form.specMultiple) +
  449. '&specGroup=' +
  450. JSON.stringify(this.form.specGroup)
  451. );
  452. }
  453. },
  454. openSel(key) {
  455. if (key === 'unit_show') {
  456. if (!this.master_unit) {
  457. this.$u.toast('请先选择基本单位');
  458. return;
  459. }
  460. } else if (key === 'cate_show') {
  461. this.$refs.tkitree._show();
  462. return;
  463. } else if (key === 'm_unit_show') {
  464. if (this.isEditSpec === 4) {
  465. return;
  466. }
  467. // 抄码商品主单位只能选择KG
  468. if (this.isEq) {
  469. this.unit_options = this.copy_unit_options.filter(item => item.unitName === 'KG');
  470. } else {
  471. this.unit_options = this.$u.deepClone(this.copy_unit_options);
  472. }
  473. } else if (key === 'fz_unit_show') {
  474. if (this.isEq) {
  475. this.unit_options = this.copy_unit_options.filter(item => item.unitName === '件');
  476. } else {
  477. this.unit_options = this.$u.deepClone(this.copy_unit_options);
  478. }
  479. }
  480. this[key] = true;
  481. },
  482. // 新增关键词确定
  483. tagConfirm() {
  484. this.tag_show = false;
  485. this.form.tag.push(this.tag_key);
  486. this.tag_key = '';
  487. },
  488. deletTag(index) {
  489. this.form.tag.splice(index, 1);
  490. },
  491. deletShop(index) {
  492. this.no_sales_shop.splice(index, 1);
  493. },
  494. // 图片上传成功
  495. uploadSuccess(imgUrl) {
  496. this.form.images.push(imgUrl);
  497. },
  498. //移除图片
  499. imgRemove(arr) {
  500. this.form.images = arr;
  501. },
  502. // 获取所有商品分类
  503. getAllCategory() {
  504. this.$u.api
  505. .getAllCategory({
  506. enableStatus: 5
  507. })
  508. .then(res => {
  509. this.cate_list = res.data;
  510. });
  511. },
  512. reduceCate(list) {
  513. list.forEach(item => {
  514. if (!item.children) {
  515. item.children = [
  516. {
  517. id: '',
  518. title: '全部'
  519. }
  520. ];
  521. } else {
  522. item.children = this.reduceCate(item.children);
  523. }
  524. });
  525. return list;
  526. },
  527. getAllUnit() {
  528. this.$u.api
  529. .getAllUnit({
  530. page: 1,
  531. pageSize: 99
  532. })
  533. .then(res => {
  534. // 备份一份单位数据
  535. this.copy_unit_options = this.$u.deepClone(res.data);
  536. this.unit_options = res.data;
  537. });
  538. },
  539. // 辅助单位选择
  540. unitPopSelConfirm(arr) {
  541. if (arr[0].label === this.master_unit) {
  542. this.$u.toast('辅助单位不能与基本单位用同一个');
  543. return;
  544. }
  545. const index = this.form.unitData.findIndex(item => item.unitName === arr[0].label);
  546. if (index > -1) {
  547. this.$u.toast('该单位已被选择');
  548. return;
  549. }
  550. this.pop_unit_obj = arr[0];
  551. },
  552. // 辅助单位确定
  553. unitPopConfirm() {
  554. if (!this.conversion) {
  555. this.$u.toast('请输入换算比例');
  556. return;
  557. }
  558. this.form.unitData.push({
  559. unitName: this.pop_unit_obj.label,
  560. isMaster: 4,
  561. unitId: this.pop_unit_obj.value,
  562. conversion: this.conversion
  563. });
  564. if (this.form.specType === 1) {
  565. this.form.specMultiple = this.form.unitData.map(item => {
  566. return {
  567. unitName: item.unitName,
  568. isMaster: item.isMaster,
  569. isSale: 5,
  570. isDefault: 4,
  571. unitId: item.unitId,
  572. conversion: item.conversion || 0,
  573. specImage: '',
  574. specGroup: [],
  575. salePrice: {
  576. unitName: item.unitName,
  577. isMaster: item.isMaster,
  578. unitId: item.unitId,
  579. conversion: item.conversion || 0,
  580. deleteStatus: 4,
  581. enabledLadder: 0,
  582. salePriceAreaType: 1,
  583. salePrice: 0,
  584. ladderPrice: [],
  585. marketPrice: 0,
  586. memberPrice: '',
  587. setNum: 1
  588. }
  589. };
  590. });
  591. } else {
  592. const skuArr = this.form.specMultiple.filter(item => item.isMaster === 5);
  593. const fuskuArr = skuArr.map(item => {
  594. return {
  595. unitName: this.pop_unit_obj.label,
  596. isMaster: 4,
  597. isSale: 5,
  598. isDefault: 4,
  599. unitId: this.pop_unit_obj.value,
  600. conversion: this.conversion,
  601. specImage: '',
  602. specGroup: item.specGroup,
  603. salePrice: {
  604. unitName: this.pop_unit_obj.label,
  605. isMaster: 4,
  606. unitId: this.pop_unit_obj.value,
  607. conversion: this.conversion,
  608. deleteStatus: 4,
  609. enabledLadder: 0,
  610. salePriceAreaType: 1,
  611. salePrice: 0,
  612. ladderPrice: [],
  613. marketPrice: 0,
  614. memberPrice: '',
  615. setNum: 1
  616. }
  617. };
  618. });
  619. this.form.specMultiple = this.form.specMultiple.concat(fuskuArr);
  620. }
  621. // 重置弹窗数据
  622. this.unit_show = false;
  623. this.conversion = '';
  624. this.pop_unit_obj = {};
  625. },
  626. deletUnit(index, unitName) {
  627. this.form.unitData.splice(index, 1);
  628. this.form.specMultiple.forEach((item, index) => {
  629. if (item.unitName === unitName) {
  630. this.form.specMultiple.splice(index, 1);
  631. }
  632. });
  633. },
  634. submit() {
  635. if (!this.form.images.length) {
  636. this.$u.toast('请至少选择一张商品图片');
  637. return;
  638. }
  639. if (!this.form.title) {
  640. this.$u.toast('请输入商品名称');
  641. return;
  642. }
  643. if (!this.form.categoryId) {
  644. this.$u.toast('请选择商品分类');
  645. return;
  646. }
  647. if (!this.form.unitData.length) {
  648. this.$u.toast('请选择基本单位');
  649. return;
  650. }
  651. if (!this.form.specMultiple || !this.form.specMultiple.length) {
  652. this.$u.toast('请编辑商品规格');
  653. return;
  654. }
  655. // 检查规格里面的销售价是不是为0
  656. let isSalePrice = true;
  657. for (let i in this.form.specMultiple) {
  658. let item = this.form.specMultiple[i];
  659. if (!item.salePrice.salePrice || item.salePrice.salePrice <= 0) {
  660. const skuName = item.specGroup.map(sku => sku.specValueName).join(';');
  661. this.$u.toast(`规格【${item.unitName + ';' + skuName}】的销售价必须大于0`);
  662. isSalePrice = false;
  663. break;
  664. }
  665. }
  666. if (!isSalePrice) {
  667. return;
  668. }
  669. // 编辑页面清楚ID
  670. this.form.specMultiple.map(item => {
  671. if (item.id) {
  672. delete item.id;
  673. }
  674. return item;
  675. });
  676. // 做延迟处理是为了获取富文本框中的值
  677. setTimeout(() => {
  678. this.sub_load = true;
  679. if (this.goods_id) {
  680. this.$u.api
  681. .editQuickGoods({
  682. ...this.form,
  683. id: this.goods_id,
  684. tag: this.form.tag ? this.form.tag.join(',') : ''
  685. })
  686. .then(res => {
  687. this.sub_load = false;
  688. this.$u.toast('修改成功');
  689. setTimeout(() => {
  690. uni.navigateBack();
  691. }, 2000);
  692. })
  693. .catch(err => {
  694. this.sub_load = false;
  695. });
  696. } else {
  697. this.$u.api
  698. .addBasicAndPublishGoods({ ...this.form, tag: this.form.tag ? this.form.tag.join(',') : '' })
  699. .then(res => {
  700. this.sub_load = false;
  701. this.$u.toast('新增成功');
  702. setTimeout(() => {
  703. uni.navigateBack();
  704. }, 2000);
  705. })
  706. .catch(err => {
  707. this.sub_load = false;
  708. });
  709. }
  710. }, 200);
  711. }
  712. }
  713. };
  714. </script>
  715. <style scoped lang="scss">
  716. .add-goods {
  717. padding-bottom: 120rpx;
  718. .form-title {
  719. line-height: 90rpx;
  720. font-weight: 700;
  721. padding: 0 24rpx;
  722. }
  723. .form-cont {
  724. padding: 0 24rpx;
  725. background-color: #ffffff;
  726. .form-value {
  727. text-align: right;
  728. width: 100%;
  729. }
  730. .top-value {
  731. text-align: left;
  732. width: 100%;
  733. }
  734. .form-main {
  735. text-align: right;
  736. .input-pl {
  737. color: #c0c4cc;
  738. font-size: 28rpx;
  739. }
  740. }
  741. }
  742. }
  743. .pop-model {
  744. padding: 0 30rpx 20rpx;
  745. text-align: center;
  746. input {
  747. border: 1px solid #f5f5f5;
  748. line-height: 70rpx;
  749. height: 70rpx;
  750. margin-bottom: 20rpx;
  751. }
  752. .pop-tit {
  753. line-height: 70rpx;
  754. }
  755. .confirm-btn {
  756. width: 80%;
  757. display: block;
  758. background-color: $uni-color-primary;
  759. text-align: center;
  760. color: #ffffff;
  761. line-height: 70rpx;
  762. height: 70rpx;
  763. border-radius: 10rpx;
  764. margin: 0 auto;
  765. }
  766. .unit-model-main {
  767. margin-bottom: 30rpx;
  768. margin-top: 10rpx;
  769. width: 600rpx;
  770. line-height: 70rpx;
  771. input {
  772. display: inline-block;
  773. vertical-align: middle;
  774. width: 200rpx;
  775. margin: 0 10rpx;
  776. }
  777. .sel-view {
  778. margin: 0 10rpx;
  779. display: inline-block;
  780. vertical-align: middle;
  781. width: 200rpx;
  782. height: 70rpx;
  783. border: 1px solid #f5f5f5;
  784. }
  785. }
  786. }
  787. .tag-li {
  788. margin-right: 20rpx;
  789. }
  790. </style>