addDialog.vue 8.5 KB

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