index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <script lang="ts">
  2. // 声明额外的选项
  3. export default {
  4. name: "Add"
  5. };
  6. </script>
  7. <script setup lang="ts">
  8. import { inject, onMounted, reactive, ref, Uploadfile, UploadImg, Editor, useRenderIcon, ElMessage, ElMessageBox, Upload, Close, http, getGroupUrl, RegularVerification, verification } from "@/utils/importUsed"
  9. // 接口列表实例
  10. let UrlList = reactive(null)
  11. // 获取当前板块接口列表
  12. onMounted(async () => {
  13. UrlList = await getGroupUrl(["prizeSet"]);
  14. projectIdQuery();
  15. prizeObjQuery();
  16. })
  17. // 组件传参对象
  18. const props = defineProps<{
  19. submit: Function;
  20. addVisible: {
  21. type: Boolean;
  22. default: false;
  23. };
  24. width: {
  25. type: Number;
  26. default: 50;
  27. };
  28. projectId: {
  29. type: Number;
  30. default: 0;
  31. },
  32. }>();
  33. // 表单数据
  34. let UpdateForm = ref({
  35. projectId: props.projectId, //项目
  36. kind: "", //奖励分类
  37. prizeName: "", //奖励名称
  38. prizePercent: "", //奖励比例
  39. prizeAmount: "", //奖励固定金额
  40. conditionMode: "", //条件模式
  41. recursionFlag: "", //是否递归
  42. prizeContent: "", //奖励内容
  43. requestParamField: "", //入参字段
  44. prizeSourceField: "", //奖励金额来源数据
  45. prizeSourceFieldType: "", //奖励金额来源数据类型
  46. prizeObj: null, //奖励发放对象
  47. queryTableIdList: "", //条件匹配列表
  48. });
  49. // 表单实例
  50. const ruleFormRef = ref()
  51. // 传参选项数据
  52. // 项目选项数据
  53. const projectIdOptionList = ref([]);
  54. const prizeObjOptionList = ref([]);
  55. // 条件模式选项数据
  56. const conditionModeOptionList = [
  57. { id: 'all', label: '全部满足' },
  58. { id: 'one', label: '一个满足' },
  59. { id: 'two', label: '两个满足' },
  60. { id: 'three', label: '三个满足' },
  61. ]
  62. // 奖励内容选项数据
  63. const prizeContentOptionList = [
  64. { id: 'cash', label: '现金' },
  65. { id: 'recyc', label: '循环资格' },
  66. { id: 'coupon', label: '机具券' },
  67. { id: 'reserve', label: '额度' },
  68. ]
  69. // 奖励分类
  70. const kindOptionList = [
  71. { id: 'pos', label: '机具奖励' },
  72. { id: 'order', label: '订单奖励' },
  73. { id: 'reserve', label: '额度返还' },
  74. ]
  75. // 奖励金额来源数据类型
  76. const prizeSourceFieldTypeOptionList = [
  77. { id: 'condi', label: '条件返回字段' },
  78. { id: 'loop', label: '循环递归返回字段' },
  79. ]
  80. // 选项卡参数(默认值为列表某项的id)
  81. const activeId = ref('1')
  82. // 提交函数
  83. const submit = async (formEl) => {
  84. // 表单校验拦截
  85. if (!formEl) return
  86. await formEl.validate(async (valid, fields) => {
  87. if (valid) {
  88. //表单校验成功回调
  89. console.log('submit!')
  90. // 需动态生成接口
  91. const { status, msg }: any = await http.Request({
  92. method: UrlList.prizeSet.priaddPriList.method,
  93. url: UrlList.prizeSet.priaddPriList.url,
  94. params: UpdateForm.value
  95. });
  96. if (status === 1) {
  97. //业务成功回调
  98. ElMessage({
  99. message: "新增成功",
  100. type: "success"
  101. });
  102. UpdateForm.value = {
  103. projectId: props.projectId, //项目
  104. kind: "", //奖励分类
  105. prizeName: "", //奖励名称
  106. prizePercent: "", //奖励比例
  107. prizeAmount: "", //奖励固定金额
  108. conditionMode: "", //条件模式
  109. recursionFlag: "", //是否递归
  110. prizeContent: "", //奖励内容
  111. requestParamField: "", //入参字段
  112. prizeSourceField: "", //奖励金额来源数据
  113. prizeSourceFieldType: "", //奖励金额来源数据类型
  114. prizeObj: null, //奖励发放对象
  115. queryTableIdList: "", //条件匹配列表
  116. };
  117. // 关闭新增弹窗;
  118. closeVisible()
  119. } else {
  120. //业务失败回调
  121. ElMessageBox.alert(msg, "提示", {
  122. confirmButtonText: "关闭",
  123. type: "warning"
  124. });
  125. }
  126. } else {
  127. //表单校验失败回调
  128. ElMessage({
  129. message: "请输入完整信息",
  130. type: "error"
  131. });
  132. }
  133. })
  134. };
  135. //获取项目数据
  136. const projectIdQuery = async () => {
  137. const { status, data }: any = await http.Request({ method: UrlList.prizeSet.prigetPriProjectDic.method, url: UrlList.prizeSet.prigetPriProjectDic.url, params: {} });
  138. if (status === 1) {
  139. projectIdOptionList.value = data.records;
  140. }
  141. };
  142. //获取奖励发放对象
  143. const prizeObjQuery = async () => {
  144. console.log(1);
  145. const { status, data }: any = await http.Request({ method: UrlList.prizeSet.prigetPriPrizeObjectTableDic.method, url: UrlList.prizeSet.prigetPriPrizeObjectTableDic.url, params: {} });
  146. if (status === 1) {
  147. prizeObjOptionList.value = data.records;
  148. }
  149. };
  150. // 表单校验规则
  151. const rules = reactive({
  152. projectId: [
  153. { required: true, message: '请输入项目', trigger: 'blur' },
  154. ],
  155. prizeName: [
  156. { required: true, message: '请输入奖励名称', trigger: 'blur' },
  157. ],
  158. prizePercent: [
  159. { required: true, message: '请输入奖励比例', trigger: 'blur' },
  160. ],
  161. conditionMode: [
  162. { required: true, message: '请输入条件模式', trigger: 'blur' },
  163. ],
  164. })
  165. // 关闭弹窗回调函数
  166. const closeFn: any = inject("closeAddVisible");
  167. const closeVisible = () => {
  168. // 清空表单项;
  169. UpdateForm.value = {
  170. projectId: props.projectId, //项目
  171. kind: "", //奖励分类
  172. prizeName: "", //奖励名称
  173. prizePercent: "", //奖励比例
  174. prizeAmount: "", //奖励固定金额
  175. conditionMode: "", //条件模式
  176. recursionFlag: "", //是否递归
  177. prizeContent: "", //奖励内容
  178. requestParamField: "", //入参字段
  179. prizeSourceField: "", //奖励金额来源数据
  180. prizeSourceFieldType: "", //奖励金额来源数据类型
  181. prizeObj: null, //奖励发放对象
  182. queryTableIdList: "", //条件匹配列表
  183. };
  184. closeFn();
  185. };
  186. // 弹窗是否全屏
  187. const isFullscreen = ref(false)
  188. </script>
  189. <template lang="pug">
  190. .main
  191. el-dialog(v-model='props.addVisible' width="50%" :fullscreen="isFullscreen" title="新增" draggable @close="closeVisible")
  192. el-form(:model='UpdateForm' label-position="right" ref="ruleFormRef" :rules="rules" label-width="100px")
  193. el-form-item(label="项目", prop="projectId")
  194. el-select(
  195. v-model="UpdateForm.projectId",
  196. placeholder="请选择项目",
  197. clearable,
  198. )
  199. el-option(:label="item.projectName", :value="item.id" v-for="(item,index) in projectIdOptionList")
  200. el-form-item(label="奖励分类", prop="kind")
  201. el-select(
  202. v-model="UpdateForm.kind",
  203. placeholder="请选择奖励分类",
  204. clearable,
  205. )
  206. el-option(:label="item.label", :value="item.id" v-for="(item,index) in kindOptionList")
  207. el-form-item(label='奖励名称' prop="prizeName")
  208. el-input(v-model='UpdateForm.prizeName' autocomplete='off'
  209. placeholder="请输入奖励名称")
  210. el-form-item(label='奖励比例' prop="prizePercent")
  211. el-input-number(v-model='UpdateForm.prizePercent' :min="0" :max="1000"
  212. placeholder="请输入奖励比例")
  213. el-form-item(label='奖励固定金额' prop="prizeAmount")
  214. el-input-number(v-model='UpdateForm.prizeAmount' :min="0" :max="100000"
  215. placeholder="请输入奖励固定金额")
  216. el-form-item(label="条件模式", prop="conditionMode")
  217. el-select(
  218. v-model="UpdateForm.conditionMode",
  219. placeholder="请选择条件模式",
  220. clearable,
  221. )
  222. el-option(:label="item.label", :value="item.id" v-for="(item,index) in conditionModeOptionList")
  223. el-form-item(label='是否递归' prop="recursionFlag")
  224. el-switch(v-model="UpdateForm.recursionFlag")
  225. el-form-item(label="奖励内容", prop="prizeContent")
  226. el-select(
  227. v-model="UpdateForm.prizeContent",
  228. placeholder="请选择奖励内容",
  229. clearable,
  230. )
  231. el-option(:label="item.label", :value="item.id" v-for="(item,index) in prizeContentOptionList")
  232. el-form-item(label='入参字段' prop="requestParamField")
  233. el-input(v-model='UpdateForm.requestParamField' autocomplete='off'
  234. placeholder="请输入入参字段")
  235. el-form-item(label='奖励金额来源数据' prop="prizeSourceField")
  236. el-input(v-model='UpdateForm.prizeSourceField' autocomplete='off'
  237. placeholder="请输入奖励金额来源数据")
  238. el-form-item(label="奖励金额来源数据类型", prop="prizeSourceFieldType")
  239. el-select(
  240. v-model="UpdateForm.prizeSourceFieldType",
  241. placeholder="请选择奖励金额来源数据类型",
  242. clearable,
  243. )
  244. el-option(:label="item.label", :value="item.id" v-for="(item,index) in prizeSourceFieldTypeOptionList")
  245. el-form-item(label="发放对象", prop="prizeObj")
  246. el-select(
  247. v-model="UpdateForm.prizeObj",
  248. placeholder="请选择发放对象",
  249. clearable,
  250. )
  251. el-option(:label="item.tableEnName + item.note", :value="item.id" v-for="(item,index) in prizeObjOptionList")
  252. el-form-item(label='条件匹配列表' prop="queryTableIdList")
  253. el-input(v-model='UpdateForm.queryTableIdList' autocomplete='off'
  254. placeholder="请输入条件匹配列表")
  255. .flex.justify-end
  256. el-button(
  257. :icon="useRenderIcon(Close)",
  258. @click="closeVisible"
  259. ) 关闭
  260. el-button(
  261. type="primary",
  262. :icon="useRenderIcon(Upload)",
  263. @click="submit(ruleFormRef)"
  264. ) 确认提交
  265. </template>
  266. <style scoped lang="scss">
  267. :deep(.el-dropdown-menu__item i) {
  268. margin: 0;
  269. }
  270. :deep(.el-form-item__label) {
  271. font-weight: 700;
  272. }
  273. :deep(.el-pagination) {
  274. flex-flow: wrap;
  275. }
  276. :deep(.is-draggable) {
  277. max-height: 80vh;
  278. overflow: auto;
  279. }
  280. :deep(.el-dialog__header) {
  281. position: sticky;
  282. top: 0;
  283. z-index: 2;
  284. background: #fff;
  285. }
  286. .collapsedom {
  287. padding: 0 20px;
  288. background-color: #fff;
  289. }
  290. .ovh-x {
  291. height: 40vh;
  292. overflow-y: auto;
  293. }
  294. :deep(.el-descriptions__header) {
  295. margin: 16px 0 !important;
  296. }
  297. .el-select {
  298. width: 100%;
  299. }
  300. </style>