index.vue 8.0 KB

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