setOneEntrustDialog.vue 11 KB

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