voteDlg.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <script setup>
  2. import { reactive, ref, onMounted, watch } from "vue";
  3. import { raiInterface, raiSpecial } from "@/api/api.js";
  4. import RichText from "../../../components/richText.vue";
  5. import { ElMessage } from "element-plus";
  6. const props = defineProps({
  7. initiateVotingDlg: {
  8. type: Boolean,
  9. default: false,
  10. },
  11. rowForm: {
  12. type: Object,
  13. default: {},
  14. },
  15. });
  16. const $emit = defineEmits(["getDataList"]);
  17. watch(
  18. () => props.rowForm,
  19. (newVal) => {
  20. props.initiateVotingDlg && newVal.QuestionnaireId && getListDetails();
  21. },
  22. {
  23. deep: true,
  24. immediate: true,
  25. }
  26. );
  27. // 校验规则
  28. const votingRules = ref({
  29. type: [{ required: true, message: "请选择活动类型", trigger: "change" }],
  30. describe: [{ required: true, message: "请输入首段描述文字", trigger: "blur" }],
  31. date: [{ required: true, message: "请设置投票截止时间", trigger: "change" }],
  32. select: [{ required: true, message: "请输入最多可选几项", trigger: "change" }],
  33. });
  34. const votingForm = ref({
  35. type: 8,
  36. describe: "",
  37. date: "",
  38. select: "",
  39. addThemeList: [
  40. { QuestionnaireThemeId: 0, ActivityTheme: "" },
  41. { QuestionnaireThemeId: 0, ActivityTheme: "" },
  42. ],
  43. });
  44. function closeHandler() {
  45. votingForm.value = {
  46. type: 8,
  47. describe: "",
  48. date: "",
  49. select: "",
  50. addThemeList: [
  51. { QuestionnaireThemeId: 0, ActivityTheme: "" },
  52. { QuestionnaireThemeId: 0, ActivityTheme: "" },
  53. ],
  54. };
  55. votingFormRes.value.resetFields();
  56. $emit("update:initiateVotingDlg", false);
  57. $emit("update:rowForm", {});
  58. }
  59. // 添加主题
  60. function addThemeHandler() {
  61. let id = votingForm.value.addThemeList.length;
  62. votingForm.value.addThemeList.push({ QuestionnaireThemeId: 0, ActivityTheme: "" });
  63. }
  64. function deleteThemeItem(item, index) {
  65. if (index >= 2) {
  66. votingForm.value.addThemeList.splice(index, 1);
  67. }
  68. }
  69. const votingFormRes = ref(null);
  70. // 点击确定
  71. function submitForm() {
  72. votingFormRes.value.validate(async (valid) => {
  73. if (valid) {
  74. const res = await raiInterface.questionnairePreserveAndEdit({
  75. ActivityTypeId: votingForm.value.type,
  76. MaxChooseTotal: votingForm.value.select,
  77. Content: votingForm.value.describe.replace(/<p data-f-id=\"pbf\".*?<\/p>/g, ""),
  78. EndTime: votingForm.value.date,
  79. ListTheme: votingForm.value.addThemeList,
  80. QuestionnaireId: props.rowForm.QuestionnaireId || 0,
  81. });
  82. if (res.Ret === 200) {
  83. $emit("getDataList");
  84. ElMessage.success("操作成功");
  85. closeHandler();
  86. }
  87. } else {
  88. console.log("error submit!!");
  89. return false;
  90. }
  91. });
  92. }
  93. async function getListDetails() {
  94. const res = await raiInterface.questionnaireDetail({
  95. QuestionnaireId: props.rowForm.QuestionnaireId,
  96. });
  97. if (res.Ret === 200) {
  98. let detail = res.Data.Detail;
  99. votingForm.value = {
  100. type: detail.ActivityTypeId,
  101. describe: detail.Content,
  102. date: detail.EndTime,
  103. select: detail.MaxChooseTotal,
  104. addThemeList: detail.ListTheme,
  105. };
  106. }
  107. }
  108. // 获取活动类型
  109. const optionsActivity = ref([]);
  110. async function activityType() {
  111. const res = await raiInterface.getActivityType({
  112. IsGetAll: true,
  113. });
  114. if (res.Ret === 200) {
  115. optionsActivity.value = res.Data.List;
  116. }
  117. }
  118. // 富文本
  119. const froalaConfig = ref({
  120. height: 150,
  121. fontSizeDefaultSelection: "16",
  122. quickInsertEnabled: false,
  123. theme: "dark", //主题
  124. placeholderText: "请输入首段描述文字",
  125. language: "zh_cn",
  126. events: {
  127. initialized: function () {
  128. this.toolbar.hide();
  129. },
  130. },
  131. });
  132. onMounted(() => {
  133. activityType();
  134. });
  135. </script>
  136. <template>
  137. <div class="container vote-dlg-container">
  138. <el-dialog
  139. draggable
  140. :close-on-click-modal="false"
  141. :title="props.rowForm.QuestionnaireId ? '编辑' : '发起投票'"
  142. :modal-append-to-body="false"
  143. center
  144. :append-to-body="true"
  145. v-model="props.initiateVotingDlg"
  146. :before-close="closeHandler"
  147. width="800px"
  148. >
  149. <div class="vote-dlg-container-theme-survey">
  150. <el-form :model="votingForm" :rules="votingRules" ref="votingFormRes" class="demo-ruleForm">
  151. <el-form-item prop="type">
  152. <el-select style="width: 100%" v-model="votingForm.type" placeholder="请选择活动类型">
  153. <el-option v-for="item in optionsActivity" :label="item.ActivityTypeName" :key="item.ActivityTypeId" :value="item.ActivityTypeId"> </el-option>
  154. </el-select>
  155. </el-form-item>
  156. <el-form-item prop="describe">
  157. <div class="fr-wrapper-content-vote-dlg-container">
  158. <froala :tag="'textarea'" :config="froalaConfig" v-model="votingForm.describe"></froala>
  159. </div>
  160. </el-form-item>
  161. <el-form-item prop="date">
  162. <el-date-picker v-model="votingForm.date" type="date" placeholder="请设置投票截止时间" value-format="YYYY-MM-DD" style="width: 100%"> </el-date-picker>
  163. </el-form-item>
  164. <el-form-item prop="select">
  165. <el-select v-model="votingForm.select" placeholder="最多可选几项" style="width: 100%" @change="selectChangeHandler">
  166. <el-option label="1" :value="1"></el-option>
  167. <el-option label="2" :value="2"></el-option>
  168. <el-option label="3" :value="3"></el-option>
  169. <el-option label="4" :value="4"></el-option>
  170. <el-option label="5" :value="5"></el-option>
  171. </el-select>
  172. </el-form-item>
  173. <el-form-item
  174. v-for="(item, index) in votingForm.addThemeList"
  175. :key="index"
  176. :prop="'addThemeList.' + index + '.ActivityTheme'"
  177. :rules="{
  178. required: true,
  179. message: '请填写活动主题',
  180. trigger: 'blur',
  181. }"
  182. >
  183. <div class="add-theme-content">
  184. <el-input v-model="item.ActivityTheme" placeholder="活动主题" style="width: 100%" clearable></el-input>
  185. <div class="delete-item-icon" @click="deleteThemeItem(item, index)" v-if="index >= 2">
  186. <img src="~@/assets/img/icons/delete-Item.png" alt="" />
  187. </div>
  188. </div>
  189. </el-form-item>
  190. <el-form-item>
  191. <div class="add-theme-box" @click="addThemeHandler">
  192. <el-image style="width: 25px; height: 25px; margin-right: 10px" :src="require('@/assets/img/icons/add-img.png')" />
  193. <span style="cursor: pointer">添加主题</span>
  194. </div>
  195. </el-form-item>
  196. </el-form>
  197. </div>
  198. <template #footer>
  199. <div class="dialog-footer">
  200. <el-button type="primary" @click="submitForm">确定</el-button>
  201. <el-button style="margin-left: 30px" type="primary" plain @click="closeHandler">取消</el-button>
  202. </div>
  203. </template>
  204. </el-dialog>
  205. </div>
  206. </template>
  207. <style scoped lang="scss">
  208. .vote-dlg-container-theme-survey {
  209. .add-theme-content {
  210. display: flex;
  211. align-items: center;
  212. }
  213. .delete-item-icon {
  214. display: flex;
  215. align-items: center;
  216. margin-left: 20px;
  217. cursor: pointer;
  218. img {
  219. width: 15px;
  220. height: 15px;
  221. }
  222. }
  223. .add-theme-box {
  224. display: flex;
  225. align-items: center;
  226. }
  227. }
  228. .fr-wrapper-content-vote-dlg-container {
  229. width: 100%;
  230. border-top: 1px solid #cccccc !important;
  231. border-bottom: 1px solid #cccccc !important;
  232. }
  233. </style>