addAndEdit.vue 8.6 KB

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