aduitInvoice.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. -->
  4. <template>
  5. <el-dialog
  6. title="申请开票"
  7. v-if="isShow"
  8. :visible.sync="isShow"
  9. width="700px"
  10. append-to-body
  11. :close-on-click-modal="false"
  12. @close="cancel"
  13. >
  14. <div class="dialog">
  15. <el-form :model="aduitForm" ref="aduitForm" :rules="formRules" label-width="150px">
  16. <el-form-item label="抬头类型" prop="handlerType">
  17. <el-radio-group v-model="aduitForm.handlerType" @input="changeType">
  18. <el-radio :label="2">企业</el-radio>
  19. <el-radio :label="1">个人</el-radio>
  20. </el-radio-group>
  21. </el-form-item>
  22. <el-form-item v-if="aduitForm.handlerType == 2" label="申请类型:" prop="invoiceLine">
  23. <el-select
  24. v-model="aduitForm.invoiceLine"
  25. placeholder="请选择申请类型"
  26. clearable
  27. style="width: 100%;"
  28. >
  29. <el-option
  30. v-for="dict in listType"
  31. :key="dict.value"
  32. :label="dict.label"
  33. :value="dict.value"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="抬头名称:" prop="name">
  38. <el-input
  39. v-model="aduitForm.name"
  40. placeholder="请输入抬头名称"
  41. clearable
  42. style="width: 100%;"
  43. />
  44. </el-form-item>
  45. <el-form-item v-if="aduitForm.handlerType == 2" label="税号:" prop="creditCode">
  46. <el-input
  47. v-model="aduitForm.creditCode"
  48. placeholder="请输入税号"
  49. clearable
  50. style="width: 100%;"
  51. />
  52. </el-form-item>
  53. <el-form-item label="电子邮箱:" prop="email">
  54. <el-input
  55. v-model="aduitForm.email"
  56. placeholder="请输入电子邮箱"
  57. clearable
  58. style="width: 100%;"
  59. />
  60. </el-form-item>
  61. <el-form-item label="发票金额(¥):" prop="invoiceAmount">
  62. <el-input
  63. v-model="aduitForm.invoiceAmount"
  64. placeholder="发票金额"
  65. disabled
  66. clearable
  67. style="width: 100%;"
  68. />
  69. </el-form-item>
  70. </el-form>
  71. </div>
  72. <span slot="footer" class="dialog-footer">
  73. <el-button @click="cancel">取消</el-button>
  74. <el-button
  75. type="primary"
  76. @click="submitForm"
  77. v-loading.fullscreen.lock="loading"
  78. element-loading-text="提交中..."
  79. element-loading-spinner="el-icon-loading"
  80. element-loading-background="rgba(0, 0, 0, 0.8)"
  81. >
  82. <span v-if="loading">提交中...</span>
  83. <span v-else>保存</span>
  84. </el-button>
  85. </span>
  86. </el-dialog>
  87. </template>
  88. <script>
  89. import {
  90. saveAndEdit,
  91. } from '@/api/order/groupBuyingMr';
  92. import Editor from "@/components/Editor";
  93. export default {
  94. name: "addAndEdit",
  95. components: {
  96. Editor,
  97. },
  98. data() {
  99. let checkEmail = (rule, value, callback) => {
  100. const regEmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
  101. if (value && !regEmail.test(value)) {
  102. callback(new Error('请输入有效的邮箱'));
  103. } else {
  104. callback(); // 确保调用 callback
  105. }
  106. };
  107. return {
  108. model: "EDIT",
  109. isShow: false,
  110. loading: false,
  111. aduitForm: {
  112. id: '',
  113. invoiceAmount: '',
  114. invoiceLine: '',
  115. handlerType: '',
  116. name: '',
  117. creditCode: '',
  118. mobile: '',
  119. email: ''
  120. },
  121. listType: [
  122. {
  123. "label": "数电专票",
  124. "value": 'bs',
  125. },
  126. {
  127. "label": "数电普票",
  128. "value": 'pc',
  129. },
  130. ],
  131. formRules: {
  132. name: [{ required: true, message: "请输入抬头名称", trigger: "blur" }],
  133. invoiceLine: [{ required: true, message: "请选择申请类型", trigger: "change" }],
  134. email: [
  135. { required: true, message: "请输入电子邮箱", trigger: "blur" },
  136. {validator: checkEmail, trigger: "blur" }
  137. ],
  138. creditCode: [{ required: true, message: "请输入税号", trigger: "blur" }],
  139. },
  140. };
  141. },
  142. methods: {
  143. // 打开弹框
  144. openDialog(title, obj, type) {
  145. this.isShow = true;
  146. // this.reset();
  147. this.$set(this.aduitForm, 'invoiceAmount', obj.realPrice || obj.invoiceAmount);
  148. this.$set(this.aduitForm, 'id', type ? obj.orderId: obj.id);
  149. this.$set(this.aduitForm, 'handlerType', 2);
  150. this.$nextTick(() => {
  151. if (this.$refs["aduitForm"]) {
  152. // console.log('表单已初始化');
  153. this.$refs["aduitForm"].clearValidate();
  154. }
  155. });
  156. },
  157. // 保存
  158. submitForm() {
  159. // console.log(this.$refs["aduitForm"], '111'); // 检查表单引用
  160. this.$refs["aduitForm"].validate((valid) => {
  161. if (valid) {
  162. try {
  163. this.loading = true;
  164. let params = {
  165. orderId: this.aduitForm.id,
  166. invoiceAmount: this.aduitForm.invoiceAmount,
  167. invoiceLine: this.aduitForm.invoiceLine,
  168. invoiceSource: 3,
  169. invoiceHandler: {
  170. handlerType: this.aduitForm.handlerType,
  171. name: this.aduitForm.name,
  172. creditCode: this.aduitForm.creditCode,
  173. mobile: this.aduitForm.mobile,
  174. email: this.aduitForm.email
  175. }
  176. };
  177. saveAndEdit({ ...params }).then(({ code }) => {
  178. if (code === 200) {
  179. this.$message.success("操作成功!");
  180. this.$emit("getList");
  181. this.cancel();
  182. }
  183. });
  184. } catch (error) {
  185. // console.error(error);
  186. } finally {
  187. this.loading = false;
  188. }
  189. } else {
  190. // console.error('表单校验失败');
  191. }
  192. });
  193. },
  194. /**
  195. * 重置
  196. * @date 2023-11-22
  197. * @returns {any}
  198. */
  199. reset() {
  200. this.$set(this.aduitForm, 'id', "");
  201. this.$set(this.aduitForm, 'handlerType', '');
  202. this.$set(this.aduitForm, 'invoiceLine', "")
  203. this.$set(this.aduitForm, 'email', "");
  204. this.$set(this.aduitForm, 'name', "");
  205. this.$set(this.aduitForm, 'invoiceAmount', "");
  206. this.$set(this.aduitForm, 'creditCode', '');
  207. },
  208. // 关闭弹框
  209. cancel() {
  210. this.reset();
  211. this.isShow = false;
  212. if (this.$refs["aduitForm"]) {
  213. this.$refs["aduitForm"].resetFields();
  214. }
  215. },
  216. /** 选择抬头类型 */
  217. changeType(value) {
  218. if (value == 2) {
  219. // this.rules = {
  220. // ...this.rules,
  221. // creditCode: [{ required: true, message: "请输入税号", trigger: ["blur"] }]
  222. // };
  223. this.$set(this.aduitForm, 'invoiceLine', 'bs');
  224. } else {
  225. this.$set(this.aduitForm, 'invoiceLine', 'pc');
  226. this.$set(this.aduitForm, 'creditCode', '');
  227. delete this.rules.creditCode; // 移除 taxCode 校验规则 invoiceLine
  228. delete this.rules.invoiceLine; // 移除 taxCode 校验规则 invoiceLine
  229. }
  230. this.$nextTick(() => {
  231. if (this.$refs["aduitForm"]) {
  232. this.$refs["aduitForm"].clearValidate();
  233. }
  234. });
  235. }
  236. },
  237. };
  238. </script>
  239. <style lang="scss" scoped>
  240. .dialog {
  241. padding: 0 30px;
  242. max-height: 65vh;
  243. overflow-y: auto;
  244. }
  245. .dialog {
  246. padding: 0 30px;
  247. .upload-btn {
  248. width: 100px;
  249. height: 100px;
  250. background-color: #fbfdff;
  251. border: dashed 1px #c0ccda;
  252. border-radius: 5px;
  253. i {
  254. font-size: 30px;
  255. margin-top: 20px;
  256. }
  257. &-text {
  258. margin-top: -10px;
  259. }
  260. }
  261. .avatar {
  262. cursor: pointer;
  263. }
  264. }
  265. .team_name_list {
  266. width: 100%;
  267. span {
  268. display: flex;
  269. width: 100%;
  270. padding: 5px 10px;
  271. cursor: pointer;
  272. }
  273. span:hover {
  274. color: #1890ff;
  275. }
  276. }
  277. </style>