detailsPageEdit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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="editCustomer"
  14. >{{ form.id ? '确认修改' : '确认新增' }}
  15. </el-button>
  16. </div>
  17. <div style="margin-top: 60px">
  18. <el-form :model="form" ref="form" label-width="130px" class="demo-ruleForm">
  19. <containerTitle title="基础资料"></containerTitle>
  20. <basic-container style="margin-bottom: 10px">
  21. <el-row>
  22. <el-col v-for="(item,index) in basicData.column" :key="index" :span="item.span?item.span:8">
  23. <el-form-item label-width="150px" :label="item.label" :prop="item.prop" :rules="item.rules">
  24. <el-date-picker v-if="item.type === 'datetime'" style="width: 100%;" v-model="form[item.prop]" size="small" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss"/>
  25. <span v-else-if="item.type === 'select'">
  26. <el-select v-model="form[item.prop]" slot="prepend" style="width: 100%;" size="small" placeholder="请选择">
  27. <el-option v-for="(item,index2) in item.dicData" :key="index2" :label="item.label" :value="item.value"></el-option>
  28. </el-select>
  29. </span>
  30. <el-input type="age" v-else v-model="form[item.prop]" size="small" autocomplete="off"></el-input>
  31. </el-form-item>
  32. </el-col>
  33. </el-row>
  34. </basic-container>
  35. <containerTitle title="发货信息"></containerTitle>
  36. <basic-container style="margin-bottom: 10px">
  37. <avue-crud
  38. :option="customerContact"
  39. v-model="contactsForm"
  40. :data="contactsData"
  41. ref="crudContact"
  42. @row-save="rowSave"
  43. @row-click="handleRowClick"
  44. @row-update="rowUpdate"
  45. @row-del="rowDel">
  46. <template slot="code" slot-scope="{row,index}">
  47. <span v-if="row.$cellEdit" style="float: left;color: #F56C6C;">*</span>
  48. <span style="margin-left: 12px;padding-top: 2px">{{ row.code }}</span>
  49. <el-button type="text" v-if="row.$cellEdit" size="mini" style="float: right" @click="commodityChoice(row,index)">选择</el-button>
  50. </template>
  51. <template slot-scope="{row,index}" slot="menu">
  52. <el-button
  53. type="text"
  54. size="small"
  55. @click="rowCell(row,index)"
  56. >{{ row.$cellEdit ? '保存' : '修改' }}
  57. </el-button>
  58. </template>
  59. </avue-crud>
  60. </basic-container>
  61. </el-form>
  62. </div>
  63. <el-dialog
  64. title="导入商品"
  65. append-to-body
  66. class="el-dialogDeep"
  67. :visible.sync="dialogVisible"
  68. width="80%"
  69. :close-on-click-modal="false"
  70. :destroy-on-close="true"
  71. :close-on-press-escape="false">
  72. <el-row style="height: 0;">
  73. <el-col :span="5">
  74. <div>
  75. <el-scrollbar>
  76. <basic-container>
  77. <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick"/>
  78. </basic-container>
  79. </el-scrollbar>
  80. </div>
  81. </el-col>
  82. <el-col :span="19">
  83. <basic-container>
  84. <avue-crud :option="optionTwo"
  85. :table-loading="loading"
  86. :data="data"
  87. ref="crud"
  88. @refresh-change="refreshChange"
  89. @selection-change="selectionChange"
  90. :page.sync="page"
  91. @on-load="onLoad">
  92. </avue-crud>
  93. </basic-container>
  94. </el-col>
  95. </el-row>
  96. <span slot="footer" class="dialog-footer">
  97. <el-button @click="dialogVisible = false">取 消</el-button>
  98. <el-button type="primary" @click="importGoods()" :disabled="this.tableData.length == 1 ? false:true">导 入</el-button>
  99. </span>
  100. </el-dialog>
  101. </div>
  102. </template>
  103. <script>
  104. import customerContact from "./configuration/customerContact.json"
  105. import {detail,corpsattn,typeSave} from "@/api/maintenance/priceManagement"
  106. import commodity from "../../salesManagement/salesContract/config/commodity.json";
  107. import {getList} from "@/api/basicData/configuration"
  108. import {getDeptLazyTreeTwo} from "@/api/basicData/basicFeesDesc";
  109. export default {
  110. name: "detailsPage",
  111. data() {
  112. return {
  113. form: {},
  114. disabled: false,
  115. customerContact: customerContact,
  116. contactsForm: {},
  117. contactsData: [],
  118. basicData: {
  119. column: [
  120. {
  121. label: '大字(规格编码)',
  122. prop: 'bigCharacter',
  123. rules: [
  124. {
  125. required: true,
  126. message: ' ',
  127. trigger: 'blur'
  128. }
  129. ]
  130. }, {
  131. label: '品牌',
  132. prop: 'brand',
  133. rules: [
  134. {
  135. required: true,
  136. message: ' ',
  137. trigger: 'blur'
  138. }
  139. ]
  140. }, {
  141. label: '状态',
  142. prop: 'status',
  143. type:'select',
  144. dicData:[{
  145. label:'正常',
  146. value:0
  147. },{
  148. label:'停用',
  149. value:1
  150. }],
  151. rules: [
  152. {
  153. required: true,
  154. message: ' ',
  155. trigger: 'blur'
  156. }
  157. ]
  158. }, {
  159. label: '规格',
  160. prop: 'typeno',
  161. rules: [
  162. {
  163. required: true,
  164. message: ' ',
  165. trigger: 'blur'
  166. }
  167. ]
  168. }, {
  169. label: '花纹',
  170. prop: 'brandItem',
  171. rules: [
  172. {
  173. required: true,
  174. message: ' ',
  175. trigger: 'blur'
  176. }
  177. ]
  178. }, {
  179. label: '类别',
  180. prop: 'category',
  181. rules: [
  182. {
  183. required: true,
  184. message: ' ',
  185. trigger: 'blur'
  186. }
  187. ]
  188. }, {
  189. label: '产品分类',
  190. prop: 'productCategory',
  191. rules: [
  192. {
  193. required: true,
  194. message: ' ',
  195. trigger: 'blur'
  196. }
  197. ]
  198. }
  199. ]
  200. },
  201. //导入商品
  202. detailsSelect:"",
  203. treeDeptId:'',
  204. tableData:[],
  205. dialogVisible: false,
  206. treeOption: {
  207. nodeKey: 'id',
  208. lazy: true,
  209. treeLoad: function (node, resolve) {
  210. const parentId = (node.level === 0) ? 0 : node.data.id;
  211. getDeptLazyTreeTwo(parentId).then(res => {
  212. resolve(res.data.data.map(item => {
  213. return {
  214. ...item,
  215. leaf: !item.hasChildren
  216. }
  217. }))
  218. });
  219. },
  220. addBtn: false,
  221. menu: false,
  222. size: 'small',
  223. props: {
  224. labelText: '标题',
  225. label: 'title',
  226. value: 'value',
  227. children: 'children'
  228. }
  229. },
  230. optionTwo: commodity,
  231. loading: false,
  232. data: [],
  233. page: {
  234. pageSize: 10,
  235. currentPage: 1,
  236. total: 0
  237. },
  238. }
  239. },
  240. //初始化查询
  241. created() {
  242. if (this.$route.query.id) {
  243. detail(JSON.parse(this.$route.query.id)).then(res =>{
  244. this.form = res.data.data
  245. this.contactsData = res.data.data.priceItemList
  246. delete this.form.priceItemList
  247. })
  248. } else {
  249. this.form = {}
  250. this.contactsData = []
  251. }
  252. },
  253. watch: {
  254. '$route'(to, from) {
  255. console.log(to, from);
  256. if (this.$route.query.id) {
  257. } else {
  258. this.form = {}
  259. }
  260. }
  261. },
  262. methods: {
  263. //新增商品信息保存触发
  264. rowSave(row, done, loading) {
  265. console.log(row)
  266. console.log(this.contactsData)
  267. // this.contactsData.push(row)
  268. done()
  269. },
  270. //点击行可编辑
  271. handleRowClick(row, event, column) {
  272. console.log(row.$index)
  273. },
  274. //商品编辑
  275. rowCell(row, index) {
  276. console.log(row)
  277. this.$refs.crudContact.rowCell(row, index)
  278. },
  279. //修改商品信息触发
  280. rowUpdate(row, index, done, loading) {
  281. done(row);
  282. },
  283. //删除商品信息触发
  284. rowDel(row, index, donerowDel) {
  285. this.$confirm("确定将选择数据删除?", {
  286. confirmButtonText: "确定",
  287. cancelButtonText: "取消",
  288. type: "warning"
  289. }).then(() => {
  290. //商品判断是否需要调用删除接口
  291. if (row.id) {
  292. corpsattn(row.id).then(res => {
  293. this.$message({
  294. type: "success",
  295. message: "操作成功!"
  296. });
  297. this.contactsData.splice(index, 1);
  298. })
  299. } else {
  300. this.$message({
  301. type: "success",
  302. message: "操作成功!"
  303. });
  304. this.contactsData.splice(index, 1);
  305. }
  306. })
  307. },
  308. //修改提交触发
  309. editCustomer() {
  310. this.$refs["form"].validate((valid) => {
  311. //校验明细列表
  312. let valids = true;
  313. if(this.contactsData.length !=0){
  314. this.contactsData.forEach((item) =>{
  315. if((!item.code || !item.bigCharacter) && valids){
  316. this.$message({
  317. type: "warning",
  318. message: "请检查明细列表第 "+(item.$index +1 )+" 行必填项"
  319. });
  320. valids = false;
  321. }
  322. })
  323. }
  324. if (valid && valids) {
  325. this.form.priceItemList = this.contactsData
  326. typeSave(this.form).then(res=>{
  327. this.$message({
  328. type: "success",
  329. message: this.form.id ? "修改成功!" : "新增成功!"
  330. });
  331. this.backToList()
  332. })
  333. } else {
  334. return false;
  335. }
  336. });
  337. },
  338. //选择
  339. commodityChoice(row,index){
  340. this.dialogVisible = true;
  341. this.detailsSelect = index
  342. },
  343. //导入页左商品类型查询
  344. nodeClick(data) {
  345. this.treeDeptId = data.id;
  346. this.page.currentPage = 1;
  347. this.onLoad(this.page);
  348. },
  349. //刷新触发
  350. refreshChange() {
  351. this.treeDeptId = '';
  352. this.page.currentPage = 1;
  353. this.onLoad(this.page);
  354. },
  355. //选中触发
  356. selectionChange(list) {
  357. this.tableData = list
  358. },
  359. //商品列表查询
  360. onLoad(page, params = {}) {
  361. this.loading = true;
  362. getList(page.currentPage, page.pageSize, Object.assign(params, this.query), this.treeDeptId).then(res => {
  363. const data = res.data.data;
  364. this.page.total = data.total;
  365. this.data = data.records;
  366. this.loading = false;
  367. });
  368. },
  369. //导入
  370. importGoods(){
  371. if(this.tableData){
  372. this.contactsData[this.detailsSelect].code = this.tableData[0].code;
  373. this.dialogVisible = !this.dialogVisible
  374. }
  375. },
  376. //返回列表
  377. backToList() {
  378. this.$router.$avueRouter.closeTag();
  379. this.$router.push({
  380. path: '/maintenance/priceManagement/index',
  381. query: {}
  382. });
  383. }
  384. }
  385. }
  386. </script>
  387. <style lang="scss" scoped>
  388. .customer-head {
  389. position: fixed;
  390. top: 105px;
  391. width: 100%;
  392. margin-left: -10px;
  393. height: 62px;
  394. background: #ffffff;
  395. box-shadow: 0 4px 12px 0px rgba(232, 232, 235, 1);
  396. z-index: 999;
  397. /* display: flex;
  398. justify-content: left; */
  399. }
  400. .customer-back {
  401. cursor: pointer;
  402. line-height: 62px;
  403. font-size: 16px;
  404. color: #323233;
  405. font-weight: 400;
  406. }
  407. .back-icon {
  408. line-height: 64px;
  409. font-size: 20px;
  410. margin-right: 8px;
  411. }
  412. .add-customer-btn {
  413. position: fixed;
  414. right: 36px;
  415. top: 115px;
  416. }
  417. ::v-deep .el-form-item {
  418. margin-bottom: 0;
  419. }
  420. .el-dialogDeep {
  421. ::v-deep .el-dialog {
  422. margin: 1vh auto 0 !important;
  423. padding-bottom: 10px !important;
  424. .el-dialog__body, .el-dialog__footer {
  425. padding-bottom: 0 !important;
  426. padding-top: 0 !important;
  427. }
  428. }
  429. }
  430. </style>