relatedOrders.vue 8.3 KB

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