relatedOrders.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="relatedTasks pl-4 pr-4 pt-3 pb-3 h-full flex flex-col">
  3. <div class="flex justify-between">
  4. <div class="title">相关销售订单</div>
  5. <div v-permission="['orderAdd']">
  6. <el-button type="primary" @click="editOrder()">新建销售订单</el-button>
  7. </div>
  8. </div>
  9. <div class="flex-1 overflow-auto pt-3">
  10. <el-table :data="relatedOrders" border style="width: 100%;height: 300px;">
  11. <el-table-column prop="orderCode" label="订单编号" width="130" />
  12. <el-table-column prop="orderName" label="订单名称" min-width="200">
  13. <template #default="scope">
  14. <el-button link type="primary" size="large">{{
  15. scope.row.orderName
  16. }}</el-button>
  17. </template>
  18. </el-table-column>
  19. <el-table-column prop="customName" label="客户名称" width="130" />
  20. <el-table-column prop="price" label="订单金额(¥)" width="130" />
  21. <el-table-column prop="receivedPayment" label="已回款(¥)" width="130" />
  22. <el-table-column prop="unReceivedPayment" label="未回款(¥)" width="130" />
  23. <el-table-column prop="typeName" label="订单类型" width="130" />
  24. <el-table-column prop="placeTime" label="下单时间" width="200" />
  25. <el-table-column prop="inchargerName" label="负责人" width="130" />
  26. <el-table-column prop="creatorName" label="创建人" width="130" />
  27. <el-table-column prop="createTime" label="创建时间" width="200" />
  28. </el-table>
  29. </div>
  30. <!-- 弹窗 -->
  31. <el-dialog v-model="allVisible.editOrderVisible" width="1000" :show-close="false" top="10vh">
  32. <template #header="{ close, titleId, titleClass }">
  33. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  34. <h4 :id="titleId">{{ '新建销售订单' }}</h4>
  35. <div>
  36. <el-button type="primary" :loading="allLoading.editSaveLading"
  37. @click="saveOrder(false)">保存</el-button>
  38. <el-button @click="closeVisible('editOrderVisible')">取消</el-button>
  39. </div>
  40. </div>
  41. </template>
  42. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3" v-loading="allLoading.orderTemplateLoadinng">
  43. <GenerateForm ref="orderTemplateRef" :data="orderTemplate" :key="orderTemplateKey"
  44. :value="orderTemplateValue" />
  45. <div>相关产品</div>
  46. <RelatedProducts ref="relatedProductsRef" :productTableList="productTableList"
  47. :productTableListValue="productTableListValue" />
  48. </div>
  49. </el-dialog>
  50. </div>
  51. </template>
  52. <script lang="ts" setup>
  53. import { ref, reactive, onMounted, onUnmounted, defineExpose, inject, watchEffect } from 'vue'
  54. import { setTemplateDataDisable } from '@/utils/tools';
  55. import { GenerateForm } from '@zmjs/form-design';
  56. import { get, post } from '@/utils/request';
  57. import RelatedProducts from '@/components/relatedProducts/relatedProducts.vue'
  58. import { GETGENERATEFOEM, GETTABLELIST, URL_OEDERUPDATE } from '@/pages/order/api';
  59. import { formatDate } from '@/utils/times';
  60. const emits = defineEmits(['refreshData']);
  61. const globalPopup = inject<GlobalPopup>('globalPopup')
  62. const props = defineProps<{
  63. data: any
  64. }>()
  65. const information = ref<any>({})
  66. const relatedOrders = ref([])
  67. const productTableList = ref([])
  68. const productTableListValue = ref([])
  69. const orderTemplateValue = ref({})
  70. const orderTemplateKey = ref(1)
  71. const orderTemplateRef = ref<typeof GenerateForm>()
  72. const relatedProductsRef = ref<typeof RelatedProducts>()
  73. const orderTemplate = ref({
  74. list: [],
  75. config: {}
  76. })
  77. const allVisible = reactive({
  78. editOrderVisible: false,
  79. })
  80. const allLoading = reactive({
  81. editSaveLading: false,
  82. orderTemplateLoadinng: false,
  83. })
  84. function saveOrder(flag: boolean) {
  85. orderTemplateRef.value?.getData().then((res: any) => {
  86. let productTableListData = relatedProductsRef?.value?.returnData()
  87. for (var i in productTableListData) {
  88. productTableListData[i].sealPrice = productTableListData[i].sellingPrice,
  89. productTableListData[i].discount = productTableListData[i].discount,
  90. productTableListData[i].num = productTableListData[i].quantity
  91. }
  92. const produt = productTableListData ? JSON.stringify(productTableListData) : []
  93. allLoading.editSaveLading = true
  94. post(URL_OEDERUPDATE, {
  95. ...orderTemplateValue.value,
  96. ...res,
  97. orderEndDate: res.orderEndDate ? formatDate(res.orderEndDate) : '',
  98. orderStartDate: res.orderStartDate ? formatDate(res.orderStartDate) : '',
  99. placeTime: res.placeTime ? formatDate(res.placeTime) : '',
  100. orderProductDetailString: produt
  101. }).then((_res) => {
  102. allVisible.editOrderVisible = flag
  103. globalPopup?.showSuccess('操作成功')
  104. if (flag) {
  105. orderTemplateRef.value?.reset()
  106. }
  107. emits('refreshData')
  108. }).finally(() => {
  109. allLoading.editSaveLading = false
  110. })
  111. }).catch((_err: any) => {
  112. globalPopup?.showError('请填写完整')
  113. })
  114. }
  115. function editOrder() {
  116. showVisible('editOrderVisible')
  117. allLoading.orderTemplateLoadinng = true
  118. orderTemplateValue.value = { customId: information.value.id }
  119. productTableListValue.value = []
  120. setTimeout(() => {
  121. orderTemplateRef.value && orderTemplateRef.value.reset()
  122. orderTemplateKey.value++
  123. allLoading.orderTemplateLoadinng = false
  124. }, 1000)
  125. }
  126. async function getSystemField() {
  127. const datas = await get(GETGENERATEFOEM)
  128. let newConfig = JSON.parse(datas.data[0].config)
  129. newConfig.list = setTemplateDataDisable(newConfig.list, ['customId'])
  130. orderTemplate.value = newConfig
  131. }
  132. function showVisible(type: keyof typeof allVisible) {
  133. allVisible[type] = true
  134. }
  135. function closeVisible(type: keyof typeof allVisible) {
  136. allVisible[type] = false
  137. }
  138. function getProductTableList() {
  139. post(GETTABLELIST, { pageIndex: -1, pageSize: -1 }).then((res) => {
  140. if (res.code == 'ok') {
  141. const { record, total } = res.data
  142. productTableList.value = record.map((item: any) => {
  143. const { id, productName, productCode, unit, unitName, typeName, type, price, inventory } = item
  144. return {
  145. id,
  146. productId: id,
  147. productName,
  148. productCode,
  149. unit,
  150. unitName,
  151. price,
  152. type,
  153. typeName,
  154. inventory,
  155. quantity: '',
  156. discount: '',
  157. totalPrice: ''
  158. }
  159. })
  160. }
  161. })
  162. }
  163. watchEffect(() => {
  164. const { data } = props
  165. information.value = data
  166. relatedOrders.value = (data.salesOrders || [])
  167. })
  168. // 生命周期钩子
  169. onMounted(() => {
  170. getProductTableList()
  171. getSystemField()
  172. });
  173. </script>
  174. <style scoped lang="scss">
  175. .relatedTasks {
  176. .title {
  177. font-size: 18px;
  178. color: #000
  179. }
  180. }
  181. </style>