edit.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <div class="productInfoEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="productInfoEdit-cont" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="productInfoEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  8. </template>
  9. </a-page-header>
  10. <a-form-model
  11. id="productInfoEdit-form"
  12. ref="ruleForm"
  13. :model="form"
  14. :rules="rules"
  15. :label-col="formItemLayout.labelCol"
  16. :wrapper-col="formItemLayout.wrapperCol">
  17. <a-card :bordered="false" class="productInfoEdit-cont">
  18. <a-row>
  19. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  20. <a-form-model-item label="产品名称" prop="name">
  21. <a-input v-model.trim="form.name" id="productInfoEdit-name" :maxLength="100" allowClear placeholder="请输入产品名称(最多100个字符)" />
  22. </a-form-model-item>
  23. </a-col>
  24. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  25. <a-form-model-item label="产品编码" prop="code">
  26. <a-input
  27. id="productInfoEdit-code"
  28. :maxLength="100"
  29. :disabled="form.state&&form.state!='WAIT'"
  30. v-model.trim="form.code"
  31. placeholder="请输入产品编码(最多100个字符)"
  32. allowClear />
  33. </a-form-model-item>
  34. </a-col>
  35. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  36. <a-form-model-item label="原厂编码" prop="origCode">
  37. <a-input
  38. id="productInfoEdit-origCode"
  39. :maxLength="200"
  40. v-model.trim="form.origCode"
  41. placeholder="请输入(最多200个字符,多个编码用逗号隔开)"
  42. allowClear />
  43. </a-form-model-item>
  44. </a-col>
  45. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  46. <a-form-model-item label="其他编码" prop="otherCode">
  47. <a-input
  48. id="productInfoEdit-otherCode"
  49. :maxLength="60"
  50. v-model.trim="form.otherCode"
  51. placeholder="请输入(最多60个字符,多个编码用逗号隔开)"
  52. allowClear />
  53. </a-form-model-item>
  54. </a-col>
  55. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  56. <a-form-model-item label="产品品牌" prop="productBrandSn">
  57. <a-select
  58. id="productInfoEdit-productBrand"
  59. placeholder="请选择产品品牌"
  60. allowClear
  61. v-model="form.productBrandSn"
  62. :showSearch="true"
  63. option-filter-prop="children"
  64. :filter-option="filterOption">
  65. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn" :disabled="item.enabledFlag==0">{{ item.brandName }}</a-select-option>
  66. </a-select>
  67. </a-form-model-item>
  68. </a-col>
  69. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  70. <a-form-model-item label="产品分类" prop="productType">
  71. <a-cascader
  72. :disabled="form.state&&form.state!='WAIT'"
  73. expand-trigger="hover"
  74. @change="changeProductType"
  75. :options="productTypeList"
  76. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  77. id="productInfoEdit-productType"
  78. placeholder="请选择产品分类"
  79. allowClear
  80. v-model="form.productType" />
  81. </a-form-model-item>
  82. </a-col>
  83. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  84. <a-form-model-item label="单位" prop="unit">
  85. <v-select
  86. code="PRODUCT_UNIT"
  87. id="productInfoEdit-unit"
  88. v-model="form.unit"
  89. allowClear
  90. placeholder="请选择单位"
  91. ></v-select>
  92. </a-form-model-item>
  93. </a-col>
  94. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  95. <a-form-model-item label="包装数" prop="packQty" :label-col="{span:4}" :wrapper-col="{span:16}">
  96. <a-input-number
  97. id="productInfoEdit-packQty"
  98. v-model="form.packQty"
  99. :precision="0"
  100. :min="1"
  101. :max="99999999"
  102. placeholder="请输入"
  103. />
  104. <span style="margin: 0 5px;">/</span>
  105. <v-select
  106. code="PRODUCT_PACK_UNIT"
  107. id="productInfoEdit-packQtyUnit"
  108. v-model="form.packQtyUnit"
  109. allowClear
  110. style="width: 100px;"
  111. placeholder="单位"
  112. ></v-select>
  113. </a-form-model-item>
  114. </a-col>
  115. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  116. <a-form-model-item label="箭冠产品" prop="arrowFalg">
  117. <v-select
  118. code="ARROW_FALG"
  119. id="productInfoEdit-arrowFalg"
  120. v-model="form.arrowFalg"
  121. allowClear
  122. placeholder="请选择"
  123. ></v-select>
  124. </a-form-model-item>
  125. </a-col>
  126. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  127. <a-form-model-item label="条形码" prop="qrCode">
  128. <a-input
  129. id="productInfoEdit-qrCode"
  130. :maxLength="50"
  131. v-model.trim="form.qrCode"
  132. placeholder="请输入条形码(最多50个字符)"
  133. allowClear />
  134. </a-form-model-item>
  135. </a-col>
  136. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  137. <a-form-model-item label="出库仓库" prop="outWarehouseSn">
  138. <chooseWarehouse ref="outWarehouse" id="productInfoEdit-outWarehouse" isPermission v-model="form.outWarehouseSn"></chooseWarehouse>
  139. </a-form-model-item>
  140. </a-col>
  141. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  142. <a-form-model-item label="退货仓库" prop="returnWarehouseSn">
  143. <chooseWarehouse ref="returnWarehouse" id="productInfoEdit-returnWarehouse" isPermission v-model="form.returnWarehouseSn"></chooseWarehouse>
  144. </a-form-model-item>
  145. </a-col>
  146. </a-row>
  147. <a-row>
  148. <a-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16">
  149. <a-form-model-item label="产品图片" help="说明:图片比例1:1,尺寸大于300*300px,首张为主图,最多5张。" :label-col="{span:3}" :wrapper-col="{span:18}">
  150. <Upload
  151. class="upload"
  152. id="productInfoEdit-productMsg"
  153. v-model="form.productMsg"
  154. ref="productMsg"
  155. @change="changeImage"
  156. :maxNums="5"
  157. listType="picture-card" ></Upload>
  158. </a-form-model-item>
  159. </a-col>
  160. </a-row>
  161. <a-row>
  162. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  163. <a-form-model-item label="产品尺寸" prop="size">
  164. <a-input
  165. v-model.trim="form.size"
  166. id="productInfoEdit-size"
  167. :maxLength="50"
  168. allowClear
  169. placeholder="请输入产品尺寸(最多50个字符)" />
  170. </a-form-model-item>
  171. </a-col>
  172. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  173. <a-form-model-item label="产品重量(g)" prop="weight">
  174. <a-input-number
  175. style="width:80%;"
  176. :precision="0"
  177. id="productInfoEdit-weight"
  178. v-model="form.weight"
  179. :min="1"
  180. :max="999999"
  181. placeholder="请输入产品重量,注意单位为g(正整数)"/>
  182. <span v-if="form.weight">({{ form.weight/1000 }}kg)</span>
  183. </a-form-model-item>
  184. </a-col>
  185. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  186. <a-form-model-item label="颜色" prop="color">
  187. <a-input
  188. v-model.trim="form.color"
  189. id="productInfoEdit-color"
  190. :maxLength="50"
  191. allowClear
  192. placeholder="请输入颜色(最多50个字符)" />
  193. </a-form-model-item>
  194. </a-col>
  195. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  196. <a-form-model-item label="产品内盒尺寸" prop="boxSize">
  197. <a-input
  198. v-model.trim="form.boxSize"
  199. id="productInfoEdit-boxSize"
  200. :maxLength="50"
  201. allowClear
  202. placeholder="请输入产品内盒尺寸(最多50个字符)" />
  203. </a-form-model-item>
  204. </a-col>
  205. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  206. <a-form-model-item label="产品说明" prop="description" :label-col="{span:2}" :wrapper-col="{span:20}">
  207. <editor id="productInfoEdit-description" ref="editor" class="productInfoEdit-description" @on-change="editorDescriptionChange" :cache="false"></editor>
  208. </a-form-model-item>
  209. </a-col>
  210. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  211. <a-form-model-item label="其他说明" prop="otherDesc" :label-col="{span:2}" :wrapper-col="{span:20}">
  212. <editor id="productInfoEdit-otherDesc" ref="otherDesc" class="productInfoEdit-otherDesc" @on-change="editorOtherChange" :cache="false"></editor>
  213. </a-form-model-item>
  214. </a-col>
  215. </a-row>
  216. </a-card>
  217. </a-form-model>
  218. </a-spin>
  219. <div class="affix-cont">
  220. <a-button
  221. type="primary"
  222. class="button-primary"
  223. :disabled="spinning"
  224. id="productInfoEdit-submit-btn"
  225. size="large"
  226. @click="handleSubmit"
  227. style="padding: 0 60px;">保存</a-button>
  228. </div>
  229. </div>
  230. </template>
  231. <script>
  232. import { commonMixin } from '@/utils/mixin'
  233. // 组件
  234. import { VSelect, Upload } from '@/components'
  235. import Editor from '@/components/WEeditor'
  236. import chooseWarehouse from '@/views/common/chooseWarehouse'
  237. // 接口
  238. import { productSave, productSnDetail } from '@/api/product'
  239. import { productTypeQueryAll } from '@/api/productType'
  240. import { productBrandQuery } from '@/api/productBrand'
  241. export default {
  242. name: 'ProductInfoEdit',
  243. mixins: [commonMixin],
  244. components: { VSelect, Upload, Editor, chooseWarehouse },
  245. data () {
  246. return {
  247. spinning: false,
  248. formItemLayout: {
  249. labelCol: { span: 4 }, // label 标签布局
  250. wrapperCol: { span: 16 }// 输入控件布局
  251. },
  252. form: {
  253. name: '', // 产品名称
  254. code: '', // 产品编码
  255. origCode: '', // 原厂编码
  256. otherCode: '', // 其他编码
  257. productBrandSn: undefined, // 产品品牌
  258. productTypeSn1: '', // 产品一级分类
  259. productTypeSn2: '', // 产品二级分类
  260. productTypeSn3: '', // 产品三级分类
  261. productType: [], // 产品分类
  262. unit: undefined, // 单位
  263. packQty: '', // 包装数
  264. packQtyUnit: undefined, // 包装数单位
  265. arrowFalg: undefined, // 是否箭冠产品
  266. qrCode: '', // 条形码
  267. productMsg: '', // 产品图片
  268. size: '', // 产品尺寸
  269. weight: undefined, // 产品重量
  270. color: undefined, // 颜色
  271. boxSize: '', // 内核尺寸
  272. description: '', // 产品说明
  273. otherDesc: '', // 其他说明
  274. outWarehouseSn: undefined, // 出库仓库
  275. returnWarehouseSn: undefined// 退货仓库
  276. },
  277. // 表单验证规则
  278. rules: {
  279. name: [
  280. { required: true, message: '请输入产品名称', trigger: 'change' }
  281. // { validator: validateSpecialCharacter, trigger: 'change' }
  282. ],
  283. code: [
  284. { required: true, message: '请输入产品编码', trigger: 'change' }
  285. // { validator: validateSpecialCharacter, trigger: 'change' }
  286. ],
  287. origCode: [
  288. // { validator: validateSpecialCharacter, trigger: 'change' }
  289. ],
  290. productBrandSn: [
  291. { required: true, message: '请选择产品品牌', trigger: 'change' }
  292. ],
  293. productType: [
  294. { required: true, message: '请选择产品分类', trigger: 'change' }
  295. ],
  296. unit: [
  297. { required: true, message: '请选择单位', trigger: 'change' }
  298. ],
  299. packQty: [
  300. { required: true, message: '请输入包装数', trigger: 'change' }
  301. ],
  302. arrowFalg: [
  303. { required: true, message: '请选择是否为箭冠产品', trigger: 'change' }
  304. ],
  305. outWarehouseSn: [
  306. { required: true, message: '请选择出库仓库', trigger: 'change' }
  307. ],
  308. returnWarehouseSn: [
  309. { required: true, message: '请选择退货仓库', trigger: 'change' }
  310. ],
  311. qrCode: [
  312. { required: false, message: '请输入条形码', trigger: 'change' },
  313. { validator: this.validateQrCode }
  314. ]
  315. },
  316. productBrandList: [], // 品牌下拉数据
  317. productTypeList: [] // 分类下拉数据
  318. }
  319. },
  320. methods: {
  321. // 获取编辑回显数据
  322. getDetail () {
  323. productSnDetail({ sn: this.$route.params.sn }).then(res => {
  324. if (res.status == 200) {
  325. const data = res.data
  326. this.form = Object.assign(this.form, data)
  327. // 产品分类回显赋值
  328. this.form.productType = [ this.form.productTypeSn1, this.form.productTypeSn2, this.form.productTypeSn3 ]
  329. // 产品图片回显
  330. if (res.data.productPicList && res.data.productPicList.length > 0) {
  331. let str = ''
  332. res.data.productPicList.map(item => {
  333. if (item.imageUrl) {
  334. str += item.imageUrl + ','
  335. }
  336. })
  337. str = str.substr(0, str.length - 1)
  338. this.$refs.productMsg.setFileList(str)
  339. this.form.productMsg = str
  340. } else {
  341. this.$refs.productMsg.setFileList('')
  342. this.form.productMsg = ''
  343. }
  344. // 产品说明回显
  345. this.$refs.editor.setHtml(res.data.description)
  346. this.$refs.otherDesc.setHtml(res.data.otherDesc)
  347. } else {
  348. this.$refs.ruleForm.resetFields()
  349. }
  350. })
  351. },
  352. // 提交
  353. handleSubmit (e) {
  354. // 防止表单重复提交
  355. e.preventDefault()
  356. const _this = this
  357. this.$refs.ruleForm.validate(valid => {
  358. if (valid) {
  359. const form = JSON.parse(JSON.stringify(_this.form))
  360. // 判断产品分类是否选择到第三级
  361. if (!form.productTypeSn3) {
  362. this.$message.warning('产品分类未选到第三级,请修改后再提交!')
  363. return false
  364. }
  365. form.id = _this.$route.params.id ? _this.$route.params.id : undefined
  366. // 产品图片
  367. form.productPicList = []
  368. if (form.productMsg) {
  369. const arr = form.productMsg.split(',')
  370. arr.map(item => {
  371. form.productPicList.push({ imageUrl: item })
  372. })
  373. }
  374. delete form.productMsg
  375. delete form.productType
  376. delete form.updateDate
  377. _this.spinning = true
  378. productSave(form).then(res => {
  379. if (res.status == 200) {
  380. _this.$message.success(res.message)
  381. setTimeout(() => {
  382. _this.handleBack()
  383. _this.spinning = false
  384. }, 1000)
  385. } else {
  386. _this.spinning = false
  387. }
  388. })
  389. } else {
  390. console.log('error submit!!')
  391. return false
  392. }
  393. })
  394. },
  395. // 返回
  396. handleBack () {
  397. this.$router.push({ name: 'productInfoList', query: { closeLastOldTab: true } })
  398. },
  399. // 产品图片上传
  400. changeImage (file) {
  401. this.form.productMsg = file
  402. },
  403. // 验证 条形码 规则
  404. validateQrCode (rule, value, callback) {
  405. const reg = /^[0-9a-zA-Z]+$/
  406. if (value && !reg.test(value)) {
  407. callback('条形码由大小写英文字母和数字组成')
  408. } else {
  409. callback()
  410. }
  411. },
  412. // 产品说明 文本编辑器
  413. editorDescriptionChange (html, text) {
  414. this.form.description = html
  415. },
  416. // 其他说明 文本编辑器
  417. editorOtherChange (html, text) {
  418. this.form.otherDesc = html
  419. },
  420. // 产品分类 change
  421. changeProductType (val, opt) {
  422. this.form.productTypeSn1 = val[0] ? val[0] : ''
  423. this.form.productTypeSn2 = val[1] ? val[1] : ''
  424. this.form.productTypeSn3 = val[2] ? val[2] : ''
  425. },
  426. // 产品品牌 列表
  427. getProductBrand () {
  428. productBrandQuery({}).then(res => {
  429. if (res.status == 200) {
  430. this.productBrandList = res.data
  431. } else {
  432. this.productBrandList = []
  433. }
  434. })
  435. },
  436. // 产品分类 列表
  437. getProductType () {
  438. productTypeQueryAll({}).then(res => {
  439. if (res.status == 200) {
  440. if (res.data && res.data.length > 0) {
  441. // 递归处理disabled禁用
  442. this.recursionFun(res.data, false)
  443. this.productTypeList = res.data
  444. } else {
  445. this.productTypeList = []
  446. }
  447. } else {
  448. this.productTypeList = []
  449. }
  450. })
  451. },
  452. // 递归函数
  453. recursionFun (data, state) {
  454. if (data) {
  455. data.map((item, index) => {
  456. // enabledFlag为0表示禁用,父级禁用则子级也为禁用
  457. if ((item.enabledFlag && item.enabledFlag == 0) || state) {
  458. item.disabled = true
  459. } else {
  460. item.disabled = false
  461. }
  462. if (item.children && item.children.length == 0) {
  463. delete item.children
  464. } else {
  465. this.recursionFun(item.children, item.disabled)
  466. }
  467. })
  468. }
  469. },
  470. // 根据输入项进行筛选
  471. filterOption (input, option) {
  472. return (
  473. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  474. )
  475. },
  476. // 初始化数据
  477. pageInit () {
  478. this.$refs.productMsg.setFileList('')
  479. this.$refs.editor.setHtml('')
  480. this.$refs.otherDesc.setHtml('')
  481. this.$refs.ruleForm.resetFields()
  482. this.form.packQtyUnit = undefined
  483. this.getProductBrand()
  484. this.getProductType()
  485. if (this.$route.params.id) { // 编辑页
  486. this.getDetail()
  487. }
  488. }
  489. },
  490. mounted () {
  491. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  492. this.pageInit()
  493. }
  494. },
  495. activated () {
  496. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  497. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  498. this.pageInit()
  499. }
  500. },
  501. beforeRouteEnter (to, from, next) {
  502. next(vm => {})
  503. }
  504. }
  505. </script>
  506. <style lang="less">
  507. .productInfoEdit-wrap{
  508. position: relative;
  509. height: 100%;
  510. padding-bottom: 51px;
  511. box-sizing: border-box;
  512. >.ant-spin-nested-loading{
  513. overflow-y: scroll;
  514. height: 100%;
  515. }
  516. .productInfoEdit-cont{
  517. margin-bottom: 10px;
  518. }
  519. .upload{
  520. width: 100%!important;
  521. }
  522. // 文本编辑器 工具栏样式换行
  523. .productInfoEdit-editor{
  524. .w-e-toolbar{
  525. flex-wrap: wrap;
  526. z-index: 0;
  527. }
  528. }
  529. .affix{
  530. .ant-affix{
  531. z-index: 101;
  532. }
  533. }
  534. }
  535. </style>