addAndEdit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: Sugar.
  6. * @LastEditTime: 22023-11-24 13:55:00
  7. * @FilePath: \cattle_webui\src\views\team\ticketMr\dialog\AddOrEditDialog.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="700px"
  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" :rules="rules" label-width="120px">
  21. <el-form-item label="选择剧目:" prop="performId">
  22. <el-select
  23. v-model="form.performId"
  24. placeholder="选择剧目"
  25. clearable
  26. @change="performChangeEven"
  27. style="width: 100%;"
  28. >
  29. <el-option
  30. v-for="dict in goodsList"
  31. :key="dict.id"
  32. :label="dict.name"
  33. :value="dict.id"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="票务管理:" prop="goodsId">
  38. <el-select
  39. v-model="form.goodsId"
  40. placeholder="票务管理"
  41. clearable
  42. @change="goodsChangeEven"
  43. style="width: 100%;"
  44. >
  45. <el-option
  46. v-for="dict in ticketList"
  47. :key="dict.id"
  48. :label="dict.goodsName"
  49. :value="dict.goodsId"
  50. />
  51. </el-select>
  52. </el-form-item>
  53. <el-form-item label="座位类型:" prop="seatTypeId">
  54. <el-select
  55. v-model="form.seatTypeId"
  56. placeholder="座位类型"
  57. clearable
  58. @change="seatChangeEven"
  59. style="width: 100%;"
  60. >
  61. <el-option
  62. v-for="dict in seatList"
  63. :key="dict.seatTypeId"
  64. :label="dict.seatTypeName"
  65. :value="dict.seatTypeId"
  66. />
  67. </el-select>
  68. </el-form-item>
  69. <el-form-item label="销售价:" prop="originalSalePrice">
  70. <el-input
  71. disabled
  72. v-model="form.originalSalePrice"
  73. placeholder="销售价"
  74. clearable
  75. style="width: 100%;"
  76. />
  77. </el-form-item>
  78. <el-form-item label="团购单价:" prop="salePrice">
  79. <el-input
  80. type="number"
  81. v-model="form.salePrice"
  82. placeholder=""
  83. clearable
  84. @change="changePriceAmount('salePrice')"
  85. style="width: 260px;"
  86. >
  87. <template slot="append">元/人</template>
  88. </el-input>
  89. </el-form-item>
  90. <el-form-item label="成团人数:" prop="teamPersonNum">
  91. <el-input
  92. type="number"
  93. v-model="form.teamPersonNum"
  94. placeholder=""
  95. clearable
  96. @change="changePriceAmount('teamPersonNum')"
  97. style="width: 260px;"
  98. >
  99. </el-input>
  100. <span style="margin-left: 5px">人起成团</span>
  101. </el-form-item>
  102. </el-form>
  103. </div>
  104. <span slot="footer" class="dialog-footer">
  105. <el-button @click="cancel">取消</el-button>
  106. <el-button
  107. type="primary"
  108. @click="submitForm"
  109. v-loading.fullscreen.lock="loading"
  110. element-loading-text="提交中..."
  111. element-loading-spinner="el-icon-loading"
  112. element-loading-background="rgba(0, 0, 0, 0.8)"
  113. >
  114. <span v-if="loading">提交中...</span>
  115. <span v-else>保存</span>
  116. </el-button>
  117. </span>
  118. </el-dialog>
  119. </template>
  120. <script>
  121. // import { updateNoticeMgr } from "@/api/system/noticeMgr";
  122. import { saveAndEdit, getSelectById } from "@/api/team/ticketMr";
  123. import Editor from "@/components/Editor";
  124. import { getToken } from "@/utils/auth";
  125. import { goodsPageList } from '@/api/programmeMr/programmeMr'
  126. import { seatPricePageList } from '@/api/distribution/ticketMr'
  127. export default {
  128. name: "addAndEdit",
  129. props: {
  130. dict: {
  131. type: Object,
  132. default: () => [],
  133. },
  134. },
  135. components: {
  136. Editor,
  137. },
  138. data() {
  139. return {
  140. title: "编辑",
  141. model: "EDIT",
  142. activeName: '01',
  143. open: false,
  144. loading: false,
  145. form: {
  146. id: undefined,
  147. },
  148. rules: {
  149. performId: [{ required: true, message: "请选择选择剧目", trigger: ["change","blur"] }],
  150. goodsId: [{ required: true, message: "请选择票务", trigger: ["change","blur"] }],
  151. seatTypeId: [{ required: true, message: "请选择座位类型", trigger: ["change","blur"] }],
  152. salePrice: [{ required: true, message: "请输入团购单价", trigger: ["change","blur"] }],
  153. originalSalePrice: [{ required: true, message: "请输入销售价", trigger: ["change","blur"] }],
  154. teamPersonNum: [{ required: true, message: "请输入人数", trigger: ["change","blur"] }],
  155. },
  156. uploadObj: {
  157. url: process.env.VUE_APP_UPLOAD_FILE_API + "/upload/single/minio",
  158. Headers: { Authorization: "Bearer " + getToken() },
  159. },
  160. goodsList: [],
  161. ticketList: [],
  162. seatList: []
  163. };
  164. },
  165. methods: {
  166. /**
  167. * 打开弹框
  168. * @date 2023-11-22
  169. * @param {any} obj
  170. * @returns {any}
  171. */
  172. openDialog(title, obj) {
  173. this.open = true;
  174. this.goodsPageList();
  175. this.reset();
  176. if (obj){
  177. this.title = "编辑票务管理";
  178. this.getSelectByIdApi(obj);
  179. }else{
  180. this.title = "添加票务管理";
  181. this.$nextTick(() => {
  182. this.$refs["form"].clearValidate();
  183. });
  184. }
  185. },
  186. /** 获取详情 */
  187. getSelectByIdApi(row) {
  188. const id = row.id
  189. getSelectById(id).then(response => {
  190. const obj = response.data;
  191. this.$nextTick(() => {
  192. this.$set(this.form, 'id', obj.id);
  193. this.$set(this.form, 'goodsId', obj.goodsId);
  194. this.$set(this.form, 'seatTypeId', obj.seatTypeId);
  195. this.$set(this.form, 'performId', obj.performId);
  196. this.$set(this.form, 'originalSalePrice', obj.originalSalePrice);
  197. this.$set(this.form, 'salePrice', obj.salePrice);
  198. this.$set(this.form, 'brokeragePrice', obj.brokeragePrice);
  199. this.$set(this.form, 'teamPersonNum', obj.teamPersonNum);
  200. this.ticketListApi();
  201. this.getSeatTypeList({goodsId: this.form.goodsId, performId: this.form.performId});
  202. });
  203. });
  204. },
  205. /** 剧目列表查询 */
  206. goodsPageList() {
  207. goodsPageList(this.addDateRange({pageNum: 1, pageSize: 100, status: 1}))
  208. .then(response => {
  209. this.goodsList = response.data.rows;
  210. });
  211. },
  212. /** 票务列表查询 */
  213. ticketListApi(performId) {
  214. this.ticketList = []
  215. seatPricePageList(this.addDateRange({pageNum: 1, pageSize: 100, performId: performId,goodsStatus: 0}))
  216. .then(response => {
  217. let ticketList = []
  218. response.data.rows.forEach(item => {
  219. if(ticketList.indexOf(item.goodsId) == -1){
  220. this.ticketList.push(item);
  221. ticketList.push(item.goodsId);
  222. }
  223. })
  224. });
  225. },
  226. /** 座位类型列表 */
  227. getSeatTypeList(obj) {
  228. seatPricePageList(this.addDateRange({pageNum: 1, pageSize: 100, goodsId: obj.goodsId, performId: obj.performId}))
  229. .then(response => {
  230. let ticketList = []
  231. response.data.rows.forEach(item => {
  232. if(ticketList.indexOf(item.seatTypeId) == -1){
  233. this.seatList.push(item);
  234. ticketList.push(item.seatTypeId);
  235. }
  236. })
  237. });
  238. },
  239. /** 价格输入事件 */
  240. changePriceAmount(key) {
  241. if(this.form[key] * 1 < 0){
  242. this.$message.error("输入需大于或等于0!");
  243. this.$set(this.form, key, '');
  244. return false
  245. }
  246. },
  247. // 剧目改变事件
  248. performChangeEven(val) {
  249. this.seatList = [];
  250. this.ticketList = [];
  251. this.$set(this.form, 'originalSalePrice', '')
  252. this.$set(this.form, 'goodsId', '');
  253. this.$set(this.form, 'seatTypeId', '');
  254. this.ticketListApi(val);
  255. },
  256. // 票务改变事件
  257. goodsChangeEven() {
  258. this.seatList = [];
  259. this.$set(this.form, 'originalSalePrice', '');
  260. this.$set(this.form, 'seatTypeId', '');
  261. let selectMap = {goodsId: this.form.goodsId, performId: this.form.performId}
  262. this.getSeatTypeList(selectMap);
  263. },
  264. // 座位类型改变事件
  265. seatChangeEven(val) {
  266. this.seatList.forEach(item => {
  267. if(item.seatTypeId == val){
  268. this.$set(this.form, 'originalSalePrice', item.priceAmount);
  269. }
  270. })
  271. },
  272. /**
  273. * 保存
  274. * @date 2023-11-22
  275. * @returns {any}
  276. */
  277. submitForm() {
  278. this.$refs["form"].validate(async (valid) => {
  279. if (valid) {
  280. try {
  281. this.loading = true;
  282. const { code } = await saveAndEdit({ ...this.form });
  283. if (code === 200) {
  284. this.$message.success("操作成功!");
  285. this.$emit("getList");
  286. this.cancel();
  287. }
  288. } catch (error) {
  289. } finally {
  290. this.loading = false;
  291. }
  292. }
  293. });
  294. },
  295. /**
  296. * 重置
  297. * @date 2023-11-22
  298. * @returns {any}
  299. */
  300. reset() {
  301. this.$set(this.form, 'id', '');
  302. this.$set(this.form, 'goodsId', '');
  303. this.$set(this.form, 'seatTypeId', '');
  304. this.$set(this.form, 'performId', '');
  305. this.$set(this.form, 'originalSalePrice', '');
  306. this.$set(this.form, 'salePrice', '');
  307. this.$set(this.form, 'brokeragePrice', '');
  308. this.$set(this.form, 'teamPersonNum', '');
  309. },
  310. /**
  311. * 关闭弹框
  312. * @date 2023-11-22
  313. * @returns {any}
  314. */
  315. cancel() {
  316. this.reset();
  317. this.open = false;
  318. },
  319. /**
  320. * 上传成功
  321. * @date 2023-11-22
  322. * @param {any} res
  323. * @returns {any}
  324. */
  325. handleAvatarSuccess(res) {
  326. if (res.code === 200) {
  327. // this.form.mainImg = res?.data?.url;
  328. this.$set(this.form, 'mainImg', res?.data?.url)
  329. }
  330. },
  331. /**
  332. * 上传文件之前之前
  333. * @date 2023-11-22
  334. * @param {any} file
  335. * @returns {any}
  336. */
  337. beforeAvatarUpload(file) {
  338. const isJPG = file.type === "image/jpeg" || "image/png";
  339. if (!isJPG) {
  340. this.$message.error("上传头像图片只能是jpg或png格式!");
  341. }
  342. return isJPG;
  343. },
  344. /**
  345. * 剧目海报上传成功
  346. * @date 2023-11-22
  347. * @param {any} res
  348. * @returns {any}
  349. */
  350. handlePhotoListSuccess(res) {
  351. if (res.code === 200) {
  352. let photo = {
  353. imageUrl: res?.data?.url,
  354. url: res?.data?.url,
  355. photoType: '2'
  356. }
  357. if(!this.form.photoList){
  358. this.form.photoList = []
  359. }
  360. // this.form.photoList.push(photo);
  361. this.$set(this.form.photoList, this.form.photoList.length, photo);
  362. }
  363. },
  364. handleRemove(file, fileList) {
  365. this.form.photoList.forEach((item, index) => {
  366. if(item.uid == file.uid){
  367. this.form.photoList.splice(index, 1)
  368. }
  369. })
  370. },
  371. },
  372. };
  373. </script>
  374. <style lang="scss" scoped>
  375. .dialog {
  376. padding: 0 30px;
  377. max-height: 65vh;
  378. overflow-y: auto;
  379. }
  380. .dialog {
  381. padding: 0 30px;
  382. .upload-btn {
  383. width: 100px;
  384. height: 100px;
  385. background-color: #fbfdff;
  386. border: dashed 1px #c0ccda;
  387. border-radius: 5px;
  388. i {
  389. font-size: 30px;
  390. margin-top: 20px;
  391. }
  392. &-text {
  393. margin-top: -10px;
  394. }
  395. }
  396. .avatar {
  397. cursor: pointer;
  398. }
  399. }
  400. </style>