procure-setting.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <script setup lang="ts">
  2. import { computed, reactive, ref, watch, shallowRef, nextTick } from "vue";
  3. import { cost_rules } from "./../supplyCommodityCost/config/configs";
  4. import RemoteSelect from "/@/components/RemoteSelect";
  5. import { useResponseHandle } from "/@/hooks";
  6. import { useRoute } from "vue-router";
  7. import { ElForm } from "element-plus";
  8. import { httpCatlist, httpAdd } from "/@/api/InvoiceSaleSettings/commodityCost";
  9. import QueryCategory from "./query-category.vue"
  10. import { type DescriptionColumn } from "/@/components/BasicDescriptions";
  11. const remoteSelectRef = ref<any>(null);
  12. const emit = defineEmits(["refresh"]);
  13. const props = defineProps<{
  14. columns: Array<DescriptionColumn>;
  15. backRoute: string;
  16. name?: string;
  17. detail: any;
  18. }>();
  19. const initalFormData = {
  20. inv_good_name: "", // 开票商品名称
  21. cat_name: "",
  22. cat_code: "",
  23. tax: ""
  24. };
  25. const taxs = ref<Array<string>>([]);
  26. const { query } = useRoute();
  27. const responseHandle = useResponseHandle();
  28. const formRef = ref<InstanceType<typeof ElForm>>(null);
  29. const spuCode = computed(() => query.id as string);
  30. const formData = reactive({ ...initalFormData });
  31. const loading = shallowRef(false);
  32. //禁用字段
  33. const disabledField = computed(() => {
  34. const isDisabledTaxField = !formData.cat_code;
  35. return {
  36. tax: isDisabledTaxField
  37. };
  38. });
  39. //动态验证规则
  40. const dynamicRules = computed(() => {
  41. return { ...cost_rules};
  42. });
  43. function handleRelatedCategories() {
  44. formRef.value.validate(async isValid => {
  45. if (!isValid) return;
  46. const { cat_code, inv_good_name, tax } = formData;
  47. const list = [{ cat_code, inv_good_name, tax, spuCode: spuCode.value }]
  48. loading.value = true;
  49. const { code, message } = await httpAdd({ list, status:"1" });
  50. loading.value = false;
  51. responseHandle({
  52. code,
  53. message,
  54. handler: () => emit("refresh")
  55. });
  56. });
  57. }
  58. function handleSelectCategory(category, isInit) {
  59. if (!category) {
  60. formData.tax = "";
  61. formData.cat_name = "";
  62. return (taxs.value = []);
  63. }
  64. const { tax, label } = category;
  65. taxs.value = [...tax, "0%"];
  66. if(!isInit){
  67. formData.cat_name = label;
  68. formData.tax = "";
  69. }
  70. }
  71. watch(
  72. () => props.detail,
  73. async () => {
  74. if (!props.detail) return;
  75. const { inv_good_name, inv_cat_code, good_name, inv_tax, cgd_inv_tax, cgd_inv_cat_code } = props.detail;
  76. formData.inv_good_name = inv_good_name ? inv_good_name : good_name;
  77. formData.tax = inv_tax ? inv_tax * 100 + "%" : "";
  78. if (formData.inv_good_name.length > 70) {
  79. formData.inv_good_name = formData.inv_good_name.slice(0, 70);
  80. }
  81. if (cgd_inv_tax) {
  82. formData.tax = cgd_inv_tax;
  83. }
  84. nextTick(async () => {
  85. if (inv_cat_code && remoteSelectRef.value && inv_cat_code.trim().length !== 0) {
  86. const params = { cat_code: inv_cat_code };
  87. const result = await remoteSelectRef.value.initalData(params);
  88. if (!result || !Array.isArray(result)) return;
  89. const { tax } = result[0];
  90. taxs.value = [...tax, '0%','1%','3%'];
  91. } else if (cgd_inv_cat_code && remoteSelectRef.value && cgd_inv_cat_code.trim().length !== 0) {
  92. const params = { cat_code: cgd_inv_cat_code };
  93. const result = await remoteSelectRef.value.initalData(params);
  94. if (!result || !Array.isArray(result)) return;
  95. const { tax } = result[0];
  96. taxs.value = [...tax, '0%','1%','3%'];
  97. }
  98. })
  99. },
  100. {
  101. immediate: true
  102. }
  103. );
  104. </script>
  105. <template>
  106. <el-form
  107. label-position="left"
  108. ref="formRef"
  109. :rules="dynamicRules"
  110. :model="formData"
  111. >
  112. <div flex gap="1">
  113. <el-form-item label="商品类目设置" prop="cat_code" flex-1>
  114. <!-- <RemoteSelect
  115. ref="remoteSelectRef"
  116. w-full
  117. is-root
  118. :api="httpCatlist"
  119. v-model="formData.cat_code"
  120. placeholder="请选择商品类目"
  121. response-label-prop="cat_name"
  122. response-val-prop="merge_code"
  123. request-prop="cat_name"
  124. sub-label-prop="short_name"
  125. @item-change="handleSelectCategory"
  126. @inital="code => (formData.cat_code = code)"
  127. /> -->
  128. <QueryCategory
  129. ref="remoteSelectRef"
  130. v-model="formData.cat_code"
  131. @change="handleSelectCategory"
  132. />
  133. </el-form-item>
  134. <el-form-item label="开票商品名称" prop="inv_good_name" flex-1>
  135. <el-input
  136. w-full
  137. v-model="formData.inv_good_name"
  138. placeholder="请输入商品名称"
  139. maxlength="70"
  140. />
  141. </el-form-item>
  142. </div>
  143. <div flex gap-3>
  144. <el-form-item label="税率" prop="tax">
  145. <el-select
  146. w-180px
  147. v-model="formData.tax"
  148. :disabled="disabledField.tax"
  149. placeholder="请输入税率"
  150. >
  151. <el-option
  152. v-for="(t, index) in taxs"
  153. :key="index"
  154. :label="t"
  155. :value="t"
  156. />
  157. </el-select>
  158. </el-form-item>
  159. </div>
  160. </el-form>
  161. <div flex justify-end>
  162. <el-button type="primary" @click="handleRelatedCategories" :loading="loading">保存</el-button>
  163. </div>
  164. </template>
  165. <style lang="scss" scoped>
  166. .settings__content {
  167. padding: 20px !important;
  168. }
  169. </style>