addDialog.vue 7.1 KB

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