addDialog.vue 7.5 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 type="primary" @click="submitAdd" v-if="type != 'view'"
  19. >保存</el-button
  20. >
  21. <el-button type="primary" @click="submit" v-if="type != 'view'"
  22. >提交</el-button
  23. >
  24. <el-button type="primary" @click="dispatch" v-if="type != 'view'"
  25. >派单</el-button
  26. >
  27. <el-button @click="handleClose">返回</el-button>
  28. </div>
  29. </ele-modal>
  30. </template>
  31. <script>
  32. import { mapGetters, mapActions } from 'vuex';
  33. import modalTitle from '@/BIZComponents/modalTitle.vue';
  34. import customerDialog from '@/views/financialManage/components/customerListDialog.vue';
  35. import SubmitDialog from './submitDialog.vue';
  36. import dispatchDialog from './dispatchDialog.vue';
  37. import { getByCode } from '@/api/system/dictionary-data';
  38. import {
  39. saveSalesDemand,
  40. updateSalesDemand,
  41. getSalesDemandById
  42. } from '@/api/salesServiceManagement/index';
  43. // import fileMain from '@/components/addDoc/index.vue';
  44. import info from '@/views/salesServiceManagement/components/info.vue';
  45. export default {
  46. components: {
  47. modalTitle,
  48. customerDialog,
  49. // fileMain,
  50. info,
  51. SubmitDialog,
  52. dispatchDialog
  53. },
  54. watch: {},
  55. computed: {
  56. ...mapGetters(['getDictValue'])
  57. },
  58. data() {
  59. return {
  60. title: '新增',
  61. addRepairNotesDialog: false,
  62. type: 'add',
  63. form: {},
  64. demandList: []
  65. };
  66. },
  67. created() {
  68. this.getLevelCode('requirement_name');
  69. },
  70. methods: {
  71. // 初始化数据(父组件调用)
  72. init(row, type) {
  73. this.addRepairNotesDialog = true;
  74. this.type = type;
  75. this.title = type == 'add' ? '新增' : type == 'view' ? '详情' : '修改';
  76. if (row?.id) {
  77. this.getDetail(row.id);
  78. } else {
  79. }
  80. },
  81. //
  82. async getLevelCode(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. // 提交
  101. async submit() {
  102. let pData = await this.handleParameter();
  103. if (!pData) {
  104. return;
  105. }
  106. this.$refs.submitRef.open(pData, this.type);
  107. },
  108. // 派单
  109. async dispatch() {
  110. let pData = await this.handleParameter();
  111. if (!pData) {
  112. return;
  113. }
  114. this.$refs.dispatchRef.open(pData, this.type);
  115. },
  116. async getDetail(id) {
  117. const res = await getSalesDemandById(id);
  118. this.$nextTick(() => {
  119. this.$refs.infoRef.init(res);
  120. });
  121. this.form = res;
  122. },
  123. handleClose() {
  124. this.addRepairNotesDialog = false;
  125. this.form = {};
  126. this.$refs.infoRef.catch();
  127. },
  128. // 标准时间函数 ***
  129. formatDate(dateString) {
  130. const isStandardFormat = /^\d{4}-\d{1,2}-\d{1,2}$/.test(dateString);
  131. if (isStandardFormat) {
  132. return dateString;
  133. }
  134. try {
  135. const date = new Date(dateString);
  136. if (isNaN(date.getTime())) {
  137. throw new Error('Invalid date');
  138. }
  139. const year = date.getFullYear();
  140. const month = String(date.getMonth() + 1).padStart(2, '0');
  141. const day = String(date.getDate()).padStart(2, '0');
  142. return `${year}-${month}-${day}`;
  143. } catch (error) {
  144. return dateString; // 转换失败时返回原始字符串
  145. }
  146. },
  147. // 提取公共 参数
  148. async handleParameter() {
  149. let data = this.$refs.infoRef.getValue();
  150. if (!data.contactInfoVOS?.length) {
  151. this.$message.warning('联系人信息至少有1条');
  152. return false;
  153. }
  154. try {
  155. let valid = await this.$refs.infoRef.getValidate();
  156. let expectedTime = data.expectedTime
  157. ? this.formatDate(data.expectedTime)
  158. : '';
  159. let pData = {
  160. ...this.form,
  161. name: data.name,
  162. faultLevel: data.faultLevel,
  163. expectedTime: expectedTime,
  164. contactId: data.contractInfo.id,
  165. contactCode: data.contractInfo.code,
  166. contactName: data.contractInfo.name,
  167. orderCode: data.orderCode,
  168. orderId: data.orderId,
  169. contactAddress: data.contactAddress,
  170. productDetail: data.tableList.map((item) => {
  171. item['produceTime'] = item['produceTime'] || null;
  172. return item;
  173. }),
  174. contactInfoVOS: data.contactInfoVOS
  175. };
  176. return pData;
  177. } catch (err) {}
  178. },
  179. savExit() {
  180. this.$emit('refresh');
  181. this.handleClose();
  182. },
  183. // 保存
  184. async submitAdd() {
  185. // let data = this.$refs.infoRef.getValue();
  186. // if (!data.contactInfoVOS?.length) {
  187. // this.$message.warning('联系人信息至少有1条');
  188. // return;
  189. // }
  190. try {
  191. let pData = await this.handleParameter();
  192. if (!pData) {
  193. return;
  194. }
  195. // let valid = await this.$refs.infoRef.getValidate();
  196. // let expectedTime = data.expectedTime
  197. // ? this.formatDate(data.expectedTime)
  198. // : '';
  199. // let pData = {
  200. // ...this.form,
  201. // name: data.name,
  202. // faultLevel: data.faultLevel,
  203. // expectedTime: expectedTime,
  204. // contactId: data.contractInfo.id,
  205. // contactCode: data.contractInfo.code,
  206. // contactName: data.contractInfo.name,
  207. // orderCode: data.orderCode,
  208. // orderId: data.orderId,
  209. // contactAddress: data.contactAddress,
  210. // productDetail: data.tableList.map((item) => {
  211. // item['produceTime'] = item['produceTime'] || null;
  212. // return item;
  213. // }),
  214. // contactInfoVOS: data.contactInfoVOS
  215. // };
  216. let requestname =
  217. this.title === '新增' ? saveSalesDemand : updateSalesDemand;
  218. const res = await requestname(pData);
  219. if (res) {
  220. this.$message.success('操作成功!');
  221. this.$emit('refresh');
  222. this.handleClose();
  223. }
  224. } catch (error) {}
  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>