edit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. import { validateSpecialCharacter } from '@/libs/tools'
  226. export default {
  227. name: 'ProductInfoEdit',
  228. mixins: [commonMixin],
  229. components: { VSelect, Upload, Editor },
  230. data () {
  231. return {
  232. spinning: false,
  233. formItemLayout: {
  234. labelCol: { span: 4 },
  235. wrapperCol: { span: 16 }
  236. },
  237. form: {
  238. name: '', // 产品名称
  239. code: '', // 产品编码
  240. origCode: '', // 原厂编码
  241. otherCode: '', // 其他编码
  242. productBrandSn: undefined, // 产品品牌
  243. productTypeSn1: '', // 产品一级分类
  244. productTypeSn2: '', // 产品二级分类
  245. productTypeSn3: '', // 产品三级分类
  246. productType: [], // 产品分类
  247. unit: undefined, // 单位
  248. packQty: '', // 包装数
  249. packQtyUnit: undefined, // 包装数单位
  250. arrowFalg: undefined, // 是否箭冠产品
  251. qrCode: '',
  252. productMsg: '', // 产品图片
  253. size: '', // 产品尺寸
  254. weight: '', // 产品重量
  255. color: undefined, // 颜色
  256. boxSize: '', // 内核尺寸
  257. description: '', // 产品说明
  258. otherDesc: '' // 其他说明
  259. },
  260. rules: {
  261. name: [
  262. { required: true, message: '请输入产品名称', trigger: 'change' },
  263. // { validator: validateSpecialCharacter, trigger: 'change' }
  264. ],
  265. code: [
  266. { required: true, message: '请输入产品编码', trigger: 'change' },
  267. // { validator: validateSpecialCharacter, trigger: 'change' }
  268. ],
  269. origCode: [
  270. // { validator: validateSpecialCharacter, trigger: 'change' }
  271. ],
  272. productBrandSn: [
  273. { required: true, message: '请选择产品品牌', trigger: 'change' }
  274. ],
  275. productType: [
  276. { required: true, message: '请选择产品分类', trigger: 'change' }
  277. ],
  278. unit: [
  279. { required: true, message: '请选择单位', trigger: 'change' }
  280. ],
  281. packQty: [
  282. { required: true, message: '请输入包装数', trigger: 'change' }
  283. ],
  284. arrowFalg: [
  285. { required: true, message: '请选择是否为箭冠产品', trigger: 'change' }
  286. ],
  287. qrCode: [
  288. { required: false, message: '请输入条形码', trigger: 'change' },
  289. { validator: this.validateQrCode }
  290. ]
  291. },
  292. productBrandList: [], // 品牌下拉数据
  293. productTypeList: [] // 分类下拉数据
  294. }
  295. },
  296. methods: {
  297. // 详情
  298. getDetail () {
  299. productSnDetail({ sn: this.$route.params.sn }).then(res => {
  300. if (res.status == 200) {
  301. const data = res.data
  302. this.form = Object.assign(this.form, data)
  303. this.form.productType = [ this.form.productTypeSn1, this.form.productTypeSn2, this.form.productTypeSn3 ]
  304. if (res.data.productPicList && res.data.productPicList.length > 0) {
  305. let str = ''
  306. res.data.productPicList.map(item => {
  307. if (item.imageUrl) {
  308. str += item.imageUrl + ','
  309. }
  310. })
  311. str = str.substr(0, str.length - 1)
  312. this.$refs.productMsg.setFileList(str)
  313. this.form.productMsg = str
  314. } else {
  315. this.$refs.productMsg.setFileList('')
  316. this.form.productMsg = ''
  317. }
  318. this.$refs.editor.setHtml(res.data.description)
  319. this.$refs.otherDesc.setHtml(res.data.otherDesc)
  320. } else {
  321. this.$refs.ruleForm.resetFields()
  322. }
  323. })
  324. },
  325. // 提交
  326. handleSubmit (e) {
  327. e.preventDefault()
  328. const _this = this
  329. this.$refs.ruleForm.validate(valid => {
  330. if (valid) {
  331. const form = JSON.parse(JSON.stringify(_this.form))
  332. if (!form.productTypeSn3) {
  333. this.$message.warning('产品分类未选到第三级,请修改后再提交!')
  334. return false
  335. }
  336. form.id = _this.$route.params.id ? _this.$route.params.id : undefined
  337. form.productPicList = []
  338. if (form.productMsg) {
  339. const arr = form.productMsg.split(',')
  340. arr.map(item => {
  341. form.productPicList.push({ imageUrl: item })
  342. })
  343. }
  344. delete form.productMsg
  345. delete form.productType
  346. delete form.updateDate
  347. _this.spinning = true
  348. productSave(form).then(res => {
  349. if (res.status == 200) {
  350. _this.$message.success(res.message)
  351. setTimeout(() => {
  352. _this.handleBack()
  353. _this.spinning = false
  354. }, 1000)
  355. } else {
  356. _this.spinning = false
  357. }
  358. })
  359. } else {
  360. console.log('error submit!!')
  361. return false
  362. }
  363. })
  364. },
  365. // 返回
  366. handleBack () {
  367. this.$router.push({ path: '/productManagement/productInfo/list', query: { closeLastOldTab: true } })
  368. },
  369. // 产品图片上传
  370. changeImage (file) {
  371. console.log(file.split(","))
  372. this.form.productMsg = file
  373. },
  374. validateQrCode (rule, value, callback) {
  375. const reg = /^[0-9a-zA-Z]+$/
  376. if (value && !reg.test(value)) {
  377. callback('条形码由大小写英文字母和数字组成')
  378. } else {
  379. callback()
  380. }
  381. },
  382. // 产品说明 文本编辑器
  383. editorDescriptionChange (html, text) {
  384. this.form.description = html
  385. },
  386. // 其他说明 文本编辑器
  387. editorOtherChange (html, text) {
  388. this.form.otherDesc = html
  389. },
  390. // 产品分类 change
  391. changeProductType (val, opt) {
  392. this.form.productTypeSn1 = val[0] ? val[0] : ''
  393. this.form.productTypeSn2 = val[1] ? val[1] : ''
  394. this.form.productTypeSn3 = val[2] ? val[2] : ''
  395. },
  396. // 产品品牌 列表
  397. getProductBrand () {
  398. productBrandQuery({}).then(res => {
  399. if (res.status == 200) {
  400. this.productBrandList = res.data
  401. } else {
  402. this.productBrandList = []
  403. }
  404. })
  405. },
  406. // 产品分类 列表
  407. getProductType () {
  408. productTypeQueryAll({}).then(res => {
  409. if (res.status == 200) {
  410. if (res.data && res.data.length > 0) {
  411. // 递归处理disabled禁用
  412. this.recursionFun(res.data, false)
  413. this.productTypeList = res.data
  414. } else {
  415. this.productTypeList = []
  416. }
  417. } else {
  418. this.productTypeList = []
  419. }
  420. })
  421. },
  422. // 递归函数
  423. recursionFun (data, state) {
  424. if (data) {
  425. data.map((item, index) => {
  426. // enabledFlag为0表示禁用,父级禁用则子级也为禁用
  427. if ((item.enabledFlag && item.enabledFlag == 0) || state) {
  428. item.disabled = true
  429. } else {
  430. item.disabled = false
  431. }
  432. if (item.children && item.children.length == 0) {
  433. delete item.children
  434. } else {
  435. this.recursionFun(item.children, item.disabled)
  436. }
  437. })
  438. }
  439. },
  440. filterOption (input, option) {
  441. return (
  442. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  443. )
  444. },
  445. pageInit () {
  446. this.$refs.productMsg.setFileList('')
  447. this.$refs.editor.setHtml('')
  448. this.$refs.otherDesc.setHtml('')
  449. this.$refs.ruleForm.resetFields()
  450. this.form.packQtyUnit = undefined
  451. this.getProductBrand()
  452. this.getProductType()
  453. if (this.$route.params.id) { // 编辑页
  454. this.getDetail()
  455. }
  456. }
  457. },
  458. mounted () {
  459. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  460. this.pageInit()
  461. }
  462. },
  463. activated () {
  464. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  465. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  466. this.pageInit()
  467. }
  468. },
  469. beforeRouteEnter (to, from, next) {
  470. next(vm => {})
  471. }
  472. }
  473. </script>
  474. <style lang="less">
  475. .productInfoEdit-wrap{
  476. position: relative;
  477. height: 100%;
  478. padding-bottom: 51px;
  479. box-sizing: border-box;
  480. >.ant-spin-nested-loading{
  481. overflow-y: scroll;
  482. height: 100%;
  483. }
  484. .productInfoEdit-cont{
  485. margin-bottom: 10px;
  486. }
  487. .upload{
  488. width: 100%!important;
  489. }
  490. // 文本编辑器 工具栏样式换行
  491. .productInfoEdit-editor{
  492. .w-e-toolbar{
  493. flex-wrap: wrap;
  494. z-index: 0;
  495. }
  496. }
  497. .affix{
  498. .ant-affix{
  499. z-index: 101;
  500. }
  501. }
  502. }
  503. </style>