detailsPageEdit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <div class="borderless">
  3. <div class="customer-head">
  4. <div class="customer-back">
  5. <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
  6. @click="backToList">返回列表
  7. </el-button>
  8. </div>
  9. <el-button
  10. class="el-button--small-yh add-customer-btn"
  11. type="primary"
  12. :disabled="disabled"
  13. @click="editProductInfo"
  14. >{{ form.id ? '确认修改' : '确认新增' }}
  15. </el-button>
  16. </div>
  17. <div style="margin-top: 60px">
  18. <containerTitle title="基础信息"></containerTitle>
  19. <basic-container style="margin-bottom: 10px">
  20. <avue-form ref="form" v-model="form" :option="option">
  21. <template slot="goodsTypeId" slot-scope="scope">
  22. <avue-input-tree
  23. v-model="form.goodsTypeId"
  24. :props="{ label: 'title', value: 'id' }"
  25. multiple
  26. placeholder=" "
  27. type="tree"
  28. :dic="dicData"/>
  29. </template>
  30. </avue-form>
  31. </basic-container>
  32. <containerTitle title="商品规格"></containerTitle>
  33. <basic-container style="margin-bottom: 10px">
  34. <avue-crud
  35. :data="sftData"
  36. :option="sftOption"
  37. @row-del="rowSftDel"
  38. >
  39. <template slot="menuLeft" slot-scope="{ row, index }">
  40. <el-button
  41. type="primary"
  42. icon="el-icon-plus"
  43. size="small"
  44. @click.stop="addSftRow(row, index)"
  45. >新增明细
  46. </el-button>
  47. </template>
  48. <template slot="menu" slot-scope="{ row, index }">
  49. <el-button
  50. size="small"
  51. icon="el-icon-edit"
  52. type="text"
  53. @click.stop="rowSftEdit(row, index)"
  54. >
  55. {{ row.$cellEdit ? "保存" : "编辑" }}
  56. </el-button>
  57. <el-button
  58. size="small"
  59. icon="el-icon-edit"
  60. type="text"
  61. @click.stop="rowSftDel(row, index)">
  62. 删除
  63. </el-button>
  64. <el-button
  65. size="small"
  66. icon="el-icon-close"
  67. type="text">
  68. 下架
  69. </el-button>
  70. </template>
  71. </avue-crud>
  72. </basic-container>
  73. <containerTitle title="商品图片"></containerTitle>
  74. <basic-container style="margin-bottom: 10px">
  75. <avue-crud
  76. ref="imgUpload"
  77. :option="imgUploadList"
  78. :data="imgUploadData"
  79. @row-save="imgUploadSave"
  80. @row-update="imgUploadUpdate"
  81. @row-del="imgUploadDel"
  82. :upload-before="uploadBefore"
  83. ></avue-crud>
  84. </basic-container>
  85. <containerTitle title="详情页编辑"></containerTitle>
  86. <basic-container style="margin-bottom: 10px">
  87. <avue-ueditor v-model="text" :options="options"></avue-ueditor>
  88. </basic-container>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import {getDetail, updateDetail, getDeptTree, priceDelete} from "@/api/basicData/commodityType";
  94. import sftOption from "./configuration/specification.json";
  95. import imgUploadList from "./configuration/imgUploadList.json";
  96. export default {
  97. name: "detailsPage",
  98. data() {
  99. return {
  100. form: {},
  101. sftData: [],
  102. sftOption: sftOption,
  103. imgUploadList: imgUploadList,
  104. text: '<h1 class="ql-align-center" style="text-align: center;"><a href="https://avuejs.com/doc/plugins/ueditor-plugins" target="_blank" style="font-weight: bold; color: rgb(194, 79, 74);">欢迎使用Avue富文本编辑器</a></h1><p class="ql-align-center" style="text-align: center;"><span style="font-weight: bold; color: rgb(194, 79, 74);"><img src="https://avuejs.com/images/logo-bg.jpg" height="200" width="200"></span></p>',
  105. options: {
  106. //普通图片上传
  107. action: "https://avuejs.com/imgupload",
  108. customConfig: {}, //wangEditor编辑的配置
  109. props: {
  110. res: "data",
  111. url: "url"
  112. }
  113. },
  114. disabled: false,
  115. userDialog: false,//供应商导入窗口
  116. imgUploadData: [],
  117. dicData: [],
  118. detailsSelect: {},
  119. option: {
  120. menuBtn: false,
  121. labelWidth: 100,
  122. column: [
  123. {
  124. label: "产品编码",
  125. prop: "code",
  126. span: 8,
  127. rules: [
  128. {
  129. required: true,
  130. message: " ",
  131. trigger: "blur"
  132. }
  133. ],
  134. },
  135. {
  136. label: "产品名称",
  137. prop: "cname",
  138. span: 8,
  139. rules: [
  140. {
  141. required: true,
  142. message: " ",
  143. trigger: "blur"
  144. }
  145. ],
  146. slot: true
  147. },
  148. {
  149. label: "产品分类",
  150. prop: "goodsTypeId",
  151. span: 8,
  152. rules: [
  153. {
  154. required: true,
  155. message: " ",
  156. trigger: "blur"
  157. }
  158. ],
  159. },
  160. {
  161. label: "花纹",
  162. prop: "brandItem",
  163. span: 8,
  164. rules: [
  165. {
  166. required: true,
  167. message: " ",
  168. trigger: "blur"
  169. }
  170. ],
  171. },
  172. {
  173. label: "品牌",
  174. prop: "brand",
  175. span: 8,
  176. rules: [
  177. {
  178. required: true,
  179. message: " ",
  180. trigger: "blur"
  181. }
  182. ],
  183. },
  184. {
  185. label: "状态",
  186. prop: "status",
  187. span: 8,
  188. type: 'select',
  189. dicData: [{
  190. label: '正常',
  191. value: 0
  192. }, {
  193. label: '停用',
  194. value: 1
  195. }],
  196. },
  197. {
  198. label: "规格",
  199. prop: "specs",
  200. span: 8,
  201. rules: [
  202. {
  203. required: true,
  204. message: " ",
  205. trigger: "blur"
  206. }
  207. ],
  208. },
  209. {
  210. label: "规格1",
  211. prop: "specsOne",
  212. span: 8,
  213. rules: [
  214. {
  215. required: true,
  216. message: " ",
  217. trigger: "blur"
  218. }
  219. ],
  220. },
  221. {
  222. label: "规格2",
  223. prop: "specsTwo",
  224. span: 8,
  225. rules: [
  226. {
  227. required: true,
  228. message: " ",
  229. trigger: "blur"
  230. }
  231. ],
  232. },
  233. {
  234. label: "级别",
  235. prop: "level",
  236. span: 8,
  237. rules: [
  238. {
  239. required: true,
  240. message: " ",
  241. trigger: "blur"
  242. }
  243. ],
  244. },
  245. {
  246. label: "产地",
  247. prop: "placeProduction",
  248. span: 8,
  249. rules: [
  250. {
  251. required: true,
  252. message: " ",
  253. trigger: "blur"
  254. }
  255. ],
  256. },
  257. {
  258. label: "三包",
  259. prop: "threeGuarantees",
  260. span: 8,
  261. },
  262. {
  263. label: "备注",
  264. prop: "remarks",
  265. type: "textarea",
  266. minRows: 2,
  267. span: 24
  268. }
  269. ]
  270. },
  271. }
  272. },
  273. //初始化查询
  274. created() {
  275. getDeptTree().then(res => {
  276. this.dicData = res.data.data;
  277. });
  278. if (this.$route.query.id) {
  279. getDetail(JSON.parse(this.$route.query.id)).then(res => {
  280. this.form = res.data.data
  281. })
  282. } else {
  283. this.$set(this.form, "goodsTypeId", this.$route.query.treeDeptId)
  284. }
  285. },
  286. methods: {
  287. // 商品图片上传保存
  288. imgUploadSave(row, done, loading) {
  289. console.log(row);
  290. this.imgUploadData.push(row);
  291. done();
  292. },
  293. imgUploadUpdate(row, index, done, loading) {
  294. done();
  295. },
  296. imgUploadDel(row, index, donerowDel) {
  297. this.$confirm("确定将选择数据删除?", {
  298. confirmButtonText: "确定",
  299. cancelButtonText: "取消",
  300. type: "warning"
  301. }).then(() => {
  302. //商品判断是否需要调用删除接口
  303. if (row.id) {
  304. // corpsattn(row.id).then(res => {
  305. // this.$message({
  306. // type: "success",
  307. // message: "操作成功!"
  308. // });
  309. // this.imgUploadData.splice(index, 1);
  310. // })
  311. } else {
  312. this.$message({
  313. type: "success",
  314. message: "操作成功!"
  315. });
  316. this.imgUploadData.splice(index, 1);
  317. }
  318. });
  319. },
  320. // 上传前
  321. uploadBefore(file, done, loading, column) {
  322. const is2M = file.size / 1024 / 1024 < 2;
  323. const isType =
  324. file.type === "image/jpeg" ||
  325. file.type === "image/png" ||
  326. file.type === "image/jpg";
  327. if (!isType) {
  328. this.$message.error("图片只能是JPG、JPEG、PNG格式");
  329. loading();
  330. }
  331. if (!is2M) {
  332. this.$message.error("图片大小不能超过2M");
  333. loading();
  334. }
  335. const img = new Image();
  336. const _URL = window.URL || window.webkitURL;
  337. let isSize = null;
  338. img.onload = () => {
  339. if (column.label == "图片") {
  340. isSize = img.width === img.height;
  341. if (!isSize) {
  342. this.$message.error("图片宽高限制比例为1:1");
  343. }
  344. } else {
  345. const width = 750;
  346. const height = 1000;
  347. isSize = img.width === width && img.height <= height;
  348. if (!isSize) {
  349. this.$message.error("商品详情轮播图宽为750,高不能超过1000");
  350. }
  351. }
  352. if (is2M && isType && isSize) {
  353. done();
  354. } else {
  355. loading();
  356. }
  357. };
  358. img.src = _URL.createObjectURL(file);
  359. },
  360. rowSftEdit(row) {
  361. if (row.$cellEdit == true) {
  362. this.$set(row, "$cellEdit", false);
  363. } else {
  364. this.$set(row, "$cellEdit", true);
  365. }
  366. },
  367. addSftRow() {
  368. this.sftData.push({
  369. $cellEdit: true,
  370. cname: null,
  371. texture: null,
  372. colour: null,
  373. describe: null,
  374. remarks: null
  375. });
  376. },
  377. rowSftDel(row, index) {
  378. },
  379. rowContactCell(row, index) {
  380. this.$refs.crudContact.rowCell(row, index)
  381. },
  382. rowPurchaseCell(row, index) {
  383. this.$refs.crudPurchase.rowCell(row, index)
  384. },
  385. //修改提交触发
  386. editProductInfo() {
  387. this.$refs["form"].validate((valid) => {
  388. //校验明细列表
  389. if (valid) {
  390. const params = {
  391. ...this.form,
  392. type: 0,
  393. }
  394. updateDetail(params).then(res => {
  395. if (res.data.success) {
  396. this.$message.success("操作成功!")
  397. }
  398. })
  399. } else {
  400. return false;
  401. }
  402. });
  403. },
  404. //返回列表
  405. backToList() {
  406. this.$router.$avueRouter.closeTag();
  407. this.$router.push({
  408. path: '/basicData/productInformation/index',
  409. query: {}
  410. });
  411. }
  412. }
  413. }
  414. </script>
  415. <style lang="scss" scoped>
  416. .customer-head {
  417. position: fixed;
  418. top: 105px;
  419. width: 100%;
  420. margin-left: -10px;
  421. height: 62px;
  422. background: #ffffff;
  423. box-shadow: 0 4px 12px 0px rgba(232, 232, 235, 1);
  424. z-index: 999;
  425. /* display: flex;
  426. justify-content: left; */
  427. }
  428. .customer-back {
  429. cursor: pointer;
  430. line-height: 62px;
  431. font-size: 16px;
  432. color: #323233;
  433. font-weight: 400;
  434. }
  435. .back-icon {
  436. line-height: 64px;
  437. font-size: 20px;
  438. margin-right: 8px;
  439. }
  440. .add-customer-btn {
  441. position: fixed;
  442. right: 36px;
  443. top: 115px;
  444. }
  445. ::v-deep .el-form-item {
  446. margin-bottom: 0;
  447. }
  448. .el-dialogDeep {
  449. ::v-deep .el-dialog {
  450. margin: 1vh auto 0 !important;
  451. padding-bottom: 10px !important;
  452. .el-dialog__body, .el-dialog__footer {
  453. padding-bottom: 0 !important;
  454. padding-top: 0 !important;
  455. }
  456. }
  457. }
  458. </style>