edit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <div class="productInfoEdit-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" class="productInfoEdit-cont" >
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="purchaseOrderEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  7. </template>
  8. </a-page-header>
  9. <a-form-model
  10. id="productInfoEdit-form"
  11. ref="ruleForm"
  12. :model="form"
  13. :rules="rules"
  14. :label-col="formItemLayout.labelCol"
  15. :wrapper-col="formItemLayout.wrapperCol">
  16. <a-card :bordered="false" class="productInfoEdit-cont">
  17. <a-row>
  18. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  19. <a-form-model-item label="产品名称" prop="name">
  20. <a-input v-model.trim="form.name" id="productInfoEdit-name" :maxLength="100" allowClear placeholder="请输入产品名称(最多100个字符)" />
  21. </a-form-model-item>
  22. </a-col>
  23. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  24. <a-form-model-item label="产品编码" prop="code">
  25. <a-input
  26. id="productInfoEdit-code"
  27. :maxLength="100"
  28. :disabled="form.state&&form.state!='WAIT'"
  29. v-model="form.code"
  30. placeholder="请输入产品编码(最多100个字符)"
  31. allowClear />
  32. </a-form-model-item>
  33. </a-col>
  34. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  35. <a-form-model-item label="原厂编码" prop="origCode">
  36. <a-input
  37. id="productInfoEdit-origCode"
  38. :maxLength="200"
  39. v-model="form.origCode"
  40. placeholder="请输入(最多200个字符,多个编码用逗号隔开)"
  41. allowClear />
  42. </a-form-model-item>
  43. </a-col>
  44. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  45. <a-form-model-item label="其他编码" prop="otherCode">
  46. <a-input
  47. id="productInfoEdit-otherCode"
  48. :maxLength="60"
  49. v-model="form.otherCode"
  50. placeholder="请输入(最多60个字符,多个编码用逗号隔开)"
  51. allowClear />
  52. </a-form-model-item>
  53. </a-col>
  54. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  55. <a-form-model-item label="产品品牌" prop="productBrandSn">
  56. <a-select
  57. id="productInfoEdit-productBrand"
  58. placeholder="请选择产品品牌"
  59. allowClear
  60. v-model="form.productBrandSn"
  61. :showSearch="true"
  62. option-filter-prop="children"
  63. :filter-option="filterOption">
  64. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn" :disabled="item.enabledFlag==0">{{ item.brandName }}</a-select-option>
  65. </a-select>
  66. </a-form-model-item>
  67. </a-col>
  68. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  69. <a-form-model-item label="产品分类" prop="productType">
  70. <a-cascader
  71. :disabled="form.state&&form.state!='WAIT'"
  72. expand-trigger="hover"
  73. @change="changeProductType"
  74. :options="productTypeList"
  75. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  76. id="productInfoEdit-productType"
  77. placeholder="请选择产品分类"
  78. allowClear
  79. v-model="form.productType" />
  80. </a-form-model-item>
  81. </a-col>
  82. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  83. <a-form-model-item label="单位" prop="unit">
  84. <v-select
  85. code="PRODUCT_UNIT"
  86. id="productInfoEdit-unit"
  87. v-model="form.unit"
  88. allowClear
  89. placeholder="请选择单位"
  90. ></v-select>
  91. </a-form-model-item>
  92. </a-col>
  93. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  94. <a-form-model-item label="包装数" prop="packQty" :label-col="{span:4}" :wrapper-col="{span:16}">
  95. <a-row>
  96. <a-col :span="14">
  97. <a-input-number
  98. id="productInfoEdit-packQty"
  99. v-model="form.packQty"
  100. :precision="0"
  101. :min="1"
  102. :max="999999"
  103. placeholder="请输入"
  104. style="width: 70%;" /><span>{{ form.unit }}/</span>
  105. </a-col>
  106. <a-col :span="10">
  107. <v-select
  108. code="PRODUCT_UNIT"
  109. id="productLevelEdit-packQtyUnit"
  110. v-model="form.packQtyUnit"
  111. allowClear
  112. placeholder="包装数单位"
  113. ></v-select>
  114. </a-col>
  115. </a-row>
  116. </a-form-model-item>
  117. </a-col>
  118. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  119. <a-form-model-item label="箭冠产品" prop="arrowFalg">
  120. <v-select
  121. code="ARROW_FALG"
  122. id="productInfoEdit-arrowFalg"
  123. v-model="form.arrowFalg"
  124. allowClear
  125. placeholder="请选择"
  126. ></v-select>
  127. </a-form-model-item>
  128. </a-col>
  129. </a-row>
  130. <a-row>
  131. <a-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16">
  132. <a-form-model-item label="产品图片" help="说明:图片比例1:1,尺寸大于300*300px,首张为主图,最多5张。" :label-col="{span:3}" :wrapper-col="{span:18}">
  133. <Upload
  134. class="upload"
  135. id="productInfoEdit-productMsg"
  136. v-model="form.productMsg"
  137. ref="productMsg"
  138. @change="changeImage"
  139. :maxNums="5"
  140. listType="picture-card" ></Upload>
  141. </a-form-model-item>
  142. </a-col>
  143. </a-row>
  144. <a-row>
  145. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  146. <a-form-model-item label="产品尺寸" prop="size">
  147. <a-input
  148. v-model.trim="form.size"
  149. id="productInfoEdit-size"
  150. :maxLength="50"
  151. allowClear
  152. placeholder="请输入产品尺寸(最多50个字符)" />
  153. </a-form-model-item>
  154. </a-col>
  155. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  156. <a-form-model-item label="产品重量" prop="weight">
  157. <a-input
  158. v-model.trim="form.weight"
  159. id="productInfoEdit-weight"
  160. :maxLength="50"
  161. allowClear
  162. placeholder="请输入产品重量(最多50个字符)" />
  163. </a-form-model-item>
  164. </a-col>
  165. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  166. <a-form-model-item label="颜色" prop="color">
  167. <a-input
  168. v-model.trim="form.color"
  169. id="productLevelEdit-color"
  170. :maxLength="50"
  171. allowClear
  172. placeholder="请输入颜色(最多50个字符)" />
  173. </a-form-model-item>
  174. </a-col>
  175. <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  176. <a-form-model-item label="产品内盒尺寸" prop="boxSize">
  177. <a-input
  178. v-model.trim="form.boxSize"
  179. id="productInfoEdit-boxSize"
  180. :maxLength="50"
  181. allowClear
  182. placeholder="请输入产品内盒尺寸(最多50个字符)" />
  183. </a-form-model-item>
  184. </a-col>
  185. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  186. <a-form-model-item label="产品说明" prop="description" :label-col="{span:2}" :wrapper-col="{span:20}">
  187. <editor id="productInfoEdit-description" ref="editor" class="productInfoEdit-description" @on-change="editorDescriptionChange" :cache="false"></editor>
  188. </a-form-model-item>
  189. </a-col>
  190. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  191. <a-form-model-item label="其他说明" prop="otherDesc" :label-col="{span:2}" :wrapper-col="{span:20}">
  192. <editor id="productInfoEdit-other-otherDesc" ref="otherDesc" class="productInfoEdit-otherDesc" @on-change="editorOtherChange" :cache="false"></editor>
  193. </a-form-model-item>
  194. </a-col>
  195. </a-row>
  196. </a-card>
  197. </a-form-model>
  198. <a-affix :offset-bottom="0" class="affix">
  199. <div style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  200. <a-button
  201. type="primary"
  202. class="button-primary"
  203. id="productInfoEdit-submit-btn"
  204. size="large"
  205. @click="handleSubmit"
  206. style="padding: 0 60px;">提交</a-button>
  207. </div>
  208. </a-affix>
  209. </div>
  210. </template>
  211. <script>
  212. import { VSelect, Upload } from '@/components'
  213. import Editor from '@/components/WEeditor'
  214. import { productSave, productSnDetail } from '@/api/product'
  215. import { productTypeQuery } from '@/api/productType'
  216. import { productBrandQuery } from '@/api/productBrand'
  217. export default {
  218. components: { VSelect, Upload, Editor },
  219. data () {
  220. return {
  221. formItemLayout: {
  222. labelCol: { span: 4 },
  223. wrapperCol: { span: 16 }
  224. },
  225. form: {
  226. name: '', // 产品名称
  227. code: '', // 产品编码
  228. origCode: '', // 原厂编码
  229. otherCode: '', // 其他编码
  230. productBrandSn: undefined, // 产品品牌
  231. productTypeSn1: '', // 产品一级分类
  232. productTypeSn2: '', // 产品二级分类
  233. productTypeSn3: '', // 产品三级分类
  234. productType: [], // 产品分类
  235. unit: undefined, // 单位
  236. packQty: '', // 包装数
  237. packQtyUnit: undefined, // 包装数单位
  238. arrowFalg: undefined, // 是否箭冠产品
  239. productMsg: '', // 产品图片
  240. size: '', // 产品尺寸
  241. weight: '', // 产品重量
  242. color: undefined, // 颜色
  243. boxSize: '', // 内核尺寸
  244. description: '', // 产品说明
  245. otherDesc: '' // 其他说明
  246. },
  247. rules: {
  248. name: [
  249. { required: true, message: '请输入产品名称', trigger: 'blur' }
  250. ],
  251. code: [
  252. { required: true, message: '请输入产品编码', trigger: 'blur' }
  253. ],
  254. productBrandSn: [
  255. { required: true, message: '请选择产品品牌', trigger: 'change' }
  256. ],
  257. productType: [
  258. { required: true, message: '请选择产品分类', trigger: 'change' }
  259. ],
  260. unit: [
  261. { required: true, message: '请选择单位', trigger: 'change' }
  262. ],
  263. packQty: [
  264. { required: true, message: '请输入包装数', trigger: 'blur' }
  265. ],
  266. arrowFalg: [
  267. { required: true, message: '请选择是否为箭冠产品', trigger: 'change' }
  268. ]
  269. },
  270. productBrandList: [], // 品牌下拉数据
  271. productTypeList: [] // 分类下拉数据
  272. }
  273. },
  274. methods: {
  275. // 详情
  276. getDetail () {
  277. productSnDetail({ sn: this.$route.params.sn }).then(res => {
  278. if (res.status == 200) {
  279. const data = res.data
  280. this.form = Object.assign(this.form, data)
  281. this.form.productType = [ this.form.productTypeSn1, this.form.productTypeSn2, this.form.productTypeSn3 ]
  282. this.$refs.productMsg.setFileList(res.data.productMsg)
  283. this.$refs.editor.setHtml(res.data.description)
  284. this.$refs.otherDesc.setHtml(res.data.otherDesc)
  285. } else {
  286. this.$refs.ruleForm.resetFields()
  287. }
  288. })
  289. },
  290. // 提交
  291. handleSubmit (e) {
  292. e.preventDefault()
  293. const _this = this
  294. if (!this.form.productTypeSn3) {
  295. this.$message.warning('产品分类未选到第三级,请修改后再提交!')
  296. return
  297. }
  298. this.$refs.ruleForm.validate(valid => {
  299. if (valid) {
  300. const form = JSON.parse(JSON.stringify(_this.form))
  301. form.id = _this.$route.params.id ? _this.$route.params.id : undefined
  302. delete form.productType
  303. productSave(form).then(res => {
  304. if (res.status == 200) {
  305. _this.$message.success(res.message)
  306. setTimeout(() => {
  307. _this.handleBack()
  308. }, 1000)
  309. }
  310. })
  311. } else {
  312. console.log('error submit!!')
  313. return false
  314. }
  315. })
  316. },
  317. // 返回
  318. handleBack () {
  319. this.$router.push({ path: '/productManagement/productInfo/list' })
  320. },
  321. // 产品图片上传
  322. changeImage (file) {
  323. this.form.productMsg = file
  324. },
  325. // 产品说明 文本编辑器
  326. editorDescriptionChange (html, text) {
  327. this.form.description = html
  328. },
  329. // 其他说明 文本编辑器
  330. editorOtherChange (html, text) {
  331. this.form.otherDesc = html
  332. },
  333. // 产品分类 change
  334. changeProductType (val, opt) {
  335. this.form.productTypeSn1 = val[0] ? val[0] : ''
  336. this.form.productTypeSn2 = val[1] ? val[1] : ''
  337. this.form.productTypeSn3 = val[2] ? val[2] : ''
  338. },
  339. // 产品品牌 列表
  340. getProductBrand () {
  341. productBrandQuery({}).then(res => {
  342. if (res.status == 200) {
  343. this.productBrandList = res.data
  344. } else {
  345. this.productBrandList = []
  346. }
  347. })
  348. },
  349. // 产品分类 列表
  350. getProductType () {
  351. productTypeQuery({}).then(res => {
  352. if (res.status == 200) {
  353. this.productTypeList = res.data
  354. } else {
  355. this.productTypeList = []
  356. }
  357. })
  358. },
  359. filterOption (input, option) {
  360. return (
  361. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  362. )
  363. }
  364. },
  365. beforeRouteEnter (to, from, next) {
  366. next(vm => {
  367. vm.$refs.productMsg.setFileList('')
  368. vm.$refs.editor.setHtml('')
  369. vm.$refs.otherDesc.setHtml('')
  370. vm.$refs.ruleForm.resetFields()
  371. vm.getProductBrand()
  372. vm.getProductType()
  373. if (vm.$route.params.id) { // 编辑页
  374. vm.getDetail()
  375. }
  376. })
  377. }
  378. }
  379. </script>
  380. <style lang="less">
  381. .productInfoEdit-wrap{
  382. .productInfoEdit-cont{
  383. margin-bottom: 10px;
  384. }
  385. .upload{
  386. width: 100%!important;
  387. }
  388. // 文本编辑器 工具栏样式换行
  389. .productInfoEdit-editor{
  390. .w-e-toolbar{
  391. flex-wrap: wrap;
  392. z-index: 0;
  393. }
  394. }
  395. .affix{
  396. .ant-affix{
  397. z-index: 101;
  398. }
  399. }
  400. }
  401. </style>