edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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-affix :offset-bottom="0" class="affix">
  200. <div style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  201. <a-button
  202. type="primary"
  203. class="button-primary"
  204. id="productInfoEdit-submit-btn"
  205. size="large"
  206. @click="handleSubmit"
  207. style="padding: 0 60px;">提交</a-button>
  208. </div>
  209. </a-affix>
  210. </a-spin>
  211. </div>
  212. </template>
  213. <script>
  214. import { VSelect, Upload } from '@/components'
  215. import Editor from '@/components/WEeditor'
  216. import { productSave, productSnDetail } from '@/api/product'
  217. import { productTypeQueryAll } from '@/api/productType'
  218. import { productBrandQuery } from '@/api/productBrand'
  219. export default {
  220. components: { VSelect, Upload, Editor },
  221. data () {
  222. return {
  223. spinning: false,
  224. formItemLayout: {
  225. labelCol: { span: 4 },
  226. wrapperCol: { span: 16 }
  227. },
  228. form: {
  229. name: '', // 产品名称
  230. code: '', // 产品编码
  231. origCode: '', // 原厂编码
  232. otherCode: '', // 其他编码
  233. productBrandSn: undefined, // 产品品牌
  234. productTypeSn1: '', // 产品一级分类
  235. productTypeSn2: '', // 产品二级分类
  236. productTypeSn3: '', // 产品三级分类
  237. productType: [], // 产品分类
  238. unit: undefined, // 单位
  239. packQty: '', // 包装数
  240. packQtyUnit: undefined, // 包装数单位
  241. arrowFalg: undefined, // 是否箭冠产品
  242. productMsg: '', // 产品图片
  243. size: '', // 产品尺寸
  244. weight: '', // 产品重量
  245. color: undefined, // 颜色
  246. boxSize: '', // 内核尺寸
  247. description: '', // 产品说明
  248. otherDesc: '' // 其他说明
  249. },
  250. rules: {
  251. name: [
  252. { required: true, message: '请输入产品名称', trigger: 'blur' }
  253. ],
  254. code: [
  255. { required: true, message: '请输入产品编码', trigger: 'blur' }
  256. ],
  257. productBrandSn: [
  258. { required: true, message: '请选择产品品牌', trigger: 'change' }
  259. ],
  260. productType: [
  261. { required: true, message: '请选择产品分类', trigger: 'change' }
  262. ],
  263. unit: [
  264. { required: true, message: '请选择单位', trigger: 'change' }
  265. ],
  266. packQty: [
  267. { required: true, message: '请输入包装数', trigger: 'blur' }
  268. ],
  269. arrowFalg: [
  270. { required: true, message: '请选择是否为箭冠产品', trigger: 'change' }
  271. ]
  272. },
  273. productBrandList: [], // 品牌下拉数据
  274. productTypeList: [] // 分类下拉数据
  275. }
  276. },
  277. methods: {
  278. // 详情
  279. getDetail () {
  280. productSnDetail({ sn: this.$route.params.sn }).then(res => {
  281. if (res.status == 200) {
  282. const data = res.data
  283. this.form = Object.assign(this.form, data)
  284. this.form.productType = [ this.form.productTypeSn1, this.form.productTypeSn2, this.form.productTypeSn3 ]
  285. if (res.data.productPicList && res.data.productPicList.length > 0) {
  286. let str = ''
  287. res.data.productPicList.map(item => {
  288. if (item.imageUrl) {
  289. str += item.imageUrl + ','
  290. }
  291. })
  292. str = str.substr(0, str.length - 1)
  293. this.$refs.productMsg.setFileList(str)
  294. } else {
  295. this.$refs.productMsg.setFileList('')
  296. }
  297. this.$refs.editor.setHtml(res.data.description)
  298. this.$refs.otherDesc.setHtml(res.data.otherDesc)
  299. } else {
  300. this.$refs.ruleForm.resetFields()
  301. }
  302. })
  303. },
  304. // 提交
  305. handleSubmit (e) {
  306. e.preventDefault()
  307. const _this = this
  308. if (!this.form.productTypeSn3) {
  309. this.$message.warning('产品分类未选到第三级,请修改后再提交!')
  310. return
  311. }
  312. this.$refs.ruleForm.validate(valid => {
  313. if (valid) {
  314. const form = JSON.parse(JSON.stringify(_this.form))
  315. form.id = _this.$route.params.id ? _this.$route.params.id : undefined
  316. form.productPicList = []
  317. if (form.productMsg) {
  318. const arr = form.productMsg.split(',')
  319. arr.map(item => {
  320. form.productPicList.push({ imageUrl: item })
  321. })
  322. }
  323. delete form.productMsg
  324. delete form.productType
  325. delete form.updateDate
  326. _this.spinning = true
  327. productSave(form).then(res => {
  328. if (res.status == 200) {
  329. _this.$message.success(res.message)
  330. setTimeout(() => {
  331. _this.handleBack()
  332. _this.spinning = false
  333. }, 1000)
  334. } else {
  335. _this.spinning = false
  336. }
  337. })
  338. } else {
  339. console.log('error submit!!')
  340. return false
  341. }
  342. })
  343. },
  344. // 返回
  345. handleBack () {
  346. this.$router.push({ path: '/productManagement/productInfo/list', query: { closeLastOldTab: true } })
  347. },
  348. // 产品图片上传
  349. changeImage (file) {
  350. this.form.productMsg = file
  351. },
  352. // 产品说明 文本编辑器
  353. editorDescriptionChange (html, text) {
  354. this.form.description = html
  355. },
  356. // 其他说明 文本编辑器
  357. editorOtherChange (html, text) {
  358. this.form.otherDesc = html
  359. },
  360. // 产品分类 change
  361. changeProductType (val, opt) {
  362. this.form.productTypeSn1 = val[0] ? val[0] : ''
  363. this.form.productTypeSn2 = val[1] ? val[1] : ''
  364. this.form.productTypeSn3 = val[2] ? val[2] : ''
  365. },
  366. // 产品品牌 列表
  367. getProductBrand () {
  368. productBrandQuery({}).then(res => {
  369. if (res.status == 200) {
  370. this.productBrandList = res.data
  371. } else {
  372. this.productBrandList = []
  373. }
  374. })
  375. },
  376. // 产品分类 列表
  377. getProductType () {
  378. productTypeQueryAll({}).then(res => {
  379. if (res.status == 200) {
  380. if (res.data && res.data.length > 0) {
  381. // 递归处理disabled禁用
  382. this.recursionFun(res.data, false)
  383. this.productTypeList = res.data
  384. } else {
  385. this.productTypeList = []
  386. }
  387. } else {
  388. this.productTypeList = []
  389. }
  390. })
  391. },
  392. // 递归函数
  393. recursionFun (data, state) {
  394. if (data) {
  395. data.map((item, index) => {
  396. // enabledFlag为0表示禁用,父级禁用则子级也为禁用
  397. if ((item.enabledFlag && item.enabledFlag == 0) || state) {
  398. item.disabled = true
  399. } else {
  400. item.disabled = false
  401. }
  402. if (item.children && item.children.length == 0) {
  403. delete item.children
  404. } else {
  405. this.recursionFun(item.children, item.disabled)
  406. }
  407. })
  408. }
  409. },
  410. filterOption (input, option) {
  411. return (
  412. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  413. )
  414. }
  415. },
  416. beforeRouteEnter (to, from, next) {
  417. next(vm => {
  418. vm.$refs.productMsg.setFileList('')
  419. vm.$refs.editor.setHtml('')
  420. vm.$refs.otherDesc.setHtml('')
  421. vm.$refs.ruleForm.resetFields()
  422. vm.getProductBrand()
  423. vm.getProductType()
  424. if (vm.$route.params.id) { // 编辑页
  425. vm.getDetail()
  426. }
  427. })
  428. }
  429. }
  430. </script>
  431. <style lang="less">
  432. .productInfoEdit-wrap{
  433. .productInfoEdit-cont{
  434. margin-bottom: 10px;
  435. }
  436. .upload{
  437. width: 100%!important;
  438. }
  439. // 文本编辑器 工具栏样式换行
  440. .productInfoEdit-editor{
  441. .w-e-toolbar{
  442. flex-wrap: wrap;
  443. z-index: 0;
  444. }
  445. }
  446. .affix{
  447. .ant-affix{
  448. z-index: 101;
  449. }
  450. }
  451. }
  452. </style>