edit.vue 17 KB

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