addAndEdit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: gcz
  6. * @LastEditTime: 2024-04-22 16:20:30
  7. * @FilePath: \great_webui\src\views\ticket\ticketMr\dialog\addAndEdit.vue
  8. * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
  9. -->
  10. <template>
  11. <el-dialog
  12. :title="title"
  13. :visible.sync="open"
  14. width="95%"
  15. append-to-body
  16. :close-on-click-modal="false"
  17. @close="cancel"
  18. >
  19. <div class="dialog">
  20. <el-form :model="form" ref="form" size="mini" :rules="rules" label-width="120px">
  21. <el-form-item label="模板名称:" prop="name">
  22. <el-input
  23. v-model="form.name"
  24. placeholder="模板名称"
  25. clearable
  26. />
  27. </el-form-item>
  28. <div style="display: flex;">
  29. <el-form-item label="演出厅:" prop="auditoriumId">
  30. <el-select v-model="form.auditoriumId" @change="countBySeatTypFun" placeholder="请选择演出厅">
  31. <el-option
  32. v-for="item in performList"
  33. :key="item.id"
  34. :label="item.name"
  35. :value="item.id">
  36. </el-option>
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item label="可配置数量:" prop="seatNum">
  40. {{ form.seatNum }}
  41. </el-form-item>
  42. </div>
  43. <el-form-item label="库存模式:" prop="chennelList">
  44. <div class="inventory_box">
  45. <div class="inventory_channel" style="width: 200px;">
  46. <div class="inventory_channel_header">
  47. <span>序号</span>
  48. <span>渠道名称</span>
  49. <span>数量</span>
  50. </div>
  51. <div
  52. :class="['inventory_channel_item',index == chennelAtion ?'inventory_channel_item-action':'']"
  53. v-for="(item,index) in form.chennelListForm"
  54. :key="index"
  55. @click="setDictLabel(item,index)"
  56. >
  57. <span>{{ index+1 }}</span>
  58. <span>{{ item.channelName }}</span>
  59. <span>{{ item.stockNum }}</span>
  60. </div>
  61. </div>
  62. <div class="inventory_seat" v-if="chennelAtion !== null">
  63. <el-form-item label="选择模式:" label-width="75px">
  64. <el-radio-group v-model="form.chennelListForm[chennelAtion].stockType">
  65. <el-radio :label="0">根据数量</el-radio>
  66. <el-radio :label="1">根据座位</el-radio>
  67. </el-radio-group>
  68. </el-form-item>
  69. <div v-if="!form.chennelListForm[chennelAtion].stockType">
  70. <el-table ref="tables" v-loading="loading" :data="form.chennelListForm[chennelAtion].seatTypeList" border>
  71. <el-table-column label="序号" align="center" type="index" width="60"></el-table-column>
  72. <el-table-column label="座位类型" align="center" prop="seatTypeName" />
  73. <el-table-column label="可配置数量" align="center" prop="stock"></el-table-column>
  74. <el-table-column label="配置数量" align="center">
  75. <template slot-scope="scope">
  76. <el-input v-model="form.chennelListForm[chennelAtion].seatTypeList[scope.$index].stockNum" type="number" clearable placeholder="请输入数量"></el-input>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. </div>
  81. <div v-else>
  82. </div>
  83. </div>
  84. </div>
  85. </el-form-item>
  86. <el-form-item label="备注:" prop="remark">
  87. <el-input
  88. v-model="form.remark"
  89. type="textarea"
  90. placeholder="请输入备注"
  91. clearable
  92. />
  93. </el-form-item>
  94. </el-form>
  95. </div>
  96. <span slot="footer" class="dialog-footer">
  97. <el-button @click="cancel">取消</el-button>
  98. <el-button
  99. type="primary"
  100. @click="submitForm"
  101. v-loading.fullscreen.lock="loading"
  102. element-loading-text="提交中..."
  103. element-loading-spinner="el-icon-loading"
  104. element-loading-background="rgba(0, 0, 0, 0.8)"
  105. >
  106. <span v-if="loading">提交中...</span>
  107. <span v-else>保存</span>
  108. </el-button>
  109. </span>
  110. <!-- 添加或修改对话框 End -->
  111. </el-dialog>
  112. </template>
  113. <script>
  114. import { saveAndEdit, getSelectById,countBySeatTyp,channelType } from '@/api/ticketMr/InventoryTemplate'
  115. import { merchantPageList } from '@/api/performanceHallMr/performanceHallMr'
  116. export default {
  117. name: "addAndEdit",
  118. dicts: ['system_taxrate'],
  119. data() {
  120. let validateNumber = (rule, value, callback) => {
  121. let regNumber=/^(([1-9]\d*)|([0][.]{1}[0-9]{0,2}[0-9]+)|([1-9]\d*[.]{1}[0-9]+))$/g;
  122. if (value === '') {
  123. callback(new Error('请输入大于等于0的数值!!!'));
  124. } else if(value==0){
  125. callback();
  126. }
  127. else if (!regNumber.test(value)) {
  128. callback(new Error('只能大于等于0的数值!!!'));
  129. } else{
  130. callback();
  131. }
  132. };
  133. return {
  134. title: "编辑",
  135. model: "EDIT",
  136. activeName: '01',
  137. // 演员信息弹窗
  138. performerVisible: false,
  139. // 演员信息
  140. performerList: [],
  141. // 演员上传图片索引
  142. performerIndex: 0,
  143. open: false,
  144. loading: false,
  145. form: {
  146. id: undefined,
  147. chennelListForm: []
  148. },
  149. formStock: {
  150. stockType: null,
  151. chennelList: [],
  152. },
  153. rules: {
  154. name: [{ required: true, message: "请输入模板名称", trigger: ["change","blur"] }],
  155. auditoriumId: [{ required: true, message: "请选择演出厅", trigger: ["change","blur"] }],
  156. chennelList: [{ required: true, message: "请输入库存模式", trigger: ["change","blur"] }],
  157. remark: [{ required: true, message: "请输入备注", trigger: ["change","blur"] }],
  158. },
  159. statusList: [
  160. {id: 1, name: '是', value: 1},
  161. {id: 2, name: '否', value: 2},
  162. ],
  163. performList: [], // 演出厅
  164. channelTypeList: [], // 渠道
  165. dictValue: '',
  166. chennelAtion: null,
  167. countBySeatTypList: [], // 座位类型
  168. stockFormList: []// 库存
  169. };
  170. },
  171. created() {
  172. this.getList()// 演出厅
  173. this.channelTypeFun() // 渠道
  174. },
  175. methods: {
  176. /** 查询主办方列表 */
  177. getList() {
  178. merchantPageList({pageNum: 1, pageSize: 100})
  179. .then(response => {
  180. this.performList = response.data.rows;
  181. }
  182. );
  183. },
  184. /**
  185. * 打开弹框
  186. * @date 2023-11-22
  187. * @param {any} obj
  188. * @returns {any}
  189. */
  190. async openDialog(title, obj) {
  191. this.chennelAtion = null
  192. this.open = true
  193. this.activeName = '01';
  194. if(this.channelTypeList.length<0) {
  195. await this.channelTypeFun()
  196. }
  197. if (obj){
  198. this.title = "编辑库存模板";
  199. await this.getSelectByIdApi(obj)
  200. }else{
  201. this.title = "添加库存模板";
  202. this.form = {
  203. chennelListForm: this.setDataTree({})
  204. }
  205. console.log("list====",this.form)
  206. this.setDictLabel(this.form.chennelListForm[0],0)
  207. }
  208. this.$nextTick(() => {
  209. this.$refs["form"].clearValidate();
  210. });
  211. },
  212. /** 获取详情 */
  213. async getSelectByIdApi(row) {
  214. try {
  215. const id = row.id
  216. let res = await getSelectById({id})
  217. if(res.code == 200) {
  218. let obj = res.data;
  219. await this.countBySeatTypFun(obj.auditoriumId,true)
  220. obj.chennelListForm = this.setDataTree(obj)
  221. this.form = obj
  222. this.setDictLabel(obj.chennelListForm[0],0)
  223. }
  224. } catch (error) {
  225. console.error("error====",error)
  226. }
  227. },
  228. setDataTree(obj){
  229. let list = []
  230. this.channelTypeList.forEach((item,index)=>{
  231. list.push({
  232. "channelType":item.dictValue,
  233. "channelName":item.dictLabel,
  234. "stockType": this.getStockType(item,obj),
  235. "stockNum": this.getStockAllNum(item,obj),
  236. "seatTypeList": [],
  237. "chennelSeatList": []
  238. })
  239. list[index].seatTypeList = this.getSeatTypeList(list[index],obj)
  240. list[index].chennelSeatList = this.getChennelSeatList(list[index],obj)
  241. })
  242. return list
  243. },
  244. getStockType(obj,data){
  245. let stockType = 0
  246. if(data.chennelList && data.chennelList.length>0) {
  247. for(let i = 0;i < data.chennelList.length;i++) {
  248. if(obj.dictValue == data.chennelList[i].channelType) {
  249. stockType = data.chennelList[i].stockType
  250. break;
  251. }
  252. }
  253. }
  254. return stockType
  255. },
  256. getStockAllNum(obj,data) {
  257. let num = 0
  258. let flog = false
  259. if(data.chennelList && data.chennelList.length>0) {
  260. data.chennelList.forEach((item,index)=>{
  261. if(obj.dictValue == item.channelType) {
  262. flog = true
  263. num = num + item.stockNum
  264. }
  265. })
  266. }
  267. if(flog) {
  268. return num
  269. }else {
  270. return ''
  271. }
  272. },
  273. getSeatTypeList(obj,data){
  274. let list1 = []
  275. this.countBySeatTypList.forEach((item1,index1)=>{
  276. list1.push({
  277. "seatTypeId": item1.seatTypeId,
  278. "seatTypeName": item1.seatTypeName,
  279. "stockNum": '',
  280. "stock": item1.stock,
  281. })
  282. if(obj.stockType == 0 && data.chennelList && data.chennelList.length>0) {
  283. data.chennelList.forEach((item2,index2)=>{
  284. if(item1.seatTypeId == item2.seatTypeId && obj.stockType == item2.stockType && obj.channelType == item2.channelType ) {
  285. list1[index1].stockNum = item2.stockNum
  286. }
  287. })
  288. }
  289. })
  290. return list1
  291. },
  292. getChennelSeatList(obj,data) {
  293. let list = []
  294. if(data.chennelList && data.chennelList.length>0) {
  295. for(let i = 0;i<data.chennelList.length;i++) {
  296. if(obj.channelType == data.chennelList[i].channelType) {
  297. list = data.chennelList[i].chennelSeatList ? JSON.parse(JSON.stringify(data.chennelList[i].chennelSeatList)):[]
  298. break;
  299. }
  300. }
  301. }
  302. return list
  303. },
  304. // setChennelList() {
  305. // },
  306. /** 价格输入事件 */
  307. changePriceAmount(key) {
  308. if(this.form[key] * 1 < 0){
  309. this.$message.error("输入需大于或等于0!");
  310. this.$set(this.form, key, '');
  311. return false
  312. }
  313. },
  314. /**
  315. * 保存
  316. * @date 2023-11-22
  317. * @returns {any}
  318. */
  319. submitForm() {
  320. this.$refs["form"].validate(async (valid,object) => {
  321. if (valid) {
  322. try {
  323. console.log("this.form=====",this.form)
  324. let postMap = JSON.parse(JSON.stringify(this.form))
  325. postMap.chennelList = []
  326. for(let i = 0; i< this.form.chennelListForm.length ;i++) {
  327. let obj = {
  328. "id": null,
  329. "channelType": this.form.chennelListForm[i].channelType,
  330. "channelName": this.form.chennelListForm[i].channelName,
  331. "stockType": this.form.chennelListForm[i].stockType,
  332. }
  333. if(this.form.chennelListForm[i].stockType == 0 && this.form.chennelListForm[i].stockNum) {
  334. if(this.form.chennelListForm[i].seatTypeList && this.form.chennelListForm[i].seatTypeList.length>0) {
  335. for(let j = 0;j< this.form.chennelListForm[i].seatTypeList.length;j++) {
  336. if(this.form.chennelListForm[i].seatTypeList[j].stockNum) {
  337. postMap.chennelList.push({
  338. ...obj,
  339. "seatTypeId": this.form.chennelListForm[i].seatTypeList[j].seatTypeId,
  340. "stockNum": this.form.chennelListForm[i].seatTypeList[j].stockNum,
  341. "chennelSeatList":null
  342. })
  343. }
  344. }
  345. }
  346. }else if(this.form.chennelListForm[i].stockType == 1 && this.form.chennelListForm[i].stockNum){
  347. postMap.chennelList.push({
  348. "id": null,
  349. "channelType": this.form.chennelListForm[i].channelType,
  350. "channelName": this.form.chennelListForm[i].channelName,
  351. "stockType": this.form.chennelListForm[i].stockType,
  352. "seatTypeId": null,
  353. "stockNum": this.form.chennelListForm[i].stockNum,
  354. "chennelSeatList": this.form.chennelListForm[i].chennelSeatList
  355. })
  356. }
  357. }
  358. delete postMap.chennelListForm
  359. console.log("postMap=====",postMap)
  360. } catch (error) {
  361. } finally {
  362. this.loading = false;
  363. }
  364. }else{
  365. // console.log('error submit!!',valid,object);
  366. if(object&&JSON.stringify(object) != '{}'){
  367. let str = ''
  368. for(let key in object){
  369. if(object.hasOwnProperty(key)){
  370. str = str + `[${object[key][0].message}]}]`
  371. }
  372. }
  373. this.$message.error(str);
  374. }
  375. }
  376. });
  377. },
  378. /**
  379. * 重置
  380. * @date 2023-11-22
  381. * @returns {any}
  382. */
  383. reset() {
  384. },
  385. /**
  386. * 关闭弹框
  387. * @date 2023-11-22
  388. * @returns {any}
  389. */
  390. cancel() {
  391. this.open = false;
  392. this.chennelAtion = null
  393. },
  394. /** 获取座位可用数量 */
  395. async countBySeatTypFun(value,type) {
  396. console.log("vlaue===",value)
  397. try {
  398. this.$set(this.form,'seatNum','')
  399. this.chennelAtion = null
  400. if(!value) return
  401. let res = await countBySeatTyp({auditoriumId: value})
  402. let num = 0
  403. res.data.forEach((item,index)=>{
  404. num = num + item.stock
  405. })
  406. this.$set(this.form,'seatNum',num)
  407. this.countBySeatTypList = res.data
  408. if(!type) {
  409. this.form.chennelListForm = this.setDataTree({})
  410. this.setDictLabel(this.form.chennelListForm[0],0)
  411. }
  412. } catch (error) {
  413. console.error("error1====",error)
  414. }
  415. },
  416. /** 获取渠道数据 */
  417. async channelTypeFun() {
  418. try {
  419. let res = await channelType({pageNum: 1, pageSize: 100})
  420. this.channelTypeList = res.data
  421. } catch (error) {
  422. }
  423. },
  424. setDictLabel(obj,index){
  425. this.chennelAtion = index
  426. }
  427. },
  428. };
  429. </script>
  430. <style lang="scss" scoped>
  431. .dialog {
  432. padding: 0 30px;
  433. max-height: 65vh;
  434. overflow-y: auto;
  435. }
  436. .dialog {
  437. padding: 0 30px;
  438. .upload-btn {
  439. width: 100px;
  440. height: 100px;
  441. background-color: #fbfdff;
  442. border: dashed 1px #c0ccda;
  443. border-radius: 5px;
  444. i {
  445. font-size: 30px;
  446. margin-top: 20px;
  447. }
  448. &-text {
  449. margin-top: -10px;
  450. }
  451. }
  452. .avatar {
  453. cursor: pointer;
  454. }
  455. }
  456. .el-table{
  457. .upload-btn {
  458. width: 100px;
  459. height: 100px;
  460. background-color: #fbfdff;
  461. border: dashed 1px #c0ccda;
  462. border-radius: 5px;
  463. i {
  464. font-size: 30px;
  465. margin-top: 20px;
  466. }
  467. &-text {
  468. margin-top: -10px;
  469. }
  470. }
  471. .avatar {
  472. cursor: pointer;
  473. }
  474. }
  475. .area-container {
  476. min-height: 400px;
  477. }
  478. ::v-deep .area-wrap-city.el-cascader {
  479. line-height: normal;
  480. .el-input {
  481. cursor: pointer;
  482. width: 100% !important;
  483. height: 28px !important;
  484. .el-input__inner {
  485. display: none !important;
  486. }
  487. span.el-input__suffix {
  488. position: inherit !important;
  489. i.el-input__icon {
  490. line-height: inherit;
  491. margin-left: 5px;
  492. }
  493. }
  494. .el-input__wrapper {
  495. box-shadow: none;
  496. input {
  497. display: none;
  498. }
  499. }
  500. }
  501. .el-cascader__tags {
  502. display: none;
  503. }
  504. }
  505. .area-city-popper {
  506. .el-cascader-panel {
  507. .el-scrollbar.el-cascader-menu {
  508. .el-cascader-menu__wrap.el-scrollbar__wrap {
  509. height: 315px;
  510. }
  511. }
  512. }
  513. }
  514. .inventory_box{
  515. width: 100%;
  516. border: 1px solid #ccc;
  517. min-height: 400px;
  518. padding: 10px;
  519. box-sizing: border-box;
  520. display: flex;
  521. flex-shrink: 0;
  522. .inventory_channel {
  523. width: 200px;
  524. >div {
  525. width: 100%;
  526. box-sizing: border-box;
  527. >span {
  528. display: flex;
  529. justify-content: center;
  530. align-items: center;
  531. border-right: 1px solid #333;
  532. }
  533. >span:nth-child(1) {
  534. width: 40px;
  535. }
  536. >span:nth-child(2) {
  537. flex: auto;
  538. }
  539. >span:nth-child(3) {
  540. width: 50px;
  541. }
  542. }
  543. .inventory_channel_header {
  544. width: 100%;
  545. height: 40px;
  546. display: flex;
  547. background-color: #ccc;
  548. border-bottom: 1px solid #333;
  549. border-top: 1px solid #333;
  550. border-left: 1px solid #333;
  551. }
  552. .inventory_channel_item {
  553. width: 100%;
  554. display: flex;
  555. height: 40px;
  556. cursor: pointer;
  557. border-bottom: 1px solid #333;
  558. border-left: 1px solid #333;
  559. }
  560. .inventory_channel_item:hover {
  561. background-color: rgba(135, 206, 235,0.6);
  562. }
  563. .inventory_channel_item-action {
  564. background-color: rgba(135, 206, 235,0.6);
  565. }
  566. }
  567. .inventory_seat {
  568. flex: auto;
  569. padding-left: 20px;
  570. box-sizing: border-box;
  571. }
  572. }
  573. </style>
  574. <style>
  575. .custom-class-box {
  576. z-index: 999999 !important;
  577. }
  578. </style>