index.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import { shallowRef, ref, reactive } from 'vue'
  2. import { useDataTable } from '@/hooks/datatable'
  3. import { getTableColumns } from '@/business/table'
  4. import { getReceiptTypeName } from '@/constants/receipt'
  5. import { queryMyPerformance, performanceManualConfirm, performanceDelayApply, performanceContractedApply, performanceModifyContact, queryWrPerformancePlanStep } from '@/services/api/performance'
  6. import { useLoginStore } from '@/stores'
  7. import { BuyOrSell } from '@/constants/order'
  8. import Long from 'long'
  9. // 我的履约
  10. export function usePerformance(buyorsell?: BuyOrSell) {
  11. const { getUserId } = useLoginStore()
  12. const { dataList, total, pageIndex, pageSize, inputList, buttonList, filterMethod, getQueryParam } = useDataTable<Ermcp.MyPerformancRsp>()
  13. const loading = shallowRef(false)
  14. const columns = shallowRef(getTableColumns('order'))
  15. const filterData = ref<{ history: boolean, date: string[] }>({
  16. history: false,
  17. date: []
  18. })
  19. inputList.value = [
  20. { label: '商品', keys: ['goodsno'] },
  21. ]
  22. filterMethod.onReset = () => {
  23. filterData.value = {
  24. history: false,
  25. date: []
  26. }
  27. getPerformanceList()
  28. }
  29. filterMethod.onSearch = () => {
  30. getPerformanceList()
  31. }
  32. const getPerformanceList = () => {
  33. const { history: ishis, date } = filterData.value
  34. const [begindate, enddate] = ishis && Array.isArray(date) ? date : []
  35. const param = getQueryParam()
  36. loading.value = true
  37. return queryMyPerformance({
  38. data: {
  39. userid: getUserId(),
  40. page: pageIndex.value,
  41. pagesize: pageSize.value,
  42. buyorsell,
  43. zsallproperties: param.goodsno,
  44. ishis,
  45. begindate,
  46. enddate,
  47. },
  48. success: (res) => {
  49. total.value = res.total
  50. dataList.value = res.data
  51. },
  52. complete: () => {
  53. loading.value = false
  54. }
  55. })
  56. }
  57. return {
  58. loading,
  59. dataList,
  60. total,
  61. pageIndex,
  62. pageSize,
  63. filterData,
  64. columns,
  65. inputList,
  66. buttonList,
  67. getPerformanceList,
  68. }
  69. }
  70. // 履约手动申请
  71. export function usePerformanceManual(selectedRow: Ermcp.MyPerformancRsp) {
  72. const loading = shallowRef(false)
  73. const formData = reactive<Proto.PerformanceManualConfirmReq>({
  74. PerformancePlanStepID: Long.fromString(selectedRow.curstepid), // uint64 履约计划步骤ID
  75. PerformanceExecuteSide: 1, // uint32 履约步骤执行方 1买方 2 卖方
  76. StepRemark: '',
  77. })
  78. const formSubmit = () => {
  79. loading.value = true
  80. return performanceManualConfirm({
  81. data: formData,
  82. complete: () => {
  83. loading.value = false
  84. }
  85. })
  86. }
  87. return {
  88. loading,
  89. formData,
  90. formSubmit
  91. }
  92. }
  93. // 履约延期申请
  94. export function usePerformanceDelay(selectedRow: Ermcp.MyPerformancRsp) {
  95. const { getUserId } = useLoginStore()
  96. const loading = shallowRef(false)
  97. const formData = reactive<Proto.PerformanceDelayApplyReq>({
  98. PerformancePlanStepID: Long.fromString(selectedRow.curstepid), // uint64 履约计划步骤ID
  99. applicant: getUserId(), // uint64 申请人
  100. })
  101. const formSubmit = () => {
  102. loading.value = true
  103. return performanceDelayApply({
  104. data: formData,
  105. complete: () => {
  106. loading.value = false
  107. }
  108. })
  109. }
  110. return {
  111. loading,
  112. formData,
  113. formSubmit
  114. }
  115. }
  116. // 履约违约申请
  117. export function usePerformanceContracted(selectedRow: Ermcp.MyPerformancRsp) {
  118. const { getUserId, getFirstAccountId } = useLoginStore()
  119. const loading = shallowRef(false)
  120. const formData = reactive<Proto.PerformanceContractedApplyReq>({
  121. PerformancePlanID: Long.fromString(selectedRow.performanceplanid), // uint64 履约计划ID
  122. BreachType: selectedRow.buyaccountid === getFirstAccountId() ? 2 : 1, // uint32 违约方类型
  123. Applicant: getUserId(), // uint64 违约申请人
  124. })
  125. const formSubmit = () => {
  126. loading.value = true
  127. return performanceContractedApply({
  128. data: formData,
  129. complete: () => {
  130. loading.value = false
  131. }
  132. })
  133. }
  134. return {
  135. loading,
  136. formData,
  137. formSubmit
  138. }
  139. }
  140. // 履约修改联络信息
  141. export function usePerformanceModify(selectedRow: Ermcp.MyPerformancRsp) {
  142. const { getFirstAccountId } = useLoginStore()
  143. const loading = shallowRef(false)
  144. const formData = reactive<{ address?: Ermcp.UserReceiveInfoRsp, invoice?: Ermcp.WrUserReceiptInfoRsp, contactInfo?: string }>({})
  145. const formSubmit = () => {
  146. loading.value = true
  147. const jsonParam = {
  148. ContactInfo: formData.contactInfo,
  149. ReceiveInfo: '',
  150. ReceiptInfo: ''
  151. }
  152. if (formData.address) {
  153. const { provincename, cityname, districtname, address } = formData.address
  154. jsonParam.ReceiveInfo = [provincename, cityname, districtname, address].join(' ')
  155. }
  156. if (formData.invoice) {
  157. Object.entries(formData.invoice).forEach(([key, value]) => {
  158. if (value !== '') {
  159. switch (key) {
  160. case 'receipttype': {
  161. jsonParam.ReceiptInfo += '发票类型:' + getReceiptTypeName(Number(value)) + '\n'
  162. break
  163. }
  164. case 'username': {
  165. jsonParam.ReceiptInfo += '户名:' + value + '\n'
  166. break
  167. }
  168. case 'address': {
  169. jsonParam.ReceiptInfo += '地址:' + value + '\n'
  170. break
  171. }
  172. case 'contactinfo': {
  173. jsonParam.ReceiptInfo += '联系方式:' + value + '\n'
  174. break
  175. }
  176. case 'idnum': {
  177. jsonParam.ReceiptInfo += '身份证号码:' + value + '\n'
  178. break
  179. }
  180. case 'receiptaccount': {
  181. jsonParam.ReceiptInfo += '发票帐号:' + value + '\n'
  182. break
  183. }
  184. case 'receiptbank': {
  185. jsonParam.ReceiptInfo += '发票开户行:' + value + '\n'
  186. break
  187. }
  188. case 'taxpayerid': {
  189. jsonParam.ReceiptInfo += '纳税人识别号:' + value + '\n'
  190. break
  191. }
  192. }
  193. }
  194. })
  195. }
  196. return performanceModifyContact({
  197. data: {
  198. PerformancePlanID: Long.fromString(selectedRow.performanceplanid), // uint64 履约计划ID
  199. AccountID: getFirstAccountId(), // uint64 账号
  200. ContactInfo: JSON.stringify(jsonParam), // string 联络信息
  201. },
  202. complete: () => {
  203. loading.value = false
  204. }
  205. })
  206. }
  207. return {
  208. loading,
  209. formData,
  210. formSubmit
  211. }
  212. }
  213. // 履约计划步骤
  214. export function usePerformancePlanStep(planid: string) {
  215. const { dataList } = useDataTable<Ermcp.WrPerformancePlanStepRsp>()
  216. const loading = shallowRef(false)
  217. const columns = shallowRef(getTableColumns('order_step'))
  218. const getPlanStepList = () => {
  219. loading.value = true
  220. return queryWrPerformancePlanStep({
  221. data: {
  222. planid,
  223. },
  224. success: (res) => {
  225. dataList.value = res.data
  226. },
  227. complete: () => {
  228. loading.value = false
  229. }
  230. })
  231. }
  232. return {
  233. loading,
  234. dataList,
  235. columns,
  236. getPlanStepList,
  237. }
  238. }