123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- <template>
- <div class="productInfoEdit-wrap">
- <a-spin :spinning="spinning" tip="Loading...">
- <a-page-header :ghost="false" :backIcon="false" class="productInfoEdit-cont" >
-
- <template slot="subTitle">
- <a id="purchaseOrderEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
- </template>
- </a-page-header>
- <a-form-model
- id="productInfoEdit-form"
- ref="ruleForm"
- :model="form"
- :rules="rules"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol">
- <a-card :bordered="false" class="productInfoEdit-cont">
- <a-row>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="产品名称" prop="name">
- <a-input v-model.trim="form.name" id="productInfoEdit-name" :maxLength="100" allowClear placeholder="请输入产品名称(最多100个字符)" />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="产品编码" prop="code">
- <a-input
- id="productInfoEdit-code"
- :maxLength="100"
- :disabled="form.state&&form.state!='WAIT'"
- v-model="form.code"
- placeholder="请输入产品编码(最多100个字符)"
- allowClear />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="原厂编码" prop="origCode">
- <a-input
- id="productInfoEdit-origCode"
- :maxLength="200"
- v-model="form.origCode"
- placeholder="请输入(最多200个字符,多个编码用逗号隔开)"
- allowClear />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="其他编码" prop="otherCode">
- <a-input
- id="productInfoEdit-otherCode"
- :maxLength="60"
- v-model="form.otherCode"
- placeholder="请输入(最多60个字符,多个编码用逗号隔开)"
- allowClear />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="产品品牌" prop="productBrandSn">
- <a-select
- id="productInfoEdit-productBrand"
- placeholder="请选择产品品牌"
- allowClear
- v-model="form.productBrandSn"
- :showSearch="true"
- option-filter-prop="children"
- :filter-option="filterOption">
- <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn" :disabled="item.enabledFlag==0">{{ item.brandName }}</a-select-option>
- </a-select>
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="产品分类" prop="productType">
- <a-cascader
- :disabled="form.state&&form.state!='WAIT'"
- expand-trigger="hover"
- @change="changeProductType"
- :options="productTypeList"
- :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
- id="productInfoEdit-productType"
- placeholder="请选择产品分类"
- allowClear
- v-model="form.productType" />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="单位" prop="unit">
- <v-select
- code="PRODUCT_UNIT"
- id="productInfoEdit-unit"
- v-model="form.unit"
- allowClear
- placeholder="请选择单位"
- ></v-select>
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="包装数" prop="packQty" :label-col="{span:4}" :wrapper-col="{span:16}">
- <a-row>
- <a-col :span="14">
- <a-input-number
- id="productInfoEdit-packQty"
- v-model="form.packQty"
- :precision="0"
- :min="1"
- :max="999999"
- placeholder="请输入"
- style="width: 70%;" /><span>{{ form.unit }}/</span>
- </a-col>
- <a-col :span="10">
- <v-select
- code="PRODUCT_PACK_UNIT"
- id="productLevelEdit-packQtyUnit"
- v-model="form.packQtyUnit"
- allowClear
- placeholder="包装数单位"
- ></v-select>
- </a-col>
- </a-row>
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="箭冠产品" prop="arrowFalg">
- <v-select
- code="ARROW_FALG"
- id="productInfoEdit-arrowFalg"
- v-model="form.arrowFalg"
- allowClear
- placeholder="请选择"
- ></v-select>
- </a-form-model-item>
- </a-col>
- </a-row>
- <a-row>
- <a-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16">
- <a-form-model-item label="产品图片" help="说明:图片比例1:1,尺寸大于300*300px,首张为主图,最多5张。" :label-col="{span:3}" :wrapper-col="{span:18}">
- <Upload
- class="upload"
- id="productInfoEdit-productMsg"
- v-model="form.productMsg"
- ref="productMsg"
- @change="changeImage"
- :maxNums="5"
- listType="picture-card" ></Upload>
- </a-form-model-item>
- </a-col>
- </a-row>
- <a-row>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="产品尺寸" prop="size">
- <a-input
- v-model.trim="form.size"
- id="productInfoEdit-size"
- :maxLength="50"
- allowClear
- placeholder="请输入产品尺寸(最多50个字符)" />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="产品重量" prop="weight">
- <a-input
- v-model.trim="form.weight"
- id="productInfoEdit-weight"
- :maxLength="50"
- allowClear
- placeholder="请输入产品重量(最多50个字符)" />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="颜色" prop="color">
- <a-input
- v-model.trim="form.color"
- id="productLevelEdit-color"
- :maxLength="50"
- allowClear
- placeholder="请输入颜色(最多50个字符)" />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
- <a-form-model-item label="产品内盒尺寸" prop="boxSize">
- <a-input
- v-model.trim="form.boxSize"
- id="productInfoEdit-boxSize"
- :maxLength="50"
- allowClear
- placeholder="请输入产品内盒尺寸(最多50个字符)" />
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
- <a-form-model-item label="产品说明" prop="description" :label-col="{span:2}" :wrapper-col="{span:20}">
- <editor id="productInfoEdit-description" ref="editor" class="productInfoEdit-description" @on-change="editorDescriptionChange" :cache="false"></editor>
- </a-form-model-item>
- </a-col>
- <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
- <a-form-model-item label="其他说明" prop="otherDesc" :label-col="{span:2}" :wrapper-col="{span:20}">
- <editor id="productInfoEdit-other-otherDesc" ref="otherDesc" class="productInfoEdit-otherDesc" @on-change="editorOtherChange" :cache="false"></editor>
- </a-form-model-item>
- </a-col>
- </a-row>
- </a-card>
- </a-form-model>
- </a-spin>
- <div class="affix-cont">
- <a-button
- type="primary"
- class="button-primary"
- :disabled="spinning"
- id="productInfoEdit-submit-btn"
- size="large"
- @click="handleSubmit"
- style="padding: 0 60px;">提交</a-button>
- </div>
- </div>
- </template>
- <script>
- import { VSelect, Upload } from '@/components'
- import Editor from '@/components/WEeditor'
- import { productSave, productSnDetail } from '@/api/product'
- import { productTypeQueryAll } from '@/api/productType'
- import { productBrandQuery } from '@/api/productBrand'
- export default {
- components: { VSelect, Upload, Editor },
- data () {
- return {
- spinning: false,
- formItemLayout: {
- labelCol: { span: 4 },
- wrapperCol: { span: 16 }
- },
- form: {
- name: '',
- code: '',
- origCode: '',
- otherCode: '',
- productBrandSn: undefined,
- productTypeSn1: '',
- productTypeSn2: '',
- productTypeSn3: '',
- productType: [],
- unit: undefined,
- packQty: '',
- packQtyUnit: undefined,
- arrowFalg: undefined,
- productMsg: '',
- size: '',
- weight: '',
- color: undefined,
- boxSize: '',
- description: '',
- otherDesc: ''
- },
- rules: {
- name: [
- { required: true, message: '请输入产品名称', trigger: 'blur' }
- ],
- code: [
- { required: true, message: '请输入产品编码', trigger: 'blur' }
- ],
- productBrandSn: [
- { required: true, message: '请选择产品品牌', trigger: 'change' }
- ],
- productType: [
- { required: true, message: '请选择产品分类', trigger: 'change' }
- ],
- unit: [
- { required: true, message: '请选择单位', trigger: 'change' }
- ],
- packQty: [
- { required: true, message: '请输入包装数', trigger: 'blur' }
- ],
- arrowFalg: [
- { required: true, message: '请选择是否为箭冠产品', trigger: 'change' }
- ]
- },
- productBrandList: [],
- productTypeList: []
- }
- },
- methods: {
-
- getDetail () {
- productSnDetail({ sn: this.$route.params.sn }).then(res => {
- if (res.status == 200) {
- const data = res.data
- this.form = Object.assign(this.form, data)
- this.form.productType = [ this.form.productTypeSn1, this.form.productTypeSn2, this.form.productTypeSn3 ]
- if (res.data.productPicList && res.data.productPicList.length > 0) {
- let str = ''
- res.data.productPicList.map(item => {
- if (item.imageUrl) {
- str += item.imageUrl + ','
- }
- })
- str = str.substr(0, str.length - 1)
- this.$refs.productMsg.setFileList(str)
- this.form.productMsg = str
- } else {
- this.$refs.productMsg.setFileList('')
- this.form.productMsg = ''
- }
- this.$refs.editor.setHtml(res.data.description)
- this.$refs.otherDesc.setHtml(res.data.otherDesc)
- } else {
- this.$refs.ruleForm.resetFields()
- }
- })
- },
-
- handleSubmit (e) {
- e.preventDefault()
- const _this = this
- if (!this.form.productTypeSn3) {
- this.$message.warning('产品分类未选到第三级,请修改后再提交!')
- return
- }
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- const form = JSON.parse(JSON.stringify(_this.form))
- form.id = _this.$route.params.id ? _this.$route.params.id : undefined
- form.productPicList = []
- if (form.productMsg) {
- const arr = form.productMsg.split(',')
- arr.map(item => {
- form.productPicList.push({ imageUrl: item })
- })
- }
- delete form.productMsg
- delete form.productType
- delete form.updateDate
- _this.spinning = true
- productSave(form).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- setTimeout(() => {
- _this.handleBack()
- _this.spinning = false
- }, 1000)
- } else {
- _this.spinning = false
- }
- })
- } else {
- console.log('error submit!!')
- return false
- }
- })
- },
-
- handleBack () {
- this.$router.push({ path: '/productManagement/productInfo/list', query: { closeLastOldTab: true } })
- },
-
- changeImage (file) {
- this.form.productMsg = file
- },
-
- editorDescriptionChange (html, text) {
- this.form.description = html
- },
-
- editorOtherChange (html, text) {
- this.form.otherDesc = html
- },
-
- changeProductType (val, opt) {
- this.form.productTypeSn1 = val[0] ? val[0] : ''
- this.form.productTypeSn2 = val[1] ? val[1] : ''
- this.form.productTypeSn3 = val[2] ? val[2] : ''
- },
-
- getProductBrand () {
- productBrandQuery({}).then(res => {
- if (res.status == 200) {
- this.productBrandList = res.data
- } else {
- this.productBrandList = []
- }
- })
- },
-
- getProductType () {
- productTypeQueryAll({}).then(res => {
- if (res.status == 200) {
- if (res.data && res.data.length > 0) {
-
- this.recursionFun(res.data, false)
- this.productTypeList = res.data
- } else {
- this.productTypeList = []
- }
- } else {
- this.productTypeList = []
- }
- })
- },
-
- recursionFun (data, state) {
- if (data) {
- data.map((item, index) => {
-
- if ((item.enabledFlag && item.enabledFlag == 0) || state) {
- item.disabled = true
- } else {
- item.disabled = false
- }
- if (item.children && item.children.length == 0) {
- delete item.children
- } else {
- this.recursionFun(item.children, item.disabled)
- }
- })
- }
- },
- filterOption (input, option) {
- return (
- option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
- )
- },
- pageInit () {
- this.$refs.productMsg.setFileList('')
- this.$refs.editor.setHtml('')
- this.$refs.otherDesc.setHtml('')
- this.$refs.ruleForm.resetFields()
- this.getProductBrand()
- this.getProductType()
- if (this.$route.params.id) {
- this.getDetail()
- }
- }
- },
- mounted () {
- if (!this.$store.state.app.isNewTab) {
- this.pageInit()
- }
- },
- activated () {
-
- if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
- this.pageInit()
- }
- },
- beforeRouteEnter (to, from, next) {
- next(vm => {})
- }
- }
- </script>
- <style lang="less">
- .productInfoEdit-wrap{
- position: relative;
- height: 100%;
- padding-bottom: 51px;
- box-sizing: border-box;
- >.ant-spin-nested-loading{
- overflow-y: scroll;
- height: 100%;
- }
- .productInfoEdit-cont{
- margin-bottom: 10px;
- }
- .upload{
- width: 100%!important;
- }
- // 文本编辑器 工具栏样式换行
- .productInfoEdit-editor{
- .w-e-toolbar{
- flex-wrap: wrap;
- z-index: 0;
- }
- }
- .affix{
- .ant-affix{
- z-index: 101;
- }
- }
- }
- </style>
|