ProductInfoDetail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <div>
  3. <el-form :model="value" :rules="rules" ref="productInfoForm" label-width="120px" style="width: 700px" size="small">
  4. <el-form-item label="商品分类:" prop="productCategoryId">
  5. <el-cascader
  6. v-model="selectProductCateValue"
  7. :placeholder="cascaderPlaceholder"
  8. :options="productCateOptions">
  9. </el-cascader>
  10. </el-form-item>
  11. <el-form-item label="商品名称:" prop="name">
  12. <el-input v-model="value.name"></el-input>
  13. </el-form-item>
  14. <!-- <el-form-item label="副标题:" prop="subTitle">
  15. <el-input v-model="value.subTitle"></el-input>
  16. </el-form-item> -->
  17. <el-form-item label="商品品牌:" prop="brandId">
  18. <el-select
  19. filterable
  20. v-model="value.brandId"
  21. @change="handleBrandChange"
  22. placeholder="请选择品牌">
  23. <el-option
  24. v-for="item in brandOptions"
  25. :key="item.value"
  26. :label="item.label"
  27. :value="item.value">
  28. </el-option>
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="供应商:" prop="compId">
  32. <el-select
  33. filterable
  34. v-model="value.compId"
  35. @change="handleSupplierChange"
  36. placeholder="请选择供应商"
  37. >
  38. <el-option
  39. v-for="item in supplierOptList"
  40. :key="item.value"
  41. :label="item.label"
  42. :value="item.value"
  43. ></el-option>
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="生产地:" prop="placeOfProductionId">
  47. <el-select
  48. filterable
  49. v-model="value.placeOfProductionId"
  50. @change="handleOriginChange"
  51. placeholder="请选择生产地">
  52. <el-option
  53. v-for="item in originOptions"
  54. :key="item.value"
  55. :label="item.label"
  56. :value="item.value">
  57. </el-option>
  58. </el-select>
  59. </el-form-item>
  60. <el-form-item label="规格:" prop="spec">
  61. <el-input v-model="value.spec"></el-input>
  62. </el-form-item>
  63. <el-form-item label="商品上架:">
  64. <el-switch
  65. v-model="value.publishStatus"
  66. :active-value="1"
  67. :inactive-value="0">
  68. </el-switch>
  69. </el-form-item>
  70. <el-form-item label="库存:" >
  71. <el-input type="number" v-model="value.stock"></el-input>
  72. </el-form-item>
  73. <el-form-item label="生产日期:">
  74. <el-input v-model="value.dateOfManufacture"></el-input>
  75. <!-- <el-date-picker
  76. v-model="value.dateOfManufacture"
  77. type="date"
  78. value-format="yyyy-MM-dd"
  79. placeholder="选择日期">
  80. </el-date-picker> -->
  81. </el-form-item>
  82. <el-form-item label="保质期:">
  83. <el-input v-model="value.qualityGuaranteePeriod"></el-input>
  84. </el-form-item>
  85. <el-form-item label="商品介绍:" >
  86. <tinymce :width="580" :height="200" class="hideupload" v-model="value.description"></tinymce>
  87. <!-- <el-input
  88. :autoSize="true"
  89. v-model="value.description"
  90. type="textarea"
  91. :rows="5"
  92. placeholder="请输入内容"></el-input> -->
  93. </el-form-item>
  94. <el-form-item label="商品货号:">
  95. <el-input v-model="value.productSn"></el-input>
  96. </el-form-item>
  97. <el-form-item label="商品售价:">
  98. <el-input type="number" v-model="value.price"></el-input>
  99. </el-form-item>
  100. <el-form-item label="市场价:">
  101. <el-input type="number" v-model="value.originalPrice"></el-input>
  102. </el-form-item>
  103. <!-- <el-form-item label="商品库存:">
  104. <el-input v-model="value.stock"></el-input>
  105. </el-form-item> -->
  106. <el-form-item label="计量单位:">
  107. <el-input v-model="value.unit"></el-input>
  108. </el-form-item>
  109. <!-- <el-form-item label="商品重量:">
  110. <el-input v-model="value.weight" style="width: 300px"></el-input>
  111. <span style="margin-left: 20px">克</span>
  112. </el-form-item> -->
  113. <el-form-item label="排序">
  114. <el-input type="number" v-model="value.sort"></el-input>
  115. </el-form-item>
  116. <el-form-item label="商品图片:" prop="selectProductPics">
  117. <multi-upload v-model="selectProductPics"></multi-upload>
  118. </el-form-item>
  119. <el-form-item style="text-align: center">
  120. <!-- <el-button type="primary" size="medium" @click="handleNext('productInfoForm')">下一步,填写商品促销</el-button> -->
  121. <el-button type="primary" size="medium" @click="handleFinishCommit">完成,提交商品</el-button>
  122. </el-form-item>
  123. </el-form>
  124. </div>
  125. </template>
  126. <script>
  127. import {fetchListWithChildren} from '@/api/productCate'
  128. import {fetchList as fetchBrandList,fetchOriginList} from '@/api/brand'
  129. import {getProduct, selectCompList} from '@/api/product';
  130. import SingleUpload from '@/components/Upload/singleUpload'
  131. import MultiUpload from '@/components/Upload/multiUpload'
  132. import Tinymce from '@/components/Tinymce'
  133. export default {
  134. name: "ProductInfoDetail",
  135. components: {SingleUpload, MultiUpload, Tinymce},
  136. props: {
  137. value: Object,
  138. isEdit: {
  139. type: Boolean,
  140. default: false
  141. }
  142. },
  143. data() {
  144. return {
  145. hasEditCreated:false,
  146. //选中商品分类的值
  147. selectProductCateValue: [],
  148. productCateOptions: [],
  149. brandOptions: [],
  150. originOptions:[],
  151. supplierOptList: [],
  152. cascaderPlaceholder:'',
  153. rules: {
  154. name: [
  155. {required: true, message: '请输入商品名称', trigger: 'blur'},
  156. {min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
  157. ],
  158. subTitle: [{required: true, message: '请输入商品副标题', trigger: 'blur'}],
  159. productCategoryId: [{required: true, message: '请选择商品分类', trigger: 'blur'}],
  160. brandId: [{required: true, message: '请选择商品品牌', trigger: 'blur'}],
  161. compId: [{required: true, message: '请选择供应商', trigger: 'blur'}],
  162. placeOfProductionId: [{required: true, message: '请选择生产地', trigger: 'blur'}],
  163. description: [{required: true, message: '请输入商品介绍', trigger: 'blur'}],
  164. requiredProp: [{required: true, message: '该项为必填项', trigger: 'blur'}],
  165. spec: [{required: true, message: '该项为必填项', trigger: 'blur'}],
  166. description: [{required: true, message: '该项为必填项', trigger: 'blur'}],
  167. price: [{required: true, message: '该项为必填项', trigger: 'blur'}],
  168. qualityGuaranteePeriod: [{required: true, message: '该项为必填项', trigger: 'blur'}],
  169. selectProductPics: [ {required: true, message: '请上传商品图片', trigger: 'blur'}],
  170. }
  171. };
  172. },
  173. created() {
  174. this.getProductCateList();
  175. this.getBrandList();
  176. this.getSupplierOptList();
  177. },
  178. computed:{
  179. //商品的编号
  180. productId(){
  181. return this.value.id;
  182. },
  183. //商品的主图和画册图片
  184. selectProductPics:{
  185. get:function () {
  186. let pics=[];
  187. if(this.value.pic===undefined||this.value.pic==null||this.value.pic===''){
  188. return pics;
  189. }
  190. pics.push(this.value.pic);
  191. if(this.value.albumPics===undefined||this.value.albumPics==null||this.value.albumPics===''){
  192. return pics;
  193. }
  194. let albumPics = this.value.albumPics.split(',');
  195. for(let i=0;i<albumPics.length;i++){
  196. pics.push(albumPics[i]);
  197. }
  198. return pics;
  199. },
  200. set:function (newValue) {
  201. if (newValue == null || newValue.length === 0) {
  202. this.value.pic = null;
  203. this.value.albumPics = null;
  204. } else {
  205. this.value.pic = newValue[0];
  206. this.value.albumPics = '';
  207. if (newValue.length > 1) {
  208. for (let i = 1; i < newValue.length; i++) {
  209. this.value.albumPics += newValue[i];
  210. if (i !== newValue.length - 1) {
  211. this.value.albumPics += ',';
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. },
  219. watch: {
  220. productId:function(newValue){
  221. if(!this.isEdit)return;
  222. if(this.hasEditCreated)return;
  223. if(newValue===undefined||newValue==null||newValue===0)return;
  224. this.handleEditCreated();
  225. },
  226. selectProductCateValue: function (newValue) {
  227. // console.log('newValue',newValue);
  228. if (newValue != null && newValue.length === 2) {
  229. // 大类ID
  230. this.value.productBigCategoryId = newValue[0];
  231. // 大类名称
  232. this.value.productBigCategoryName= this.getBigCateNameById(this.value.productBigCategoryId);
  233. this.value.productCategoryId = newValue[1];
  234. this.value.productCategoryName= this.getCateNameById(this.value.productCategoryId);
  235. this.cascaderPlaceholder = this.value.productBigCategoryName + " / " + this.value.productCategoryName ;
  236. } else {
  237. this.value.productCategoryId = null;
  238. this.value.productCategoryName=null;
  239. this.value.productBigCategoryId = null;
  240. this.value.productBigCategoryName = null;
  241. }
  242. },
  243. 'value.compId'(newValue) {
  244. this.getOriginList(newValue);
  245. }
  246. },
  247. methods: {
  248. //处理编辑逻辑
  249. handleEditCreated(){
  250. if(this.value.productCategoryId!=null){
  251. this.selectProductCateValue.push(this.value.cateParentId);
  252. this.selectProductCateValue.push(this.value.productCategoryId);
  253. }
  254. this.hasEditCreated=true;
  255. },
  256. getProductCateList() {
  257. fetchListWithChildren().then(response => {
  258. // console.log('getProductCateList',JSON.parse(JSON.stringify(response)))
  259. let list = response.data;
  260. this.productCateOptions = [];
  261. for (let i = 0; i < list.length; i++) {
  262. let children = [];
  263. if (list[i].children != null && list[i].children.length > 0) {
  264. for (let j = 0; j < list[i].children.length; j++) {
  265. children.push({label: list[i].children[j].name, value: list[i].children[j].id});
  266. }
  267. }
  268. this.productCateOptions.push({label: list[i].name, value: list[i].id, children: children});
  269. }
  270. });
  271. },
  272. getBrandList() {
  273. fetchBrandList({pageNum: 1, pageSize: 100}).then(response => {
  274. this.brandOptions = [];
  275. let brandList = response.data.list;
  276. for (let i = 0; i < brandList.length; i++) {
  277. this.brandOptions.push({label: brandList[i].name, value: brandList[i].id});
  278. }
  279. });
  280. },
  281. /** 获取供应商下拉列表 */
  282. getSupplierOptList() {
  283. selectCompList().then(response => {
  284. this.supplierOptList = response.data;
  285. });
  286. },
  287. getOriginList(compId) {
  288. if(!compId) { return; }
  289. fetchOriginList(compId).then(response => {
  290. this.originOptions = [];
  291. let originList = response.data;
  292. for (let i = 0; i < originList.length; i++) {
  293. this.originOptions.push({label: originList[i].text, value: originList[i].lable});
  294. }
  295. });
  296. },
  297. getCateNameById(id){
  298. let name=null;
  299. for(let i=0;i<this.productCateOptions.length;i++){
  300. for(let j=0;j<this.productCateOptions[i].children.length;j++){
  301. if(this.productCateOptions[i].children[j].value===id){
  302. name=this.productCateOptions[i].children[j].label;
  303. return name;
  304. }
  305. }
  306. }
  307. return name;
  308. },
  309. getBigCateNameById(id){
  310. let bigName=null;
  311. for(let i=0;i<this.productCateOptions.length;i++){
  312. if(this.productCateOptions[i].value===id){
  313. bigName=this.productCateOptions[i].label;
  314. return bigName;
  315. }
  316. }
  317. return bigName;
  318. },
  319. handleNext(formName){
  320. this.$refs[formName].validate((valid) => {
  321. console.log('this.$refs[formName]',this.$refs[formName]);
  322. if (valid) {
  323. this.$emit('nextStep');
  324. } else {
  325. this.$message({
  326. message: '验证失败',
  327. type: 'error',
  328. duration:1000
  329. });
  330. return false;
  331. }
  332. });
  333. },
  334. handleBrandChange(val) {
  335. let brandName = '';
  336. for (let i = 0; i < this.brandOptions.length; i++) {
  337. if (this.brandOptions[i].value === val) {
  338. brandName = this.brandOptions[i].label;
  339. break;
  340. }
  341. }
  342. this.value.brandName = brandName;
  343. },
  344. handleSupplierChange(val) {
  345. this.value.placeOfProductionId = '';
  346. this.getOriginList(val);
  347. let supplierInfoObj = {};
  348. supplierInfoObj = this.supplierOptList.find(item => {
  349. return item.value === val;
  350. });
  351. this.value.compName = supplierInfoObj.label;
  352. },
  353. handleOriginChange(val) {
  354. let placeOfProduction = '';
  355. for (let i = 0; i < this.originOptions.length; i++) {
  356. if (this.originOptions[i].value === val) {
  357. placeOfProduction = this.originOptions[i].label;
  358. break;
  359. }
  360. }
  361. this.value.placeOfProduction = placeOfProduction;
  362. },
  363. handleFinishCommit(){
  364. console.log('1111');
  365. if(!this.selectProductPics || (this.selectProductPics || []).length==0){
  366. this.$message({
  367. message: '请上传商品相册',
  368. type: 'error',
  369. duration:1000
  370. });
  371. return;
  372. }
  373. this.$emit('finishCommit',this.isEdit);
  374. }
  375. }
  376. }
  377. </script>
  378. <style>
  379. .el-cascader input::-webkit-input-placeholder {color:#717171!important;}
  380. .hideupload /deep/ .editor-custom-btn-container{display: none;}
  381. </style>