setOneEntrustDialog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <el-dialog
  3. title="单次委托"
  4. v-model="formOpen"
  5. width="800px"
  6. append-to-body
  7. draggable
  8. @close="cancel"
  9. >
  10. <el-form ref="dictRef" :model="form" label-width="100">
  11. <el-form-item label="客户:"> {{ company.name }} </el-form-item>
  12. <el-form-item label="税号:">
  13. {{ company.socialCreditCode }}
  14. </el-form-item>
  15. <el-form-item>
  16. <el-checkbox-group v-model="onces" @change="changeDetails">
  17. <el-checkbox
  18. v-for="(item, index) in onceTasks"
  19. :key="index"
  20. :label="item.id"
  21. >{{ item.name }}</el-checkbox
  22. >
  23. </el-checkbox-group>
  24. <el-col :span="24">
  25. <el-row
  26. v-for="(item, index) in onceDetails"
  27. :key="index"
  28. style="
  29. border-radius: 5px;
  30. border-color: rgba(0, 0, 0, 20%);
  31. border-style: solid;
  32. border-width: 1px;
  33. margin-bottom: 10px;
  34. "
  35. >
  36. <el-col :span="10" style="padding-top: 18px">
  37. <el-form-item label="服务项目">
  38. {{ item.taskTypeName }}
  39. </el-form-item>
  40. </el-col>
  41. <el-col
  42. v-if="item.payAddress === 0"
  43. :span="9"
  44. style="
  45. padding-top: 18px;
  46. display: flex;
  47. flex-direction: column;
  48. margin-bottom: 18px;
  49. "
  50. >
  51. <el-form-item v-if="item.taskTypeId === '6'" label="变更类型">
  52. <el-select v-model="item.alterType" style="width: 280px">
  53. <el-option
  54. v-for="alter in alterTypes"
  55. :label="alter.label"
  56. :key="alter.value"
  57. :value="alter.value"
  58. >
  59. </el-option>
  60. </el-select>
  61. </el-form-item>
  62. <div
  63. v-if="item.alterType === '跨区变更'"
  64. style="margin-left: 60px"
  65. ></div>
  66. </el-col>
  67. <el-col
  68. :span="24"
  69. style="padding-top: 5px; padding-left: 33px; margin-bottom: 0px"
  70. >
  71. <el-checkbox-group
  72. v-model="item.processes"
  73. @change="(arg) => changeProcesses(item, arg)"
  74. style="display: block; flex-direction: row"
  75. >
  76. <el-checkbox
  77. v-for="(process, index) in item.defaultProcesses"
  78. :key="index"
  79. :label="process"
  80. >
  81. <template #default>
  82. <div
  83. style="
  84. display: block;
  85. flex-direction: row;
  86. width: 45px;
  87. justify-content: space-between;
  88. "
  89. >
  90. <div
  91. style="
  92. display: inline-block;
  93. height: 24px;
  94. line-height: 24px;
  95. margin-right: 10px;
  96. width: 80px;
  97. "
  98. >
  99. {{ process.taskTypeDetailName }}
  100. </div>
  101. </div>
  102. </template>
  103. </el-checkbox>
  104. </el-checkbox-group>
  105. </el-col>
  106. </el-row>
  107. </el-col>
  108. </el-form-item>
  109. </el-form>
  110. <template #footer>
  111. <div class="dialog-footer">
  112. <el-button
  113. type="primary"
  114. icon="Finished"
  115. size="small"
  116. @click="submitForm"
  117. >确 定</el-button
  118. >
  119. <el-button @click="cancel" icon="close" size="small">取 消</el-button>
  120. </div>
  121. </template>
  122. </el-dialog>
  123. </template>
  124. <script setup>
  125. import {
  126. addEntrust,
  127. getFactories,
  128. } from "@/api/business/entrust/currentWorkOrder";
  129. import { initTaskTypes } from "@/api/business/crm/contract";
  130. import { rowNum } from "@/utils/index";
  131. import { ref } from "vue";
  132. import { setOneEntrust } from "@/api/business/standardCompany";
  133. import { set } from "@vueuse/core";
  134. // import { fa } from "element-plus/es/locale";
  135. const { proxy } = getCurrentInstance();
  136. const loopTasks = ref([]);
  137. const onces = ref([]);
  138. const onceTasks = ref([]);
  139. const factories = ref([]);
  140. const emit = defineEmits(["choice"]);
  141. const loops = ref([]);
  142. const provinces = ref(proxy.region.getProvinces());
  143. provinces.value.unshift({ code: "", name: "全部" });
  144. const cities = ref([]);
  145. const districts = ref([]);
  146. const toTenantId = ref(null);
  147. const alterTypes = ref([
  148. {
  149. value: "普通变更",
  150. label: "普通变更",
  151. },
  152. {
  153. value: "股权变更",
  154. label: "股权变更",
  155. },
  156. {
  157. value: "减资",
  158. label: "减资",
  159. },
  160. {
  161. value: "跨区变更",
  162. label: "跨区变更",
  163. },
  164. ]);
  165. //地址数组
  166. const provincesArr = ref([]);
  167. const citiesArr = ref([]);
  168. const districtsArr = ref([]);
  169. // 单次任务明细
  170. const onceDetails = ref([]);
  171. const detailEmpty = {
  172. id: null,
  173. taskTypeName: "",
  174. taskTypeId: null,
  175. serviceNum: undefined,
  176. freeNum: undefined,
  177. price: undefined,
  178. amount: undefined,
  179. addressStyle: undefined,
  180. address: undefined,
  181. fictionAddressId: undefined,
  182. tenantId: undefined,
  183. province: "",
  184. city: "",
  185. district: "",
  186. addressStyle: 1,
  187. provinceId: undefined,
  188. processes: [],
  189. defaultProcesses: [],
  190. };
  191. const list = ref([]);
  192. const props = defineProps({
  193. getList: {
  194. type: Function,
  195. default: () => {},
  196. },
  197. });
  198. const { getList } = toRefs(props);
  199. const startMonth = ref(proxy.moment().format("YYYY-MM-01"));
  200. const formOpen = ref(false);
  201. const company = ref({});
  202. const form = ref({});
  203. const rules = ref({});
  204. const content = ref("请输入员工姓名");
  205. const ids = ref([]);
  206. function submitForm() {
  207. const formValue = form.value;
  208. formValue.details = onceDetails.value;
  209. formValue.formDate = proxy.moment().format("YYYY-MM-DD");
  210. formValue.companyId = company.value.id;
  211. formValue.companyName = company.value.name;
  212. formValue.socialCreditCode = company.value.socialCreditCode;
  213. if (onceDetails.value.length == 0) {
  214. proxy.$modal.msgError("请选择服务项目");
  215. } else {
  216. setOneEntrust(formValue).then((response) => {
  217. proxy.$modal.msgSuccess("保存成功!");
  218. formOpen.value = false;
  219. getList.value();
  220. });
  221. }
  222. }
  223. function checkedProcess(processId, item) {
  224. const processes = item.processes;
  225. return processes.findIndex((v) => v.taskTypeDetailId == processId) < 0;
  226. }
  227. function changeProcesses(item) {
  228. computedItem(item);
  229. computedService();
  230. }
  231. function computedItem(parent) {
  232. let amount = 0;
  233. amount +=
  234. parent.payAddress === 1 && parent.addressStyle === 2 && parent.addressAmount
  235. ? Number(parent.addressAmount)
  236. : 0;
  237. amount +=
  238. parent.taskTypeId === "6" &&
  239. parent.alterType === "跨区变更" &&
  240. parent.addressStyle === 2 &&
  241. parent.addressAmount
  242. ? Number(parent.addressAmount)
  243. : 0;
  244. parent.processes.forEach((l) => {
  245. amount += l.amount ? Number(l.amount) : 0;
  246. });
  247. parent.amount = amount;
  248. }
  249. function inputChangeHandler(type, field, item, value, parent) {
  250. let amount = 0;
  251. switch (type) {
  252. case "loop":
  253. switch (field) {
  254. case "price":
  255. amount =
  256. (item.serviceNum ? Number(item.serviceNum) : 0) *
  257. (value ? Number(value) : 0);
  258. item.amount = amount;
  259. break;
  260. case "serviceNum":
  261. amount =
  262. (item.price ? Number(item.price) : 0) * (value ? Number(value) : 0);
  263. item.amount = amount;
  264. break;
  265. case "freeNum":
  266. amount =
  267. (item.price ? Number(item.price) : 0) *
  268. (item.serviceNum ? Number(item.serviceNum) : 0);
  269. item.amount = amount;
  270. break;
  271. }
  272. break;
  273. case "once":
  274. computedItem(item);
  275. break;
  276. case "process":
  277. computedItem(parent);
  278. break;
  279. default:
  280. break;
  281. }
  282. computedService();
  283. }
  284. function computedService() {
  285. let amount = 0;
  286. onceDetails.value.forEach((l) => {
  287. amount +=
  288. l.payAddress === 1 && l.addressStyle === 2 && l.addressAmount
  289. ? Number(l.addressAmount)
  290. : 0;
  291. l.processes.forEach((v) => {
  292. amount += v.amount ? Number(v.amount) : 0;
  293. });
  294. });
  295. form.value.amount = amount;
  296. form.value.trueAmount =
  297. amount -
  298. (form.value.discountAmount ? Number(form.value.discountAmount) : 0);
  299. }
  300. function cancel() {
  301. formOpen.value = false;
  302. reset();
  303. }
  304. function open(options) {
  305. company.value = options;
  306. initTaskTypes().then((res) => {
  307. onceTasks.value = res.data.onceTasks;
  308. });
  309. formOpen.value = true;
  310. }
  311. function handleSelectDistrict(item, index) {
  312. const _districtCode = item.districtCode;
  313. const _district = districtsArr.value[index].find((i) => {
  314. return i.code === _districtCode;
  315. });
  316. item.district = _district.name;
  317. }
  318. function delWorkOrderHandler(index) {
  319. proxy.$modal.confirm("是否确认删除选中的数据项?").then(() => {
  320. list.value.splice(index, 1);
  321. });
  322. }
  323. function reset() {
  324. list.value = [];
  325. startMonth.value = proxy.moment().format("YYYY-MM-01");
  326. toTenantId.value = null;
  327. }
  328. function changeDetails() {
  329. onces.value.forEach((e) => {
  330. const taskType = onceTasks.value.find((v) => v.id == e);
  331. if (onceDetails.value.findIndex((v) => v.taskTypeId == e) < 0) {
  332. const newDetail = JSON.parse(JSON.stringify(detailEmpty));
  333. newDetail.taskTypeId = e;
  334. newDetail.taskTypeName = taskType.name;
  335. newDetail.payAddress = taskType.payAddress;
  336. (newDetail.alterType = e === "6" ? "普通变更" : ""),
  337. (newDetail.defaultProcesses = taskType.processes.map((v) => ({
  338. taskTypeId: e,
  339. taskTypeDetailId: v.id,
  340. taskTypeDetailName: v.name,
  341. fictionAddressId: null,
  342. fictionAddress: "",
  343. addressStyle: 0,
  344. checked: false,
  345. amount: undefined,
  346. })));
  347. newDetail.processes = [];
  348. onceDetails.value.push(newDetail);
  349. }
  350. });
  351. onceDetails.value = onceDetails.value.filter(
  352. (v) => onces.value.findIndex((e) => e == v.taskTypeId) > -1
  353. );
  354. let provincesLength = provincesArr.value.length;
  355. if (onceDetails.value.length > provincesLength) {
  356. for (let i = 0; i < onceDetails.value.length - provincesLength; i++) {
  357. provincesArr.value.push(provinces.value);
  358. citiesArr.value.push(cities.value);
  359. districtsArr.value.push(districts.value);
  360. }
  361. } else if (onceDetails.value.length < provincesLength) {
  362. for (let i = 0; i < provincesLength - onceDetails.value.length; i++) {
  363. provincesArr.value.length--;
  364. citiesArr.value.length--;
  365. districtsArr.value.length--;
  366. }
  367. }
  368. }
  369. function initFactories() {
  370. getFactories().then((res) => {
  371. factories.value = res.data;
  372. });
  373. }
  374. initFactories();
  375. // 暴露给父组件的方法
  376. defineExpose({
  377. open,
  378. cancel,
  379. });
  380. </script>