addEditor.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div class="w-full h-full flex flex-col">
  3. <div class="flex-1 overflow-y-auto">
  4. <van-form ref="vanFormRef" show-error :show-error-message="false" label-align="left" input-align="right"
  5. class="bg-white" @submit="onSubmit">
  6. <van-field v-model.trim="vantFormVal.taskName" name="taskName" rows="2" label="任务名称" maxlength="100" required
  7. show-word-limit type="textarea" placeholder="请输入" />
  8. <van-field v-model="vantFormVal.priority" name="priority" label="优先级" placeholder="请选择" is-link readonly
  9. required @click="showSelectionBox('priority', fixedFieldPriority)">
  10. <template #input v-if="vantFormVal.priority || vantFormVal.priority == 0">
  11. {{ vantFormVal.priorityName }}
  12. </template>
  13. </van-field>
  14. <van-field v-model="vantFormVal.taskType" name="taskType" label="任务类型" placeholder="请选择" is-link readonly
  15. @click="showSelectionBox('taskType', fixedFieldTaskType)" class="resetStyles">
  16. <template #input v-if="vantFormVal.taskType || vantFormVal.taskType == 0">
  17. {{ vantFormVal.taskTypeName }}
  18. </template>
  19. </van-field>
  20. <!-- 客户选择 -->
  21. <template v-if="vantFormVal.taskType == 0">
  22. <van-field v-model="vantFormVal.customId" name="customId" label="客户" placeholder="请选择" is-link readonly
  23. @click="showSelectionBox('customId', allCustomersList)" class="resetStyles">
  24. <template #input v-if="vantFormVal.customId">
  25. {{ vantFormVal.customIdName }}
  26. </template>
  27. </van-field>
  28. </template>
  29. <!-- 商机选择 -->
  30. <template v-if="vantFormVal.taskType == 1">
  31. <van-field v-model="vantFormVal.businessOpportunityId" name="businessOpportunityId" label="商机"
  32. placeholder="请选择" is-link readonly class="resetStyles"
  33. @click="showSelectionBox('businessOpportunityId', allBusinessOpportunities)">
  34. <template #input v-if="vantFormVal.businessOpportunityId">
  35. {{ vantFormVal.businessOpportunityIdName }}
  36. </template>
  37. </van-field>
  38. </template>
  39. <!-- 销售订单选择 -->
  40. <template v-if="vantFormVal.taskType == 2">
  41. <van-field v-model="vantFormVal.orderId" name="orderId" label="销售订单" placeholder="请选择" is-link readonly
  42. class="resetStyles" @click="showSelectionBox('orderId', allSalesOrdersList)">
  43. <template #input v-if="vantFormVal.orderId">
  44. {{ vantFormVal.orderIdName }}
  45. </template>
  46. </van-field>
  47. </template>
  48. <!-- 线索选择 -->
  49. <template v-if="vantFormVal.taskType == 3">
  50. <van-field v-model="vantFormVal.clueId" name="clueId" label="线索" placeholder="请选择" is-link readonly
  51. class="resetStyles" @click="showSelectionBox('clueId', allCluesList)">
  52. <template #input v-if="vantFormVal.clueId">
  53. {{ vantFormVal.clueIdName }}
  54. </template>
  55. </van-field>
  56. </template>
  57. <van-field v-model="vantFormVal.contactsId" name="contactsId" label="联系人" placeholder="请选择" is-link readonly
  58. :disabled="contactDisabled"
  59. v-if="fixedFieldTaskType.find(v => v.value == (vantFormVal.taskType || '1'))?.show" class="resetStyles"
  60. @click="showSelectionBox('contactsId', allContactsList)">
  61. <template #input v-if="vantFormVal.contactsId">
  62. {{ vantFormVal.contactsIdName }}
  63. </template>
  64. </van-field>
  65. <van-field v-model="vantFormVal.executorId" name="executorId" label="执行人" placeholder="请选择" is-link readonly
  66. class="resetStyles" @click="showSelectionToBox('executorId')">
  67. <template #input v-if="vantFormVal.executorIdName && vantFormVal.executorIdName.length > 0">
  68. <TranslationComponent :openId="vantFormVal.executorIdName" />
  69. </template>
  70. </van-field>
  71. <van-field name="isRepeat" label="重复提醒" class="resetStyles">
  72. <template #input>
  73. <van-switch v-model="vantFormVal.isRepeat" size="small" />
  74. </template>
  75. </van-field>
  76. <!-- 重复提醒 -->
  77. <template v-if="vantFormVal.isRepeat">
  78. <van-field v-model="vantFormVal.repeatType" name="repeatType" label="重复类型" placeholder="请选择" is-link readonly
  79. class="resetStyles" @click="showSelectionBox('repeatType', fixedFieldRepetitiveType)">
  80. <template #input v-if="vantFormVal.repeatType">
  81. {{ vantFormVal.repeatTypeName }}
  82. </template>
  83. </van-field>
  84. <template v-if="[0, 1, 2, 3, '0', '1', '2', '3'].includes(vantFormVal.repeatType)">
  85. <van-field v-model="vantFormVal.repeatDesignSameday" type="digit" name="repeatDesignSameday" label="每"
  86. class="resetStyles" v-if="vantFormVal.repeatType == 3">
  87. <template #input>
  88. <van-stepper v-model="vantFormVal.repeatDesignSameday" :min="0" button-size="1.2rem" theme="round"
  89. integer class="mr-2" />
  90. </template>
  91. <template #extra> 天 </template>
  92. </van-field>
  93. <van-field name="endType" label="结束" class="resetStyles">
  94. <template #input>
  95. <van-radio-group v-model="vantFormVal.endType" direction="horizontal" class="flex flex-col"
  96. @change="radiogroupChange">
  97. <van-radio name="1"><span
  98. :class="vantFormVal.endType == 1 ? 'themeTextColor' : ''">永不</span></van-radio>
  99. <van-radio name="2" class="mt-3">
  100. <van-stepper v-model="vantFormVal.repeatEndCount" :disabled="vantFormVal.endType != 2" :min="0"
  101. button-size="1.2rem" theme="round" integer class="mr-2" />
  102. 次数以后
  103. </van-radio>
  104. <van-radio name="3" class="mt-3">
  105. <div class="flex items-center">
  106. <van-field label="日期" is-link readonly :disabled="vantFormVal.endType != 3" class="selectField"
  107. placeholder="请选择" @click="vantFormVal.endType == 3 && showDatePickerBox('repeatEndDate')">
  108. <template #input v-if="vantFormVal.repeatEndDate">
  109. {{ vantFormVal.repeatEndDate }}
  110. </template>
  111. </van-field>
  112. 以后
  113. </div>
  114. </van-radio>
  115. </van-radio-group>
  116. </template>
  117. </van-field>
  118. </template>
  119. <template v-if="[4, '4'].includes(vantFormVal.repeatType)">
  120. <div class="flex items-center justify-between px-8 pt-3">
  121. <div>自定义日期</div>
  122. <div><van-icon name="add-o" class="ml-2 themeTextColor" size="1.3rem" @click="addCustomeDateItem()" />
  123. </div>
  124. </div>
  125. <van-cell-group inset class="additionalCoAuthorship">
  126. <template v-for="(item, index) in customeDate">
  127. <van-cell :title="`第${index + 1}次重复在`">
  128. <template #default>
  129. <div class="flex items-center justify-end">
  130. <van-stepper v-model="item.value" :min="0" button-size="1.2rem" theme="round" integer
  131. class="mr-2" />
  132. 天后
  133. <van-icon name="delete-o" class="ml-2 text-[red]" size="1.3rem"
  134. @click="deleteCustomeDateItem(index)" />
  135. </div>
  136. </template>
  137. </van-cell>
  138. </template>
  139. </van-cell-group>
  140. </template>
  141. </template>
  142. <van-field label="开始时间" name="startDate" is-link readonly class="resetStyles" placeholder="请选择"
  143. @click="showDatePickerBox('startDate')">
  144. <template #input v-if="vantFormVal.startDate">
  145. {{ vantFormVal.startDate }}
  146. </template>
  147. </van-field>
  148. <van-field label="结束时间" name="endDate" is-link readonly class="resetStyles" placeholder="请选择"
  149. @click="showDatePickerBox('endDate')">
  150. <template #input v-if="vantFormVal.endDate">
  151. {{ vantFormVal.endDate }}
  152. </template>
  153. </van-field>
  154. <div></div>
  155. </van-form>
  156. <CustomerForm ref="formFormRef" :formJson="formJson" :formValue="formVal"></CustomerForm>
  157. </div>
  158. <div class="mar-20px ">
  159. <van-button type="primary" @click="onSubmit" class="w-full">
  160. {{ Object.keys(formVal).length > 0 ? '确定修改' : '确定添加' }}
  161. </van-button>
  162. </div>
  163. <!-- 选择器 -->
  164. <div>
  165. <!-- 下拉框选择 -->
  166. <van-popup v-model:show="showSelectionFlag" destroy-on-close position="bottom" :style="{ height: '80%' }">
  167. <PullDownSelector :show-element="showSelectionFlag" :options="showSelectionArray" :doYouNeedTranslation="false" @change="selectChange" />
  168. </van-popup>
  169. <van-popup v-model:show="showSelectionToFlag" destroy-on-close position="bottom" :style="{ height: '80%' }">
  170. <PullDownSelector :show-element="showSelectionToFlag" :value="showSelectionToValue" @change="selectChange" :multiple-choice="true" />
  171. </van-popup>
  172. <!-- 选择日期 -->
  173. <van-popup v-model:show="showDatePicker" destroy-on-close position="bottom" :style="{ height: '50%' }">
  174. <van-date-picker v-model="showDatePickerVal" @confirm="showPickerConfirm" @cancel="showDatePicker = false" />
  175. </van-popup>
  176. </div>
  177. </div>
  178. </template>
  179. <script setup>
  180. import { ref, onActivated, computed } from 'vue';
  181. import { useLifecycle } from '@hooks/useCommon.js';
  182. import { fixedFieldTaskType, fixedFieldPriority, fixedFieldRepetitiveType } from '@utility/defaultData.js';
  183. import { GET_ALL_CUSTOMERSLIST, GET_ALL_BUSINESS_OPPORTUNITIES, GET_SALES_ORDER_LIST, GET_OBTAIN_ALL_CLUES, GET_CONTACTS_WITH_MORE_I_DS, TASK_ADD_EDIT, MODIFY_TASK } from "@hooks/useApi";
  184. import requests from "@common/requests";
  185. import useToast from "@hooks/useToast"
  186. import dayjs from 'dayjs';
  187. import PullDownSelector from '@components/common/pullDownSelector.vue'
  188. import CustomerForm from '@components/common/formForm/formView.vue'
  189. import TranslationComponent from '@components/common/translationComponent.vue';
  190. import useRouterStore from "@store/useRouterStore.js";
  191. import commonUtil from "@utility/commonUtil"
  192. const router = useRouterStore()
  193. const { toastText, toastSuccess, toastFail, toastLoading } = useToast()
  194. const props = defineProps({
  195. formJson: { required: true },
  196. formValue: { required: true },
  197. });
  198. const formFormRef = ref(null)
  199. const vantFormVal = ref({
  200. taskType: 0,
  201. taskTypeName: '客户',
  202. endType: '1',
  203. repeatEndCount: 0,
  204. repeatType: 0,
  205. repeatTypeName: '每天'
  206. })
  207. const formVal = ref({})
  208. const allBusinessOpportunities = ref([])
  209. const allCustomersList = ref([])
  210. const allCluesList = ref([])
  211. const allSalesOrdersList = ref([])
  212. const allContactsList = ref([])
  213. const showSelectionFlag = ref(false)
  214. const showSelectionFiled = ref([])
  215. const showSelectionArray = ref([])
  216. const showDatePicker = ref(false)
  217. const showDatePickerVal = ref(dayjs().format("YYYY-MM-DD").split("-"))
  218. const showDatePickerFiled = ref('')
  219. const customeDate = ref([])
  220. const showSelectionToFlag = ref(false)
  221. const showSelectionToValue = ref([])
  222. const taskTypeFiled = ['customId', 'businessOpportunityId', 'orderId', 'clueId']
  223. const contactDisabled = computed(() => {
  224. const taskType = vantFormVal.value?.taskType
  225. if (!taskType && taskType != 0) {
  226. return true
  227. }
  228. if (taskType == 0 && !vantFormVal.value.customId) {
  229. return true
  230. }
  231. if (taskType == 1 && !vantFormVal.value.businessOpportunityId) {
  232. return true
  233. }
  234. if (taskType == 2 && !vantFormVal.value.orderId) {
  235. return true
  236. }
  237. return false
  238. })
  239. function onSubmit() {
  240. formFormRef.value.getJsonData().then((res) => {
  241. const formValue = {
  242. ...formVal.value,
  243. ...vantFormVal.value,
  244. ...res.data,
  245. repeatDesignDay: customeDate.value.map(item => item.value).join(','),
  246. executorId: vantFormVal.value.executorId,
  247. isRepeat: vantFormVal.value.isRepeat ? 1 : 0
  248. }
  249. console.log('formValue', formValue)
  250. toastLoading('保存中')
  251. const url = formValue.id ? MODIFY_TASK : TASK_ADD_EDIT
  252. requests.post(url, { ...commonUtil.getFromValue({ ...formValue }) }).then(() => {
  253. toastSuccess('保存成功')
  254. setTimeout(() => {
  255. router.navigateBack({
  256. success: () => {
  257. router.eventEmit('moduleListRefreshData', {})
  258. }
  259. })
  260. }, 2000)
  261. }).finally(() => {
  262. })
  263. })
  264. }
  265. function showPickerConfirm({ selectedValues }) {
  266. vantFormVal.value[showDatePickerFiled.value] = selectedValues.join('-')
  267. showDatePicker.value = false
  268. }
  269. function showDatePickerBox(filed) {
  270. const dateVal = vantFormVal.value[filed] ? vantFormVal.value[filed] : dayjs().format("YYYY-MM-DD")
  271. showDatePickerFiled.value = filed
  272. showDatePickerVal.value = dateVal.split("-")
  273. showDatePicker.value = true
  274. }
  275. function selectChange(value, label) {
  276. console.log(value, label)
  277. if (taskTypeFiled.includes(showSelectionFiled.value)) {
  278. const item = fixedFieldTaskType.find(item => item.value == vantFormVal.value.taskType)
  279. console.log(item, value,)
  280. if (item && item.show) {
  281. getContactData(showSelectionFiled.value, value)
  282. }
  283. }
  284. if (showSelectionFiled.value == 'repeatType') {
  285. vantFormVal.value = {
  286. ...vantFormVal.value,
  287. endType: 0,
  288. repeatEndCount: 0,
  289. repeatEndDate: null
  290. }
  291. customeDate.value = []
  292. }
  293. vantFormVal.value[showSelectionFiled.value] = Array.isArray(value) ? value.join(',') : value
  294. vantFormVal.value[`${showSelectionFiled.value}Name`] = label
  295. showSelectionFlag.value = false
  296. showSelectionToFlag.value = false
  297. }
  298. function showSelectionToBox(filed) {
  299. showSelectionFiled.value = filed
  300. showSelectionToValue.value = vantFormVal.value[filed] || []
  301. showSelectionToFlag.value = true
  302. }
  303. function showSelectionBox(filed, list = [], event) {
  304. if (taskTypeFiled.includes(filed)) {
  305. const fileds = taskTypeFiled.filter(item => item !== filed)
  306. fileds.forEach(item => {
  307. vantFormVal.value[item] = ''
  308. vantFormVal.value[`${item}Name`] = ''
  309. })
  310. vantFormVal.value.contactsId = ''
  311. vantFormVal.value[`contactsIdName`] = ''
  312. }
  313. showSelectionFiled.value = filed
  314. showSelectionArray.value = filed == 'executorId' ? [] : list
  315. showSelectionFlag.value = true
  316. }
  317. function addCustomeDateItem() {
  318. customeDate.value.push({ value: null })
  319. }
  320. function deleteCustomeDateItem(index) {
  321. customeDate.value.splice(index, 1)
  322. }
  323. function radiogroupChange(val) {
  324. switch (val) {
  325. case 1:
  326. vantFormVal.value.repeatEndDate = ''
  327. vantFormVal.value.repeatEndCount = null
  328. break;
  329. case 2:
  330. vantFormVal.value.repeatEndDate = ''
  331. break;
  332. case 3:
  333. vantFormVal.value.repeatEndCount = null
  334. break;
  335. default:
  336. break;
  337. }
  338. }
  339. function getContactData(filed, value) {
  340. const urlType = {
  341. 'customId': 'customerId',
  342. 'businessOpportunityId': 'businessId',
  343. 'orderId': 'salesId',
  344. }
  345. const url = `${GET_CONTACTS_WITH_MORE_I_DS}?${urlType[filed]}=${value}`
  346. requests.get(url).then(({ data = [] }) => {
  347. let list = data.map(item => {
  348. return {
  349. label: item.name,
  350. value: item.id,
  351. }
  352. })
  353. if (!list.length) {
  354. list = [{}]
  355. }
  356. allContactsList.value = list
  357. })
  358. }
  359. function getAllListData() {
  360. requests.post(GET_ALL_CUSTOMERSLIST, {}).then(res => {
  361. allCustomersList.value = res.data.map(item => {
  362. return {
  363. label: item.customName,
  364. value: item.id,
  365. }
  366. })
  367. })
  368. requests.post(GET_ALL_BUSINESS_OPPORTUNITIES, {}).then(res => {
  369. allBusinessOpportunities.value = res.data.map(item => {
  370. return {
  371. label: item.name,
  372. value: item.id,
  373. }
  374. })
  375. })
  376. requests.post(GET_SALES_ORDER_LIST, { pageIndex: -1, pageSize: -1 }).then(({ data }) => {
  377. allSalesOrdersList.value = (data.record || []).map(item => {
  378. return {
  379. label: item.orderName,
  380. value: item.id,
  381. }
  382. })
  383. })
  384. requests.post(GET_OBTAIN_ALL_CLUES, {}).then(res => {
  385. allCluesList.value = res.data.map(item => {
  386. return {
  387. label: item.clueName,
  388. value: item.id,
  389. }
  390. })
  391. })
  392. }
  393. function initializeData() {
  394. const row = props.formValue
  395. if (!row.id) {
  396. vantFormVal.value = {
  397. taskType: 0,
  398. taskTypeName: '客户',
  399. endType: '1',
  400. repeatEndCount: 0,
  401. repeatType: 0,
  402. repeatTypeName: '每天'
  403. }
  404. formVal.value = props.formValue
  405. customeDate.value = []
  406. return
  407. }
  408. const { id, taskName, priority, taskType, customId, customName, businessOpportunityId, businessOpportunityName, orderId, orderName, clueId, clueNme, contactsId, contactsName
  409. , taskExecutors, isRepeat, repeatType, repeatDesignSameday, endType, repeatEndCount, repeatEndDate, repeatDesignDay, executorId, startDate, endDate } = row
  410. vantFormVal.value = {
  411. id, taskName, priority, taskType, customId, businessOpportunityId, orderId, clueId, contactsId, executorId, repeatType, repeatDesignSameday, endType, repeatEndCount, repeatEndDate, startDate, endDate,
  412. isRepeat: isRepeat == 1 ? true : false,
  413. executorIdName: taskExecutors || [],
  414. contactsIdName: contactsName,
  415. clueIdNme: clueNme,
  416. orderIdName: orderName,
  417. customIdName: customName,
  418. businessOpportunityIdName: businessOpportunityName,
  419. priorityName: fixedFieldPriority.find(item => item.value == priority)?.label || '',
  420. taskTypeName: fixedFieldTaskType.find(item => item.value == taskType)?.label || '',
  421. repeatTypeName: fixedFieldRepetitiveType.find(item => item.value == repeatType)?.label || ''
  422. }
  423. const list = repeatDesignDay && repeatDesignDay.split(',') || []
  424. customeDate.value = (list || []).map(item => {
  425. return {
  426. value: item
  427. }
  428. })
  429. formVal.value = props.formValue
  430. if ((taskType || taskType == 0) && taskType != 3) {
  431. const filed = taskType == 0 ? 'customId' : taskType == 1 ? 'businessOpportunityId' : taskType == 2 ? 'orderId' : 'clueId'
  432. const value = taskType == 0 ? customId : taskType == 1 ? businessOpportunityId : taskType == 2 ? orderId : clueId
  433. if (value) {
  434. getContactData(filed, value)
  435. }
  436. }
  437. }
  438. useLifecycle({
  439. load: () => {
  440. initializeData()
  441. getAllListData()
  442. },
  443. init: () => {
  444. initializeData()
  445. getAllListData()
  446. }
  447. });
  448. onActivated(() => {
  449. })
  450. </script>
  451. <style lang='scss' scoped>
  452. .selectField {
  453. padding: 0;
  454. width: 12rem;
  455. margin-right: 4px;
  456. }
  457. .selectField :deep(.van-cell__title) {
  458. width: 4rem;
  459. }
  460. .additionalCoAuthorship {
  461. border-bottom: 1px solid #EBEDF0
  462. }
  463. </style>