addDialog.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible.sync="addRepairNotesDialog"
  6. :title="title"
  7. :close-on-click-modal="false"
  8. width="85%"
  9. :maxable="true"
  10. append-to-body
  11. @close="handleClose"
  12. >
  13. <info ref="infoRef" :demandList="demandList" :type="type"></info>
  14. <SubmitDialog ref="submitRef" @savExit="savExit" />
  15. <dispatchDialog ref="dispatchRef" @savExit="savExit" />
  16. <div slot="footer" class="footer">
  17. <el-button
  18. type="primary"
  19. :loading="loading"
  20. @click="submitAdd"
  21. v-if="type != 'view'"
  22. >保存</el-button
  23. >
  24. <el-button
  25. type="primary"
  26. :loading="loading"
  27. @click="submit"
  28. v-if="type != 'view'"
  29. >提交</el-button
  30. >
  31. <el-button
  32. type="primary"
  33. :loading="loading"
  34. @click="dispatch"
  35. v-if="type != 'view'"
  36. >派单</el-button
  37. >
  38. <el-button @click="handleClose" :loading="loading">返回</el-button>
  39. </div>
  40. </ele-modal>
  41. </template>
  42. <script>
  43. import { mapGetters } from 'vuex';
  44. import modalTitle from '@/BIZComponents/modalTitle.vue';
  45. import customerDialog from '@/views/financialManage/components/customerListDialog.vue';
  46. import SubmitDialog from './submitDialog.vue';
  47. import dispatchDialog from './dispatchDialog.vue';
  48. import {
  49. saveSalesDemand,
  50. updateSalesDemand,
  51. getSalesDemandById
  52. } from '@/api/salesServiceManagement/index';
  53. import info from '@/views/salesServiceManagement/components/info.vue';
  54. import { getByCode } from '@/api/system/dictionary-data';
  55. export default {
  56. components: {
  57. modalTitle,
  58. customerDialog,
  59. info,
  60. SubmitDialog,
  61. dispatchDialog
  62. },
  63. watch: {},
  64. computed: {
  65. ...mapGetters(['getDictValue'])
  66. },
  67. data() {
  68. return {
  69. title: '新增',
  70. addRepairNotesDialog: false,
  71. type: 'add',
  72. form: {},
  73. demandList: [],
  74. loading: false
  75. };
  76. },
  77. created() {
  78. this.getLevelCode('requirement_name');
  79. },
  80. methods: {
  81. async getLevelCode(code) {
  82. console.log(code);
  83. try {
  84. const res = await getByCode(code);
  85. if (res.code == 0) {
  86. let list = Object.values(res.data).map((el) => {
  87. let k = Object.keys(el)[0];
  88. let v = Object.values(el)[0];
  89. return {
  90. label: v,
  91. value: k
  92. };
  93. });
  94. this.demandList = list;
  95. }
  96. } catch (err) {
  97. this.$message.error(err.message);
  98. }
  99. },
  100. init(row, type) {
  101. this.addRepairNotesDialog = true;
  102. this.type = type;
  103. this.title = type == 'add' ? '新增' : type == 'view' ? '详情' : '修改';
  104. if (row?.id) {
  105. this.getDetail(row.id);
  106. } else {
  107. }
  108. },
  109. async submit() {
  110. let pData = await this.handleParameter();
  111. if (!pData) {
  112. return;
  113. }
  114. this.$refs.submitRef.open(pData, this.type);
  115. },
  116. async dispatch() {
  117. let pData = await this.handleParameter();
  118. if (!pData) {
  119. return;
  120. }
  121. this.$refs.dispatchRef.open(pData, this.type);
  122. },
  123. // 获取详情
  124. async getDetail(id) {
  125. const res = await getSalesDemandById(id);
  126. this.$nextTick(() => {
  127. this.$refs.infoRef.init(res);
  128. });
  129. this.form = res;
  130. },
  131. // 关闭弹窗
  132. handleClose() {
  133. this.addRepairNotesDialog = false;
  134. this.form = {};
  135. this.$refs.infoRef.catch();
  136. },
  137. // 时间格式化
  138. formatDate(dateString) {
  139. const isStandardFormat = /^\d{4}-\d{1,2}-\d{1,2}$/.test(dateString);
  140. if (isStandardFormat) {
  141. return dateString;
  142. }
  143. try {
  144. const date = new Date(dateString);
  145. if (isNaN(date.getTime())) {
  146. throw new Error('Invalid date');
  147. }
  148. const year = date.getFullYear();
  149. const month = String(date.getMonth() + 1).padStart(2, '0');
  150. const day = String(date.getDate()).padStart(2, '0');
  151. return `${year}-${month}-${day}`;
  152. } catch (error) {
  153. return dateString; // 转换失败时返回原始字符串
  154. }
  155. },
  156. // 提取公共参数
  157. async handleParameter() {
  158. let data = this.$refs.infoRef.getValue();
  159. let sparePartsData = (this.$refs.infoRef.getSpareInfoData() || []).map(
  160. (item) => ({
  161. ...item,
  162. typeId: item.typeId,
  163. code: item.code,
  164. name: item.name,
  165. feeType: item.feeType, //费用类别
  166. modelType: item.categoryModel, //型号
  167. specification: item.specification, //规格
  168. content: item.content, //详情内容
  169. totalCount: item.totalCount, //数量
  170. measureUnit: item.measureUnit,
  171. singlePrice: item.singlePrice,
  172. settlementPrice: item.settlementPrice
  173. })
  174. );
  175. console.log(sparePartsData);
  176. if (!data.contactInfoVOS?.length) {
  177. this.$message.warning('联系人信息至少有1条');
  178. return false;
  179. }
  180. if (data.part === 1 && sparePartsData.length === 0) {
  181. this.$message.warning('请添加配件信息');
  182. return false;
  183. }
  184. try {
  185. let valid = await this.$refs.infoRef.getValidate();
  186. let expectedTime = data.expectedTime
  187. ? this.formatDate(data.expectedTime)
  188. : '';
  189. let pData = {
  190. ...this.form,
  191. name: data.name,
  192. faultLevel: data.faultLevel,
  193. expectedTime: expectedTime,
  194. contactId: data.contractInfo.id,
  195. contactCode: data.contractInfo.code,
  196. contactName: data.contractInfo.name,
  197. orderCode: data.orderCode,
  198. orderId: data.orderId,
  199. contactAddress: data.contactAddress,
  200. productDetail: data.tableList.map((item) => {
  201. item['produceTime'] = item['produceTime'] || null;
  202. return item;
  203. }),
  204. contactInfoVOS: data.contactInfoVOS,
  205. associationType: data.associationType,
  206. afterSalesType: data.aftertype,
  207. isFee: data.charge,
  208. isPieCar: data.car,
  209. pieCarType: data.pietype,
  210. isWithAccessories: data.part,
  211. costListVOS: sparePartsData,
  212. formJson: this.$refs.infoRef.carFormData,
  213. isOutsource: data.isOutsource,
  214. isCreatePurchaseOrder: data.isCreatePurchaseOrder,
  215. supplierId: data.supplierId,
  216. supplierName: data.supplierName,
  217. supplierCode: data.supplierCode
  218. };
  219. // 如果选的销售订单并且 没有售后对象数据
  220. if (pData.associationType == '2' && pData.productDetail.length == 0) {
  221. delete pData.productDetail;
  222. pData.faultDetailList = data.faultDetailList;
  223. }
  224. if (pData.associationType == '3' && pData.productDetail.length == 0) {
  225. delete pData.productDetail;
  226. pData.faultDetailList = data.faultDetailList;
  227. }
  228. return pData;
  229. } catch (err) {}
  230. },
  231. // 保存/提交后关闭弹窗
  232. savExit() {
  233. this.$emit('refresh');
  234. this.handleClose();
  235. },
  236. // 保存
  237. async submitAdd() {
  238. try {
  239. let pData = await this.handleParameter();
  240. if (!pData) {
  241. return;
  242. }
  243. this.loading = true;
  244. let requestname =
  245. this.title === '新增' ? saveSalesDemand : updateSalesDemand;
  246. const res = await requestname(pData);
  247. this.loading = false;
  248. if (res) {
  249. this.$message.success('操作成功!');
  250. this.$emit('refresh');
  251. this.handleClose();
  252. }
  253. } catch (error) {
  254. this.loading = false;
  255. }
  256. }
  257. }
  258. };
  259. </script>
  260. <style lang="scss" scoped>
  261. .dialog_top {
  262. margin-bottom: 10px;
  263. display: flex;
  264. align-items: center;
  265. span {
  266. margin-left: 50px;
  267. }
  268. .name {
  269. font-weight: 800;
  270. color: #40a9ff;
  271. }
  272. }
  273. ::v-deep .el-row {
  274. display: flex;
  275. flex-wrap: wrap;
  276. }
  277. .btns {
  278. text-align: right;
  279. }
  280. .main_container {
  281. width: 100%;
  282. display: flex;
  283. justify-content: space-between;
  284. }
  285. </style>