edit.vue 8.9 KB

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