edit.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <a-card size="small" :bordered="false" class="productInfoEdit-table-page-wrapper">
  3. <a-form-model
  4. id="productInfoEdit-form"
  5. ref="ruleForm"
  6. :model="form"
  7. :rules="rules"
  8. :label-col="formItemLayout.labelCol"
  9. :wrapper-col="formItemLayout.wrapperCol"
  10. >
  11. <a-form-model-item label="产品名称" prop="name">
  12. <a-input
  13. id="productInfoEdit-name"
  14. :maxLength="30"
  15. v-model="form.name"
  16. placeholder="请输入产品名称(最多30个字符)"
  17. allowClear />
  18. </a-form-model-item>
  19. <a-form-model-item label="产品编码" prop="code">
  20. <a-input
  21. id="productInfoEdit-code"
  22. :maxLength="30"
  23. :disabled="!!$route.params.id"
  24. v-model="form.code"
  25. placeholder="请输入产品编码(最多30个字符)"
  26. allowClear />
  27. </a-form-model-item>
  28. <a-form-model-item label="原厂编码" prop="origCode">
  29. <a-input
  30. id="productInfoEdit-origCode"
  31. :maxLength="30"
  32. v-model="form.origCode"
  33. placeholder="请输入原厂编码(最多30个字符)"
  34. allowClear />
  35. </a-form-model-item>
  36. <a-form-model-item label="基本单位" prop="unit">
  37. <a-input
  38. id="productInfoEdit-unit"
  39. :maxLength="30"
  40. v-model="form.unit"
  41. placeholder="请输入基本单位(最多30个字符)"
  42. allowClear />
  43. </a-form-model-item>
  44. <a-form-model-item label="产品品牌" prop="productBrandSn">
  45. <a-select
  46. id="productInfoEdit-productBrand"
  47. placeholder="请输入名称或拼音查询,如果没有请点击 '+' 新增"
  48. :disabled="!!$route.params.id"
  49. allowClear
  50. v-model="form.productBrandSn"
  51. :showSearch="true"
  52. option-filter-prop="children"
  53. :filter-option="filterOption"
  54. style="width: 90%;">
  55. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn" :disabled="item.enabledFlag==0">{{ item.brandName }}</a-select-option>
  56. </a-select>
  57. <a-button @click="openModal=true" icon="plus" size="small" id="productInfoEdit-add-btn" style="margin-left: 5px;"></a-button>
  58. </a-form-model-item>
  59. <a-form-model-item label="产品分类" prop="productType">
  60. <a-cascader
  61. :disabled="!!$route.params.id"
  62. @change="changeProductType"
  63. :options="productTypeList"
  64. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  65. id="productInfoEdit-productType"
  66. placeholder="请选择产品分类"
  67. allowClear
  68. v-model="form.productType" />
  69. </a-form-model-item>
  70. <a-form-model-item label="经销批发价" prop="specialPrice">
  71. <a-input-number
  72. id="productInfoEdit-specialPrice"
  73. v-model="form.specialPrice"
  74. :min="0"
  75. :max="999999"
  76. :precision="2"
  77. style="width: 90%;margin-right: 5px;"
  78. placeholder="请输入经销批发价(0~999999)"
  79. allowClear /><span>元</span>
  80. </a-form-model-item>
  81. <a-form-model-item label="终端价" prop="terminalPrice">
  82. <a-input-number
  83. id="productInfoEdit-terminalPrice"
  84. v-model="form.terminalPrice"
  85. :min="0"
  86. :max="999999"
  87. :precision="2"
  88. style="width: 90%;margin-right: 5px;"
  89. placeholder="请输入终端价(0~999999)"
  90. allowClear /><span>元</span>
  91. </a-form-model-item>
  92. <a-form-model-item label="车主价" prop="carOwnersPrice">
  93. <a-input-number
  94. id="productInfoEdit-carOwnersPrice"
  95. v-model="form.carOwnersPrice"
  96. :min="0"
  97. :max="999999"
  98. :precision="2"
  99. style="width: 90%;margin-right: 5px;"
  100. placeholder="请输入车主价(0~999999)"
  101. allowClear /><span>元</span>
  102. </a-form-model-item>
  103. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  104. <a-button type="primary" @click="handleSubmit" id="productInfoEdit-btn-submit">保存</a-button>
  105. <a-button @click="goBack" style="margin-left: 15px" id="productInfoEdit-btn-back">返回列表</a-button>
  106. </a-form-model-item>
  107. </a-form-model>
  108. <!-- 新增/编辑产品品牌 -->
  109. <product-brand-edit-modal :openModal="openModal" @ok="handleOk" @close="openModal=false" />
  110. </a-card>
  111. </template>
  112. <script>
  113. import { STable, VSelect } from '@/components'
  114. import productBrandEditModal from '../productBrand/editModal.vue'
  115. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  116. import { dealerProductTypeList } from '@/api/dealerProductType'
  117. import { dealerProductSave, dealerProductDetail } from '@/api/dealerProduct'
  118. export default {
  119. name: 'ProductInfoEdit',
  120. components: { STable, VSelect, productBrandEditModal },
  121. data () {
  122. return {
  123. formItemLayout: {
  124. labelCol: { span: 4 },
  125. wrapperCol: { span: 16 }
  126. },
  127. form: {
  128. name: '', // 产品名称
  129. code: '', // 产品编码
  130. origCode: '', // 原厂编码
  131. unit: '', // 基本单位
  132. productBrandSn: undefined, // 产品品牌
  133. productTypeSn3: '', // 产品三级分类
  134. productType: [], // 产品分类
  135. specialPrice: '', // 经销价
  136. terminalPrice: '', // 终端价
  137. carOwnersPrice: '' // 车主价
  138. },
  139. rules: {
  140. productName: [
  141. { required: true, message: '请输入产品名称', trigger: 'blur' }
  142. ],
  143. productCode: [
  144. { required: true, message: '请输入产品编码', trigger: 'blur' }
  145. ],
  146. productBrandSn: [
  147. { required: true, message: '请选择产品品牌', trigger: 'change' }
  148. ],
  149. productType: [
  150. { required: true, message: '请选择产品分类', trigger: 'change' }
  151. ]
  152. },
  153. productBrandList: [], // 品牌下拉数据
  154. productTypeList: [], // 分类下拉数据
  155. openModal: false // 新增编辑 弹框
  156. }
  157. },
  158. methods: {
  159. // 获取产品信息
  160. getGoodsDetail () {
  161. dealerProductDetail({ id: this.$route.params.id }).then(res => {
  162. if (res.status == 200) {
  163. this.form = Object.assign(this.form, res.data)
  164. const productTypeSn1 = res.data.productTypeSn1 ? res.data.productTypeSn1 : ''
  165. const productTypeSn2 = res.data.productTypeSn2 ? res.data.productTypeSn2 : ''
  166. const productTypeSn3 = res.data.productTypeSn3 ? res.data.productTypeSn3 : ''
  167. this.form.productType = [productTypeSn1, productTypeSn2, productTypeSn3]
  168. } else {
  169. this.$refs.ruleForm.resetFields()
  170. }
  171. })
  172. },
  173. // 保存
  174. handleSubmit (e) {
  175. e.preventDefault()
  176. const _this = this
  177. this.$refs.ruleForm.validate(valid => {
  178. if (valid) {
  179. const form = JSON.parse(JSON.stringify(_this.form))
  180. form.id = _this.$route.params.id ? _this.$route.params.id : undefined
  181. delete form.productType
  182. dealerProductSave(form).then(res => {
  183. if (res.status == 200) {
  184. _this.$message.success(res.message)
  185. setTimeout(() => {
  186. _this.$router.push({ path: '/productManagement/productInfo/list' })
  187. }, 1000)
  188. }
  189. })
  190. } else {
  191. console.log('error submit!!')
  192. return false
  193. }
  194. })
  195. },
  196. // 产品分类 change
  197. changeProductType (val, opt) {
  198. this.form.productTypeSn3 = val[2] ? val[2] : ''
  199. },
  200. // 新增品牌 成功
  201. handleOk () {
  202. // 获取品牌数据列表,并赋值
  203. this.getProductBrand('val')
  204. },
  205. filterOption (input, option) {
  206. return (
  207. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  208. )
  209. },
  210. // 返回
  211. goBack () {
  212. this.$router.push({ path: '/productManagement/productInfo/list' })
  213. },
  214. // 产品品牌 列表
  215. getProductBrand (val) {
  216. dealerProductBrandQuery({}).then(res => {
  217. if (res.status == 200) {
  218. this.productBrandList = res.data
  219. if (val) { // 需将新增加的品牌回填到产品品牌的地方,即不需要用户再选一下
  220. this.form.productBrandSn = this.productBrandList[this.productBrandList.length - 1].brandSn
  221. }
  222. } else {
  223. this.productBrandList = []
  224. }
  225. })
  226. },
  227. // 产品分类 列表
  228. getProductType () {
  229. dealerProductTypeList({}).then(res => {
  230. if (res.status == 200) {
  231. this.productTypeList = res.data
  232. } else {
  233. this.productTypeList = []
  234. }
  235. })
  236. }
  237. },
  238. mounted () { // 不使用beforeRouteEnter:由于页面路由动态id导致页面表现方式不同但路由相同,则会出现数据不重新请求问题
  239. this.getProductBrand()
  240. this.getProductType()
  241. this.$refs.ruleForm.resetFields()
  242. if (this.$route.params.id) { // 编辑页
  243. this.getGoodsDetail()
  244. }
  245. }
  246. }
  247. </script>