edit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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="purchaseOrderEdit-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="999999"
  102. placeholder="请输入"
  103. />
  104. <span style="margin: 0 5px;">/</span>
  105. <v-select
  106. code="PRODUCT_PACK_UNIT"
  107. id="productLevelEdit-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-row>
  137. <a-row>
  138. <a-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16">
  139. <a-form-model-item label="产品图片" help="说明:图片比例1:1,尺寸大于300*300px,首张为主图,最多5张。" :label-col="{span:3}" :wrapper-col="{span:18}">
  140. <Upload
  141. class="upload"
  142. id="productInfoEdit-productMsg"
  143. v-model="form.productMsg"
  144. ref="productMsg"
  145. @change="changeImage"
  146. :maxNums="5"
  147. listType="picture-card" ></Upload>
  148. </a-form-model-item>
  149. </a-col>
  150. </a-row>
  151. <a-row>
  152. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  153. <a-form-model-item label="产品尺寸" prop="size">
  154. <a-input
  155. v-model.trim="form.size"
  156. id="productInfoEdit-size"
  157. :maxLength="50"
  158. allowClear
  159. placeholder="请输入产品尺寸(最多50个字符)" />
  160. </a-form-model-item>
  161. </a-col>
  162. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  163. <a-form-model-item label="产品重量" prop="weight">
  164. <a-input
  165. v-model.trim="form.weight"
  166. id="productInfoEdit-weight"
  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="颜色" prop="color">
  174. <a-input
  175. v-model.trim="form.color"
  176. id="productLevelEdit-color"
  177. :maxLength="50"
  178. allowClear
  179. placeholder="请输入颜色(最多50个字符)" />
  180. </a-form-model-item>
  181. </a-col>
  182. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  183. <a-form-model-item label="产品内盒尺寸" prop="boxSize">
  184. <a-input
  185. v-model.trim="form.boxSize"
  186. id="productInfoEdit-boxSize"
  187. :maxLength="50"
  188. allowClear
  189. placeholder="请输入产品内盒尺寸(最多50个字符)" />
  190. </a-form-model-item>
  191. </a-col>
  192. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  193. <a-form-model-item label="产品说明" prop="description" :label-col="{span:2}" :wrapper-col="{span:20}">
  194. <editor id="productInfoEdit-description" ref="editor" class="productInfoEdit-description" @on-change="editorDescriptionChange" :cache="false"></editor>
  195. </a-form-model-item>
  196. </a-col>
  197. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  198. <a-form-model-item label="其他说明" prop="otherDesc" :label-col="{span:2}" :wrapper-col="{span:20}">
  199. <editor id="productInfoEdit-other-otherDesc" ref="otherDesc" class="productInfoEdit-otherDesc" @on-change="editorOtherChange" :cache="false"></editor>
  200. </a-form-model-item>
  201. </a-col>
  202. </a-row>
  203. </a-card>
  204. </a-form-model>
  205. </a-spin>
  206. <div class="affix-cont">
  207. <a-button
  208. type="primary"
  209. class="button-primary"
  210. :disabled="spinning"
  211. id="productInfoEdit-submit-btn"
  212. size="large"
  213. @click="handleSubmit"
  214. style="padding: 0 60px;">保存</a-button>
  215. </div>
  216. </div>
  217. </template>
  218. <script>
  219. import { commonMixin } from '@/utils/mixin'
  220. import { VSelect, Upload } from '@/components'
  221. import Editor from '@/components/WEeditor'
  222. import { productSave, productSnDetail } from '@/api/product'
  223. import { productTypeQueryAll } from '@/api/productType'
  224. import { productBrandQuery } from '@/api/productBrand'
  225. export default {
  226. name: 'ProductInfoEdit',
  227. mixins: [commonMixin],
  228. components: { VSelect, Upload, Editor },
  229. data () {
  230. return {
  231. spinning: false,
  232. formItemLayout: {
  233. labelCol: { span: 4 },
  234. wrapperCol: { span: 16 }
  235. },
  236. form: {
  237. name: '', // 产品名称
  238. code: '', // 产品编码
  239. origCode: '', // 原厂编码
  240. otherCode: '', // 其他编码
  241. productBrandSn: undefined, // 产品品牌
  242. productTypeSn1: '', // 产品一级分类
  243. productTypeSn2: '', // 产品二级分类
  244. productTypeSn3: '', // 产品三级分类
  245. productType: [], // 产品分类
  246. unit: undefined, // 单位
  247. packQty: '', // 包装数
  248. packQtyUnit: undefined, // 包装数单位
  249. arrowFalg: undefined, // 是否箭冠产品
  250. qrCode: '',
  251. productMsg: '', // 产品图片
  252. size: '', // 产品尺寸
  253. weight: '', // 产品重量
  254. color: undefined, // 颜色
  255. boxSize: '', // 内核尺寸
  256. description: '', // 产品说明
  257. otherDesc: '' // 其他说明
  258. },
  259. rules: {
  260. name: [
  261. { required: true, message: '请输入产品名称', trigger: 'blur' }
  262. ],
  263. code: [
  264. { required: true, message: '请输入产品编码', trigger: 'blur' }
  265. ],
  266. productBrandSn: [
  267. { required: true, message: '请选择产品品牌', trigger: 'change' }
  268. ],
  269. productType: [
  270. { required: true, message: '请选择产品分类', trigger: 'change' }
  271. ],
  272. unit: [
  273. { required: true, message: '请选择单位', trigger: 'change' }
  274. ],
  275. packQty: [
  276. { required: true, message: '请输入包装数', trigger: 'blur' }
  277. ],
  278. arrowFalg: [
  279. { required: true, message: '请选择是否为箭冠产品', trigger: 'change' }
  280. ],
  281. qrCode: [
  282. { required: false, message: '请输入条形码', trigger: 'blur' },
  283. { validator: this.validateQrCode }
  284. ]
  285. },
  286. productBrandList: [], // 品牌下拉数据
  287. productTypeList: [] // 分类下拉数据
  288. }
  289. },
  290. methods: {
  291. // 详情
  292. getDetail () {
  293. productSnDetail({ sn: this.$route.params.sn }).then(res => {
  294. if (res.status == 200) {
  295. const data = res.data
  296. this.form = Object.assign(this.form, data)
  297. this.form.productType = [ this.form.productTypeSn1, this.form.productTypeSn2, this.form.productTypeSn3 ]
  298. if (res.data.productPicList && res.data.productPicList.length > 0) {
  299. let str = ''
  300. res.data.productPicList.map(item => {
  301. if (item.imageUrl) {
  302. str += item.imageUrl + ','
  303. }
  304. })
  305. str = str.substr(0, str.length - 1)
  306. this.$refs.productMsg.setFileList(str)
  307. this.form.productMsg = str
  308. } else {
  309. this.$refs.productMsg.setFileList('')
  310. this.form.productMsg = ''
  311. }
  312. this.$refs.editor.setHtml(res.data.description)
  313. this.$refs.otherDesc.setHtml(res.data.otherDesc)
  314. } else {
  315. this.$refs.ruleForm.resetFields()
  316. }
  317. })
  318. },
  319. // 提交
  320. handleSubmit (e) {
  321. e.preventDefault()
  322. const _this = this
  323. if (!this.form.productTypeSn3) {
  324. this.$message.warning('产品分类未选到第三级,请修改后再提交!')
  325. return
  326. }
  327. this.$refs.ruleForm.validate(valid => {
  328. if (valid) {
  329. const form = JSON.parse(JSON.stringify(_this.form))
  330. form.id = _this.$route.params.id ? _this.$route.params.id : undefined
  331. form.productPicList = []
  332. if (form.productMsg) {
  333. const arr = form.productMsg.split(',')
  334. arr.map(item => {
  335. form.productPicList.push({ imageUrl: item })
  336. })
  337. }
  338. delete form.productMsg
  339. delete form.productType
  340. delete form.updateDate
  341. _this.spinning = true
  342. productSave(form).then(res => {
  343. if (res.status == 200) {
  344. _this.$message.success(res.message)
  345. setTimeout(() => {
  346. _this.handleBack()
  347. _this.spinning = false
  348. }, 1000)
  349. } else {
  350. _this.spinning = false
  351. }
  352. })
  353. } else {
  354. console.log('error submit!!')
  355. return false
  356. }
  357. })
  358. },
  359. // 返回
  360. handleBack () {
  361. this.$router.push({ path: '/productManagement/productInfo/list', query: { closeLastOldTab: true } })
  362. },
  363. // 产品图片上传
  364. changeImage (file) {
  365. console.log(file.split(","))
  366. this.form.productMsg = file
  367. },
  368. validateQrCode (rule, value, callback) {
  369. const reg = /^[0-9a-zA-Z]+$/
  370. if (value && !reg.test(value)) {
  371. callback('条形码由大小写英文字母和数字组成')
  372. } else {
  373. callback()
  374. }
  375. },
  376. // 产品说明 文本编辑器
  377. editorDescriptionChange (html, text) {
  378. this.form.description = html
  379. },
  380. // 其他说明 文本编辑器
  381. editorOtherChange (html, text) {
  382. this.form.otherDesc = html
  383. },
  384. // 产品分类 change
  385. changeProductType (val, opt) {
  386. this.form.productTypeSn1 = val[0] ? val[0] : ''
  387. this.form.productTypeSn2 = val[1] ? val[1] : ''
  388. this.form.productTypeSn3 = val[2] ? val[2] : ''
  389. },
  390. // 产品品牌 列表
  391. getProductBrand () {
  392. productBrandQuery({}).then(res => {
  393. if (res.status == 200) {
  394. this.productBrandList = res.data
  395. } else {
  396. this.productBrandList = []
  397. }
  398. })
  399. },
  400. // 产品分类 列表
  401. getProductType () {
  402. productTypeQueryAll({}).then(res => {
  403. if (res.status == 200) {
  404. if (res.data && res.data.length > 0) {
  405. // 递归处理disabled禁用
  406. this.recursionFun(res.data, false)
  407. this.productTypeList = res.data
  408. } else {
  409. this.productTypeList = []
  410. }
  411. } else {
  412. this.productTypeList = []
  413. }
  414. })
  415. },
  416. // 递归函数
  417. recursionFun (data, state) {
  418. if (data) {
  419. data.map((item, index) => {
  420. // enabledFlag为0表示禁用,父级禁用则子级也为禁用
  421. if ((item.enabledFlag && item.enabledFlag == 0) || state) {
  422. item.disabled = true
  423. } else {
  424. item.disabled = false
  425. }
  426. if (item.children && item.children.length == 0) {
  427. delete item.children
  428. } else {
  429. this.recursionFun(item.children, item.disabled)
  430. }
  431. })
  432. }
  433. },
  434. filterOption (input, option) {
  435. return (
  436. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  437. )
  438. },
  439. pageInit () {
  440. this.$refs.productMsg.setFileList('')
  441. this.$refs.editor.setHtml('')
  442. this.$refs.otherDesc.setHtml('')
  443. this.$refs.ruleForm.resetFields()
  444. this.form.packQtyUnit = undefined
  445. this.getProductBrand()
  446. this.getProductType()
  447. if (this.$route.params.id) { // 编辑页
  448. this.getDetail()
  449. }
  450. }
  451. },
  452. mounted () {
  453. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  454. this.pageInit()
  455. }
  456. },
  457. activated () {
  458. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  459. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  460. this.pageInit()
  461. }
  462. },
  463. beforeRouteEnter (to, from, next) {
  464. next(vm => {})
  465. }
  466. }
  467. </script>
  468. <style lang="less">
  469. .productInfoEdit-wrap{
  470. position: relative;
  471. height: 100%;
  472. padding-bottom: 51px;
  473. box-sizing: border-box;
  474. >.ant-spin-nested-loading{
  475. overflow-y: scroll;
  476. height: 100%;
  477. }
  478. .productInfoEdit-cont{
  479. margin-bottom: 10px;
  480. }
  481. .upload{
  482. width: 100%!important;
  483. }
  484. // 文本编辑器 工具栏样式换行
  485. .productInfoEdit-editor{
  486. .w-e-toolbar{
  487. flex-wrap: wrap;
  488. z-index: 0;
  489. }
  490. }
  491. .affix{
  492. .ant-affix{
  493. z-index: 101;
  494. }
  495. }
  496. }
  497. </style>