index.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. <template>
  2. <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: $route.meta.title + '-列表', essential: true }]">
  3. <template slot-scope="{ activeKey, data }">
  4. <template-page
  5. v-if="activeKey == 'list'"
  6. ref="pageRef"
  7. :get-list="getList"
  8. :table-attributes="tableAttributes"
  9. :table-events="tableEvents"
  10. :options-evens-group="optionsEvensGroup"
  11. :moreParameters="moreParameters"
  12. :column-parsing="columnParsing"
  13. :operation="operation()"
  14. :exportList="exportList"
  15. :operationColumnWidth="80"
  16. >
  17. <div slot="moreSearch">
  18. <el-radio-group v-model="status" size="mini" @change="changeType">
  19. <el-radio-button label="">全部</el-radio-button>
  20. <el-radio-button :label="false">已关闭</el-radio-button>
  21. <el-radio-button :label="true">已开启</el-radio-button>
  22. </el-radio-group>
  23. <br /><br />
  24. </div>
  25. </template-page>
  26. <div v-if="~['add', 'edit', 'detail'].indexOf(activeKey)">
  27. <div class="page">
  28. <el-steps :active="stepIndex" align-center>
  29. <el-step title="编辑基础信息" description=""></el-step>
  30. <el-step title="编辑价格库存" description=""></el-step>
  31. <el-step title="编辑商品详情" description=""></el-step>
  32. </el-steps>
  33. <el-card class="box-card">
  34. <div slot="header" class="clearfix">
  35. <span>{{
  36. stepIndex == 0 ? '基础信息' : stepIndex == 1 ? '价格库存' : stepIndex == 2 ? '详情内容' : ''
  37. }}</span>
  38. </div>
  39. <div class="mymain-container">
  40. <el-form
  41. ref="formRef"
  42. :rules="rules"
  43. :model="formData"
  44. label-width="110px"
  45. size="small"
  46. label-position="left"
  47. >
  48. <el-row :gutter="20" justify="start">
  49. <div v-show="stepIndex == 0">
  50. <el-col :span="24">
  51. <el-form-item label="商品可选状态" prop="status" :required="true">
  52. <div class="flex_ac">
  53. <el-radio-group v-model="formData.status">
  54. <el-radio :label="true">开启</el-radio>
  55. <el-radio :label="false">关闭</el-radio>
  56. </el-radio-group>
  57. <div class="hui" style="margin-left: 80px">
  58. 开启状态,商户可选择本商品;关闭则不允许商户选择;
  59. </div>
  60. </div>
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="6">
  64. <el-form-item
  65. label="品牌"
  66. prop="brandName"
  67. :rules="[{ required: true, message: `请输入品牌`, trigger: 'blur' }]"
  68. >
  69. <el-input type="text" v-model="formData.brandName" placeholder="请输入"></el-input>
  70. </el-form-item>
  71. </el-col>
  72. <el-col :span="6">
  73. <el-form-item label="是否虚拟商品" prop="isVr" :required="true">
  74. <el-radio-group v-model="formData.isVr">
  75. <el-radio :label="true">是</el-radio>
  76. <el-radio :label="false">否</el-radio>
  77. </el-radio-group>
  78. </el-form-item>
  79. </el-col>
  80. <el-col :span="6">
  81. <el-form-item
  82. label="商品大类"
  83. prop="category1"
  84. :rules="[{ required: true, message: `请输入商品大类`, trigger: 'blur' }]"
  85. >
  86. <el-input type="text" v-model="formData.category1" placeholder="请输入"></el-input>
  87. </el-form-item>
  88. </el-col>
  89. <el-col :span="6">
  90. <el-form-item
  91. label="商品小类"
  92. prop="category2"
  93. :rules="[{ required: true, message: `请输入商品小类`, trigger: 'blur' }]"
  94. >
  95. <el-input type="text" v-model="formData.category2" placeholder="请输入"></el-input>
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="24">
  99. <el-form-item
  100. label="商品名称"
  101. prop="goodsName"
  102. :rules="[{ required: true, message: `请输入商品名称`, trigger: 'blur' }]"
  103. >
  104. <el-input
  105. type="textarea"
  106. :rows="3"
  107. v-model="formData.goodsName"
  108. placeholder="请输入"
  109. ></el-input>
  110. <div class="hui">商品名称将显示在商品详情,让用户更直接了解商品内涵</div>
  111. </el-form-item>
  112. </el-col>
  113. <el-col :span="24">
  114. <el-form-item label="商品描述" prop="describeText">
  115. <el-input
  116. type="textarea"
  117. :rows="3"
  118. v-model="formData.describeText"
  119. placeholder="请输入"
  120. ></el-input>
  121. <div class="hui">商品描述将显示在商品详情,让用户更了解商品细节</div>
  122. </el-form-item>
  123. </el-col>
  124. <el-col :span="12">
  125. <el-form-item
  126. label="商品主图"
  127. prop="imgUrl"
  128. :rules="[{ required: true, message: `请上传商品主图`, trigger: 'change' }]"
  129. >
  130. <ImageUpload :fileList="formData.imgUrl" :limit="1" :isEdit="true" :fileType="['image']" />
  131. <div class="suggest">建议尺寸800*800</div>
  132. </el-form-item>
  133. </el-col>
  134. <el-col :span="12">
  135. <el-form-item label="商品视频" prop="vedio">
  136. <ImageUpload :fileList="formData.vedio" :limit="1" :isEdit="true" :fileType="['video']" />
  137. <div class="suggest">建议视频宽高比16:9,建议时长9-30秒</div>
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="24">
  141. <el-form-item
  142. label="轮播图"
  143. prop="imgs"
  144. :rules="[{ required: true, message: `请上传轮播图`, trigger: 'change' }]"
  145. >
  146. <ImageUpload :fileList="formData.imgs" :limit="6" :isEdit="true" :fileType="['image']" />
  147. <div class="suggest">建议尺寸800*800,最多上传6张</div>
  148. </el-form-item>
  149. </el-col>
  150. </div>
  151. <div v-show="stepIndex == 1">
  152. <el-col :span="24">
  153. <el-form-item label="规格类型" prop="goodsLibrarySpecList" class="is-required">
  154. <el-button size="mini" @click="add()" type="primary">添加规格</el-button>
  155. </el-form-item>
  156. </el-col>
  157. <el-form ref="formData" :model="formData" label-width="110px" size="small">
  158. <el-table
  159. :data="formData.goodsLibrarySpecList"
  160. element-loading-text="Loading"
  161. border
  162. fit
  163. highlight-current-row
  164. stripe
  165. >
  166. <el-table-column prop="" align="center" label="*大类">
  167. <template slot-scope="scope">
  168. <el-form-item
  169. :prop="'goodsLibrarySpecList.' + scope.$index + '.mainName'"
  170. :rules="[{ required: true, message: `请输入大类`, trigger: 'blur' }]"
  171. label-width="0"
  172. >
  173. <el-input
  174. type="text"
  175. v-model="scope.row.mainName"
  176. :disabled="isEdit != scope.$index"
  177. placeholder="请输入"
  178. ></el-input>
  179. </el-form-item>
  180. </template>
  181. </el-table-column>
  182. <el-table-column prop="" align="center" label="*小类">
  183. <template slot-scope="scope">
  184. <el-form-item
  185. :prop="'goodsLibrarySpecList.' + scope.$index + '.smallName'"
  186. :rules="[{ required: true, message: `请输入小类`, trigger: 'blur' }]"
  187. label-width="0"
  188. >
  189. <el-input
  190. type="text"
  191. v-model="scope.row.smallName"
  192. :disabled="isEdit != scope.$index"
  193. placeholder="请输入"
  194. ></el-input>
  195. </el-form-item>
  196. </template>
  197. </el-table-column>
  198. <el-table-column prop="" align="center" label="*规格型号">
  199. <template slot-scope="scope">
  200. <el-form-item
  201. :prop="'goodsLibrarySpecList.' + scope.$index + '.specValue'"
  202. :rules="[{ required: true, message: `请输入规格型号`, trigger: 'blur' }]"
  203. label-width="0"
  204. >
  205. <el-input
  206. type="text"
  207. v-model="scope.row.specValue"
  208. :disabled="isEdit != scope.$index"
  209. placeholder="请输入"
  210. ></el-input>
  211. </el-form-item>
  212. </template>
  213. </el-table-column>
  214. <el-table-column prop="" align="center" label="*参考销售价格">
  215. <template slot-scope="scope">
  216. <el-form-item
  217. :prop="'goodsLibrarySpecList.' + scope.$index + '.price'"
  218. :rules="[
  219. { required: true, message: `请输入参考销售价格`, trigger: 'blur' },
  220. {
  221. pattern: /^(([0-9]\d*)|([0][.]{1}[0-9]{0,2}[1-9]+)|([1-9]\d*[.]{1}[0-9]+))$/g,
  222. message: '请输入大于等于0的数',
  223. trigger: 'blur'
  224. }
  225. ]"
  226. label-width="0"
  227. >
  228. <el-input
  229. type="number"
  230. v-model="scope.row.price"
  231. :disabled="isEdit != scope.$index"
  232. placeholder="请输入"
  233. ></el-input>
  234. </el-form-item>
  235. </template>
  236. </el-table-column>
  237. <el-table-column prop="" align="center" label="*参考划线价格">
  238. <template slot-scope="scope">
  239. <el-form-item
  240. :prop="'goodsLibrarySpecList.' + scope.$index + '.orgPrice'"
  241. :rules="[
  242. { required: true, message: `请输入参考划线价格`, trigger: 'blur' },
  243. {
  244. pattern: /^(([0-9]\d*)|([0][.]{1}[0-9]{0,2}[1-9]+)|([1-9]\d*[.]{1}[0-9]+))$/g,
  245. message: '请输入大于等于0的数',
  246. trigger: 'blur'
  247. }
  248. ]"
  249. label-width="0"
  250. >
  251. <el-input
  252. type="number"
  253. v-model="scope.row.orgPrice"
  254. :disabled="isEdit != scope.$index"
  255. placeholder="请输入"
  256. ></el-input>
  257. </el-form-item>
  258. </template>
  259. </el-table-column>
  260. <el-table-column prop="" align="center" label="*参考成本价">
  261. <template slot-scope="scope">
  262. <el-form-item
  263. :prop="'goodsLibrarySpecList.' + scope.$index + '.costPrice'"
  264. :rules="[
  265. { required: true, message: `请输入参考成本价`, trigger: 'blur' },
  266. {
  267. pattern: /^(([0-9]\d*)|([0][.]{1}[0-9]{0,2}[1-9]+)|([1-9]\d*[.]{1}[0-9]+))$/g,
  268. message: '请输入大于等于0的数',
  269. trigger: 'blur'
  270. }
  271. ]"
  272. label-width="0"
  273. >
  274. <el-input
  275. type="number"
  276. v-model="scope.row.costPrice"
  277. :disabled="isEdit != scope.$index"
  278. placeholder="请输入"
  279. ></el-input>
  280. </el-form-item>
  281. </template>
  282. </el-table-column>
  283. <el-table-column prop="" align="center" label="*参考佣金">
  284. <template slot-scope="scope">
  285. <el-form-item
  286. :prop="'goodsLibrarySpecList.' + scope.$index + '.shareAmount'"
  287. :rules="[
  288. { required: true, message: `请输入参考佣金`, trigger: 'blur' },
  289. {
  290. pattern: /^(([0-9]\d*)|([0][.]{1}[0-9]{0,2}[1-9]+)|([1-9]\d*[.]{1}[0-9]+))$/g,
  291. message: '请输入大于等于0的数',
  292. trigger: 'blur'
  293. }
  294. ]"
  295. label-width="0"
  296. >
  297. <el-input
  298. type="number"
  299. v-model="scope.row.shareAmount"
  300. :disabled="isEdit != scope.$index"
  301. placeholder="请输入"
  302. ></el-input>
  303. </el-form-item>
  304. </template>
  305. </el-table-column>
  306. <el-table-column prop="" align="center" label="*参考内部佣金">
  307. <template slot-scope="scope">
  308. <el-form-item
  309. :prop="'goodsLibrarySpecList.' + scope.$index + '.innerShareAmount'"
  310. :rules="[
  311. { required: true, message: `请输入参考内部佣金`, trigger: 'blur' },
  312. {
  313. pattern: /^(([0-9]\d*)|([0][.]{1}[0-9]{0,2}[1-9]+)|([1-9]\d*[.]{1}[0-9]+))$/g,
  314. message: '请输入大于等于0的数',
  315. trigger: 'blur'
  316. }
  317. ]"
  318. label-width="0"
  319. >
  320. <el-input
  321. type="number"
  322. v-model="scope.row.innerShareAmount"
  323. :disabled="isEdit != scope.$index"
  324. placeholder="请输入"
  325. ></el-input>
  326. </el-form-item>
  327. </template>
  328. </el-table-column>
  329. <el-table-column prop="" align="center" label="*参考规格图片">
  330. <template slot-scope="scope">
  331. <el-form-item
  332. :prop="'goodsLibrarySpecList.' + scope.$index + '.imgUrl'"
  333. :rules="[{ required: true, message: `请上传参考规格图片`, trigger: 'change' }]"
  334. label-width="0"
  335. >
  336. <div class="flex_ac">
  337. <ImageUpload
  338. :fileList="scope.row.imgUrl"
  339. :limit="1"
  340. :download="false"
  341. :viewOnline="false"
  342. :isEdit="true"
  343. modType="text"
  344. :fileType="['image']"
  345. />
  346. </div>
  347. </el-form-item>
  348. </template>
  349. </el-table-column>
  350. <el-table-column label="操作" align="center" width="160">
  351. <template slot-scope="scope">
  352. <el-button
  353. size="mini"
  354. type="primary"
  355. v-if="scope.$index != isEdit"
  356. @click="edit(scope.$index)"
  357. >编辑</el-button
  358. >
  359. <el-button size="mini" type="danger" @click="del(scope.$index)">删除</el-button>
  360. </template>
  361. </el-table-column>
  362. </el-table>
  363. </el-form>
  364. </div>
  365. <div v-show="stepIndex == 2">
  366. <el-form-item
  367. label="详情内容"
  368. prop="content"
  369. :rules="[{ required: true, message: `请输入详情内容`, trigger: 'change' }]"
  370. >
  371. <quillEditor v-model="formData.content"></quillEditor>
  372. <input type="hidden" v-model="formData.content" />
  373. </el-form-item>
  374. </div>
  375. </el-row>
  376. </el-form>
  377. </div>
  378. </el-card>
  379. </div>
  380. <div class="footer">
  381. <el-button v-if="stepIndex > 0" size="mini" @click="up()">上一步</el-button>
  382. <el-button v-if="stepIndex < 2" size="mini" @click="next()">下一步</el-button>
  383. <el-button size="mini" @click="formConfirm(data.removeTab)" type="primary">提交</el-button>
  384. <el-button size="mini" @click="data.removeTab()">关闭</el-button>
  385. </div>
  386. </div>
  387. </template>
  388. </zj-tab-page>
  389. </template>
  390. <script>
  391. import TemplatePage from '@/components/template/template-page-1.vue'
  392. import import_mixin from '@/components/template/import_mixin.js'
  393. import ImageUpload from '@/components/file-upload'
  394. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  395. import { listPageV2, pageExport, save, del, getDetail, batch, sync } from '@/api/goodsWarehouse'
  396. import operation_mixin from '@/components/template/operation_mixin.js'
  397. import quillEditor from '@/components/v-quill-editor'
  398. export default {
  399. components: {
  400. TemplatePage,
  401. ImageUpload,
  402. quillEditor
  403. },
  404. mixins: [import_mixin, operation_mixin],
  405. data() {
  406. return {
  407. // 表格属性
  408. tableAttributes: {
  409. // 启用勾选列
  410. selectColumn: true
  411. },
  412. // 表格事件
  413. tableEvents: {
  414. 'selection-change': this.selectionChange
  415. },
  416. // 勾选选中行
  417. recordSelected: [],
  418. /** 表单变量 */
  419. formDialogType: 0,
  420. formDialogTitles: ['新增', '编辑'],
  421. formDialog: false,
  422. formData: {
  423. status: true,
  424. brandName: '',
  425. category1: '',
  426. category2: '',
  427. isVr: true,
  428. goodsName: '',
  429. describeText: '',
  430. imgUrl: [],
  431. vedio: [],
  432. imgs: [],
  433. content: '',
  434. goodsLibrarySpecList: []
  435. },
  436. rules: {},
  437. status: '',
  438. formType: 'add',
  439. formVisible: false,
  440. stepIndex: 0,
  441. isEdit: 0
  442. }
  443. },
  444. computed: {
  445. // 事件组合
  446. optionsEvensGroup() {
  447. return [
  448. [
  449. [
  450. this.optionsEvensAuth('add', {
  451. click: () => {
  452. this.openForm('add')
  453. }
  454. })
  455. ]
  456. ],
  457. [
  458. [
  459. this.optionsEvensAuth('openMore', {
  460. click: () => {
  461. this.openMore()
  462. }
  463. })
  464. ]
  465. ],
  466. [
  467. [
  468. this.optionsEvensAuth('closeMore', {
  469. click: () => {
  470. this.closeMore()
  471. }
  472. })
  473. ]
  474. ],
  475. [
  476. [
  477. this.optionsEvensAuth('synchronization', {
  478. click: () => {
  479. this.sync()
  480. }
  481. })
  482. ]
  483. ]
  484. ]
  485. },
  486. // 更多参数
  487. moreParameters() {
  488. return []
  489. },
  490. formItems() {
  491. return []
  492. }
  493. },
  494. methods: {
  495. // 列表请求函数
  496. getList(p, cb) {
  497. try {
  498. var pam = JSON.parse(JSON.stringify(p))
  499. pam.params.push({ param: 'a.status', compare: '=', value: this.status })
  500. cb && cb(pam)
  501. return listPageV2(pam)
  502. } catch (error) {
  503. console.log(error)
  504. }
  505. },
  506. // 列表导出函数
  507. exportList: pageExport,
  508. changeType() {
  509. this.$refs.pageRef.refreshList()
  510. },
  511. // 表格列解析渲染数据更改
  512. columnParsing(item, defaultData) {
  513. if (item.jname === 'imgUrl') {
  514. defaultData.render = (h, { row, index, column }) => {
  515. return (
  516. <div style="padding:6px;cursor: pointer;">
  517. {row.imgUrl
  518. ? row.imgUrl
  519. .split(',')
  520. .map(url => (
  521. <el-image
  522. src={this.$showImgUrl(url)}
  523. preview-src-list={[this.$showImgUrl(url)]}
  524. fit="fit"
  525. style="width:60px;height:60px;"
  526. />
  527. ))
  528. : null}
  529. </div>
  530. )
  531. }
  532. }
  533. if (item.jname === 'goodsName') {
  534. defaultData.render = (h, { row, index, column }) => {
  535. return <div style="padding:6px;">{row.goodsName}</div>
  536. }
  537. defaultData.columnAttributes.width = 300
  538. console.log(defaultData, 11)
  539. }
  540. return defaultData
  541. },
  542. up() {
  543. this.stepIndex -= 1
  544. },
  545. next() {
  546. this.stepIndex += 1
  547. },
  548. add() {
  549. this.$refs.formData.validate(valid => {
  550. if (valid) {
  551. this.isEdit = 0
  552. this.formData.goodsLibrarySpecList.unshift({
  553. mainName: '',
  554. smallName: '',
  555. specValue: '',
  556. price: '',
  557. orgPrice: '',
  558. shareAmount: '',
  559. innerShareAmount: '',
  560. costPrice: '',
  561. imgUrl: []
  562. })
  563. }
  564. })
  565. },
  566. edit(index) {
  567. this.$refs.formData.validate(valid => {
  568. if (valid) {
  569. this.isEdit = index
  570. }
  571. })
  572. },
  573. del(index) {
  574. this.formData.goodsLibrarySpecList.splice(index, 1)
  575. },
  576. // 监听勾选变化
  577. selectionChange(data) {
  578. this.recordSelected = data
  579. },
  580. openMore() {
  581. if (this.recordSelected.length == 0) {
  582. return this.$message.warning('请至少勾选一条数据!')
  583. }
  584. this.batch(
  585. this.recordSelected.map(item => {
  586. return item.goodsLibraryId
  587. }),
  588. true
  589. )
  590. },
  591. closeMore() {
  592. if (this.recordSelected.length == 0) {
  593. return this.$message.warning('请至少勾选一条数据!')
  594. }
  595. this.batch(
  596. this.recordSelected.map(item => {
  597. return item.goodsLibraryId
  598. }),
  599. false
  600. )
  601. },
  602. batch(goodsLibraryIds, statusEnum) {
  603. console.log(goodsLibraryIds)
  604. this.$confirm('请确认是否批量操作选中的数据, 是否继续?', '提示', {
  605. confirmButtonText: '确定',
  606. cancelButtonText: '取消',
  607. type: 'warning'
  608. }).then(() => {
  609. batch({
  610. goodsLibraryIds: goodsLibraryIds.join(','),
  611. statusEnum
  612. }).then(res => {
  613. this.$message({ type: 'success', message: statusEnum ? '批量开启成功!' : '批量关闭成功!' })
  614. this.$refs.pageRef.refreshList()
  615. })
  616. })
  617. },
  618. sync() {
  619. const loading = this.$loading({
  620. lock: true,
  621. text: 'Loading',
  622. spinner: 'el-icon-loading',
  623. background: 'rgba(0, 0, 0, 0.7)'
  624. })
  625. sync().then(res => {
  626. if (res.code == 200) {
  627. this.$message({ type: 'success', message: `同步成功!` })
  628. this.$refs.pageRef.refreshList()
  629. } else {
  630. this.$message({ type: 'error', message: res.message })
  631. }
  632. loading.close()
  633. })
  634. },
  635. // 表格操作列
  636. operation() {
  637. return this.operationBtn({
  638. edit: {
  639. btnType: 'text',
  640. click: ({ row, index, column }) => {
  641. this.openForm('edit', row.goodsLibraryId)
  642. }
  643. },
  644. del: {
  645. btnType: 'text',
  646. prompt: '确定删除吗?',
  647. click: ({ row, index, column }) => {
  648. del({
  649. goodsLibraryId: row.goodsLibraryId
  650. }).then(() => {
  651. this.$message({
  652. type: 'success',
  653. message: '删除成功!'
  654. })
  655. this.$refs.pageRef.refreshList()
  656. })
  657. }
  658. }
  659. })
  660. },
  661. // 打开 新增编辑 网点表单
  662. openForm(type, goodsLibraryId) {
  663. this.$refs.tabPage.addTab({
  664. // 对应显示的模块
  665. activeKey: type,
  666. // 唯一标识
  667. key: type,
  668. // 页签名称
  669. label: {
  670. edit: '编辑',
  671. add: '新增'
  672. }[type],
  673. // 打开时事件
  674. triggerEvent: () => {
  675. this.formCancel()
  676. this.$nextTick(() => {
  677. this.formType = type
  678. this.formVisible = true
  679. if (type == 'add') {
  680. this.formDialogType = 0
  681. } else if (type == 'edit') {
  682. this.formDialogType = 1
  683. getDetail({
  684. goodsLibraryId
  685. }).then(res => {
  686. let imgs = []
  687. let goodsLibrarySpecList = []
  688. res.data.imgs.split(',').forEach(item => {
  689. imgs.push({
  690. url: item
  691. })
  692. })
  693. res.data.goodsLibrarySpecList.forEach(item => {
  694. goodsLibrarySpecList.push({
  695. ...item,
  696. imgUrl: item.imgUrl ? [{ url: item.imgUrl }] : []
  697. })
  698. })
  699. Object.assign(this.formData, res.data, {
  700. imgUrl: res.data.imgUrl ? [{ url: res.data.imgUrl }] : [],
  701. imgs: res.data.imgs ? imgs : [],
  702. vedio: res.data.vedio ? [{ url: res.data.vedio }] : [],
  703. goodsLibrarySpecList
  704. })
  705. console.log(this.formData, imgs)
  706. })
  707. }
  708. })
  709. },
  710. // 关闭时事件
  711. closeEvent: () => {}
  712. })
  713. },
  714. formCancel() {
  715. this.formVisible = false
  716. this.$refs?.formRef?.resetFields()
  717. this.$data.formData = this.$options.data().formData
  718. },
  719. formConfirm(cancel) {
  720. let imgs = this.formData.imgs.map(item => {
  721. return item.url
  722. })
  723. let goodsLibrarySpecList = []
  724. this.formData.goodsLibrarySpecList.forEach(item => {
  725. goodsLibrarySpecList.push({
  726. ...item,
  727. imgUrl: item.imgUrl.length > 0 ? item.imgUrl[0].url : ''
  728. })
  729. })
  730. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  731. if (valid) {
  732. this.$refs.formData.validate((valid, invalidFields, errLabels) => {
  733. if (valid) {
  734. save({
  735. ...this.formData,
  736. imgUrl: this.formData.imgUrl.length > 0 ? this.formData.imgUrl[0].url : '',
  737. imgs: this.formData.imgs.length > 0 ? imgs.join(',') : '',
  738. vedio: this.formData.vedio.length > 0 ? this.formData.vedio[0].url : '',
  739. goodsLibrarySpecList
  740. }).then(res => {
  741. this.stepIndex = 0
  742. this.$message({
  743. type: 'success',
  744. message: `${this.formDialogTitles[this.formDialogType]}成功!`
  745. })
  746. cancel('list')
  747. this.$refs.pageRef.refreshList()
  748. })
  749. } else {
  750. this.stepIndex = 1
  751. }
  752. })
  753. } else {
  754. if (this.formData.goodsLibrarySpecList.length == 0) {
  755. this.stepIndex = 1
  756. this.$message({
  757. type: 'warning',
  758. message: '请添加规格类型!'
  759. })
  760. } else if (!this.formData.content) {
  761. this.stepIndex = 2
  762. this.$message({
  763. type: 'warning',
  764. message: '请输入商品内容详情!'
  765. })
  766. } else {
  767. this.stepIndex = 0
  768. }
  769. }
  770. })
  771. }
  772. }
  773. }
  774. </script>
  775. <style lang="scss" scoped>
  776. .page {
  777. padding: 20px;
  778. padding-bottom: 60px;
  779. box-sizing: border-box;
  780. }
  781. .flex_ac {
  782. display: flex;
  783. align-items: center;
  784. }
  785. .box-card {
  786. margin-top: 30px;
  787. }
  788. .hui {
  789. color: #888888;
  790. }
  791. .suggest {
  792. display: inline-block;
  793. padding: 0 10px;
  794. margin-top: 10px;
  795. background-color: #ffdee5;
  796. color: #cd1e46;
  797. }
  798. .footer {
  799. position: fixed;
  800. bottom: 0;
  801. left: 0;
  802. z-index: 1;
  803. width: 100%;
  804. background: #fff;
  805. padding: 15px 40px;
  806. box-sizing: border-box;
  807. transition: all 0.28s;
  808. text-align: right;
  809. box-shadow: 0 2px 5px 0 rgb(0 0 0 / 50%), 0 2px 5px 0 rgb(0 0 0 / 10%);
  810. &.hideSidebar {
  811. margin-left: 54px;
  812. width: calc(100vw - 54px);
  813. }
  814. &.openSidebar {
  815. margin-left: 210px;
  816. width: calc(100vw - 210px);
  817. }
  818. .tips {
  819. font-size: 12px;
  820. color: red;
  821. margin-top: 10px;
  822. }
  823. }
  824. </style>