CRMEditBaseInfo.vue 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. <template>
  2. <div v-loading="loading" class="b-cont">
  3. <div v-if="showSaveButton" class="b-cont__handle">
  4. <el-button @click.native="editCancel">取消</el-button>
  5. <el-button
  6. v-debounce="editConfirm"
  7. type="primary">保存</el-button>
  8. </div>
  9. <sections
  10. v-for="(mainItem, mainIndex) in list"
  11. :key="mainIndex"
  12. :title="mainItem.name"
  13. class="b-cells"
  14. content-height="auto">
  15. <el-form
  16. :model="editForm"
  17. :rules="currentEditRules"
  18. :ref="`editForm${mainIndex}`"
  19. class="el-form--flex"
  20. label-position="left"
  21. label-width="100px">
  22. <el-form-item
  23. v-for="(item, index) in mainItem.list"
  24. v-if="getShowValue(item)"
  25. :key="index"
  26. :prop="item.field"
  27. :class="[{'is-block': isBlockShowField(item)},, `is-${item.form_type}`]">
  28. <span slot="label">
  29. {{ item.name }}
  30. </span>
  31. <template v-if="item.isEdit">
  32. <wk-field
  33. :item="item"
  34. :index="index"
  35. :field-from="editForm"
  36. :ignore-fields="ignoreFields"
  37. @change="formChange"
  38. >
  39. <template slot-scope="{ data, index }">
  40. <el-select
  41. v-if="data.form_type === 'business_status'"
  42. v-model="editForm[data.fieldName]"
  43. style="width: 100%;"
  44. clearable>
  45. <el-option
  46. v-for="(optionItem, index) in getFieldOption(data)"
  47. :key="index"
  48. :label="optionItem.name"
  49. :value="optionItem.value"/>
  50. </el-select>
  51. <el-select
  52. v-if="data.fieldName == 'status'"
  53. v-model="editForm[data.fieldName]"
  54. style="width: 100%;">
  55. <el-option
  56. v-for="item in data.setting"
  57. :key="item.value"
  58. :label="item.name"
  59. :value="item.value"/>
  60. </el-select>
  61. <crm-relative-cell
  62. v-else-if="data.form_type === 'contacts' ||
  63. data.form_type === 'customer' ||
  64. data.form_type === 'contract' ||
  65. data.form_type === 'business'"
  66. :relative-type="data.form_type"
  67. :value="editForm[data.fieldName]"
  68. @value-change="arrayValueChange($event, data)"
  69. />
  70. <xh-prouct-cate
  71. v-else-if="data.form_type === 'category'"
  72. :value="editForm[data.fieldName]"
  73. @value-change="arrayValueChange($event, data)"
  74. />
  75. <el-select
  76. v-if="data.fieldName == 'invoice_type'"
  77. v-model="editForm[data.fieldName]"
  78. style="width: 100%;">
  79. <el-option
  80. v-for="item in invoiceTypeOptions"
  81. :key="item.value"
  82. :label="item.name"
  83. :value="item.value"/>
  84. </el-select>
  85. </template>
  86. </wk-field>
  87. <!-- <el-input
  88. v-if="item.form_type === 'text' ||
  89. item.form_type == 'number' ||
  90. item.form_type == 'floatnumber' ||
  91. item.form_type == 'mobile' ||
  92. item.form_type == 'email' ||
  93. item.form_type == 'textarea'"
  94. v-model="editForm[item.field]"/>
  95. <el-select
  96. v-else-if="item.form_type === 'select' || item.form_type === 'business_status'"
  97. v-model="editForm[item.field]"
  98. style="width: 100%;"
  99. clearable>
  100. <el-option
  101. v-for="(item, index) in getFieldOption(item)"
  102. :key="index"
  103. :label="item.name"
  104. :value="item.value"/>
  105. </el-select>
  106. <el-select
  107. v-else-if="item.form_type === 'checkbox'"
  108. v-model="editForm[item.field]"
  109. multiple
  110. style="width: 100%;"
  111. clearable>
  112. <el-option
  113. v-for="(item, index) in getFieldOption(item)"
  114. :key="index"
  115. :label="item.name"
  116. :value="item.value"/>
  117. </el-select>
  118. <el-date-picker
  119. v-else-if="item.form_type === 'date'"
  120. v-model="editForm[item.field]"
  121. type="date"
  122. clearable
  123. style="width: 100%;"
  124. value-format="yyyy-MM-dd"
  125. />
  126. <el-date-picker
  127. v-else-if="item.form_type === 'datetime'"
  128. v-model="editForm[item.field]"
  129. clearable
  130. style="width: 100%;"
  131. type="datetime"
  132. value-format="yyyy-MM-dd HH:mm:ss"
  133. />
  134. <xh-user-cell
  135. v-else-if="item.form_type === 'user' || item.form_type === 'single_user'"
  136. :value="editForm[item.field]"
  137. :radio="item.form_type === 'single_user'"
  138. @value-change="arrayValueChange($event, item)"
  139. />
  140. <xh-structure-cell
  141. v-else-if="item.form_type === 'structure'"
  142. :value="editForm[item.field]"
  143. :radio="false"
  144. @value-change="arrayValueChange($event, item)"
  145. />
  146. <crm-relative-cell
  147. v-else-if="item.form_type === 'contacts' ||
  148. item.form_type === 'customer' ||
  149. item.form_type === 'contract' ||
  150. item.form_type === 'business'"
  151. :relative-type="item.form_type"
  152. :value="editForm[item.field]"
  153. @value-change="arrayValueChange($event, item)"
  154. />
  155. <xh-files
  156. v-else-if="item.form_type === 'file'"
  157. :value="editForm[item.field]"
  158. @value-change="arrayValueChange($event, item)"
  159. />
  160. <xh-prouct-cate
  161. v-else-if="item.form_type === 'category'"
  162. :value="editForm[item.field]"
  163. @value-change="arrayValueChange($event, item)"
  164. /> -->
  165. </template>
  166. <template v-else>
  167. <!-- <flexbox v-if="item.form_type === 'file'" style="min-height: 40px;">
  168. <file-list-view :list="item.value || []" />
  169. <i v-if="getEditAuth(item)" class="wk wk-edit form-item__edit" @click="editClick(item)" />
  170. </flexbox> -->
  171. <div
  172. v-if="item.form_type === 'map_address'"
  173. :gutter="0"
  174. wrap="wrap">
  175. <div
  176. :span="0.5"
  177. class="b-cell"
  178. @click="checkMapView(item)">
  179. <flexbox
  180. class="b-cell-b">
  181. <div class="b-cell-name">定位</div>
  182. <div
  183. class="b-cell-value"
  184. style="color: #3E84E9;cursor: pointer;">{{ item.value.location }}</div>
  185. </flexbox>
  186. </div>
  187. <div
  188. :span="0.5"
  189. class="b-cell">
  190. <flexbox
  191. class="b-cell-b">
  192. <div class="b-cell-name">区域</div>
  193. <div class="b-cell-value">{{ item.value.address.join() }}</div>
  194. </flexbox>
  195. </div>
  196. <div
  197. :span="0.5"
  198. class="b-cell">
  199. <flexbox
  200. class="b-cell-b">
  201. <div class="b-cell-name">详细地址</div>
  202. <div class="b-cell-value">{{ item.value.detail_address }}</div>
  203. </flexbox>
  204. </div>
  205. </div>
  206. <flexbox
  207. v-else
  208. :class="{'can-check':isModule(item)}"
  209. align="stretch"
  210. style="width: 100%;"
  211. class="form-item__value">
  212. <wk-field-view
  213. :props="item"
  214. :form_type="item.form_type"
  215. :value="item.value"
  216. :ignore-fields="ignoreFields"
  217. >
  218. <template slot-scope="{ data }">
  219. <span v-if="data.form_type === 'business_type'">{{ detail ? detail.typeName : '' }}</span>
  220. <span v-else-if="data.form_type === 'business_status'">{{ detail ? detail.statusName : '' }}</span>
  221. <span v-else-if="data.form_type === 'category'">{{ detail ? detail.categoryName : '' }}</span>
  222. <span v-else-if="data.form_type === 'receivables_plan'">{{ detail ? detail.planNum : '' }}</span>
  223. <span v-else-if="ignoreFields.includes(data.props.field) && data.props.field === 'status'">{{ getSelectShowValue(data) }}</span>
  224. <span v-else @click="checkModuleDetail(data)">{{ getCommonShowValue(data) }}</span>
  225. </template>
  226. </wk-field-view>
  227. <i v-if="getEditAuth(item)" class="wk wk-edit form-item__edit" @click.stop="editClick(item, index)" />
  228. </flexbox>
  229. </template>
  230. </el-form-item>
  231. </el-form>
  232. </sections>
  233. <slot />
  234. <map-view
  235. v-if="showMapView"
  236. :title="mapViewInfo.title"
  237. :lat="mapViewInfo.lat"
  238. :lng="mapViewInfo.lng"
  239. @hidden="showMapView=false" />
  240. <c-r-m-full-screen-detail
  241. :visible.sync="showFullDetail"
  242. :id="fullDetailId"
  243. :crm-type="fullDetailType"/>
  244. </div>
  245. </template>
  246. <script>
  247. import { filedGetInformationAPI, filedUpdateTableFieldAPI } from '@/api/crm/common'
  248. // import { crmMarketingInformationAPI } from '@/api/crm/marketing'
  249. import {
  250. XhUserCell,
  251. XhStructureCell,
  252. XhFiles,
  253. CrmRelativeCell,
  254. XhProuctCate,
  255. XhBusinessStatus,
  256. XhReceivablesPlan
  257. } from '@/components/CreateCom'
  258. import WkFieldView from '@/components/NewCom/WkForm/WkFieldView'
  259. import WkField from '@/components/NewCom/WkForm/WkField'
  260. import crmTypeModel from '@/views/crm/model/crmTypeModel'
  261. import Sections from '../components/Sections'
  262. import MapView from '@/components/MapView' // 地图详情
  263. import FileListView from '@/components/FileListView'
  264. import CheckStatusMixin from '@/mixins/CheckStatusMixin'
  265. import { separator } from '@/filters/vueNumeralFilter/filters'
  266. import {
  267. objDeepCopy
  268. } from '@/utils'
  269. import { isArray, isObject, isEmpty } from '@/utils/types'
  270. import { mapGetters } from 'vuex'
  271. import { getWkDateTime } from '@/utils'
  272. import { getFormFieldShowName } from '@/components/NewCom/WkForm/utils'
  273. import CustomFieldsMixin from '@/mixins/CustomFields'
  274. export default {
  275. // 客户管理 的 基本信息
  276. name: 'CRMEditBaseInfo',
  277. components: {
  278. Sections,
  279. MapView,
  280. FileListView,
  281. XhUserCell,
  282. XhStructureCell,
  283. XhFiles,
  284. CrmRelativeCell,
  285. XhProuctCate,
  286. XhBusinessStatus,
  287. XhReceivablesPlan,
  288. CRMFullScreenDetail: () => import('@/components/CRMFullScreenDetail'),
  289. WkFieldView,
  290. WkField
  291. },
  292. filters: {
  293. },
  294. mixins: [CheckStatusMixin, CustomFieldsMixin],
  295. props: {
  296. // 模块ID
  297. id: [String, Number],
  298. pool_id: [String, Number],
  299. isSeas: {
  300. type: Boolean,
  301. default: false
  302. },
  303. detail: {
  304. type: Object,
  305. default: () => {
  306. return {}
  307. }
  308. },
  309. // 没有值就是全部类型 有值就是当个类型
  310. crmType: {
  311. type: String,
  312. default: ''
  313. },
  314. // 固定字段的数据
  315. filedList: Array,
  316. // 系统消息之前的数据
  317. otherList: Array,
  318. // 忽略的字段直接输出
  319. ignoreFields: {
  320. type: Array,
  321. default: () => {
  322. return []
  323. }
  324. }
  325. },
  326. data() {
  327. return {
  328. loading: false,
  329. list: [],
  330. // 控制展示地图详情
  331. showMapView: false,
  332. // 地图详情信息
  333. mapViewInfo: {},
  334. showFullDetail: false,
  335. fullDetailId: '',
  336. fullDetailType: '',
  337. // 编辑
  338. showSaveButton: false,
  339. editRules: {},
  340. editForm: {},
  341. allForm: {}, // 用于逻辑表单刷新
  342. currentEditRules: {}, // 当前编辑字段规则
  343. editOptions: {},
  344. editFieldData: [],
  345. invoiceTypeOptions: [{
  346. name: '增值税专用发票',
  347. value: 1
  348. }, {
  349. name: '增值税普通发票',
  350. value: 2
  351. }, {
  352. name: '国税通用机打发票',
  353. value: 3
  354. }, {
  355. name: '地税通用机打发票',
  356. value: 4
  357. }, {
  358. name: '收据',
  359. value: 5
  360. }]
  361. }
  362. },
  363. inject: ['rootTabs'],
  364. computed: {
  365. ...mapGetters(['crm'])
  366. },
  367. watch: {
  368. id(val) {
  369. if (!this.filedList) {
  370. this.getBaseInfo(true)
  371. }
  372. },
  373. filedList() {
  374. this.list = this.filedList
  375. },
  376. 'rootTabs.currentName'(val) {
  377. if (val === 'CRMEditBaseInfo') {
  378. this.getBaseInfo(false)
  379. }
  380. }
  381. },
  382. created() {
  383. this.$bus.on('crm-detail-update', (data) => {
  384. this.getBaseInfo(false)
  385. })
  386. },
  387. beforeDestroy() {
  388. this.$bus.off('crm-detail-update')
  389. },
  390. mounted() {
  391. if (this.filedList) {
  392. this.list = this.filedList
  393. } else {
  394. this.getBaseInfo(true)
  395. }
  396. },
  397. methods: {
  398. /**
  399. * 获取基础信息
  400. */
  401. getBaseInfo(loading) {
  402. this.loading = !!loading
  403. if (this.crmType === 'marketing') {
  404. // crmMarketingInformationAPI().then(res => {
  405. // this.list = res.data || []
  406. // this.loading = false
  407. // }).catch(() => {
  408. // this.loading = false
  409. // })
  410. } else {
  411. const params = {
  412. id: this.id,
  413. types: crmTypeModel[this.crmType],
  414. action_id: this.id,
  415. module: 'crm',
  416. controller: this.crmType,
  417. action: 'read',
  418. system: 1
  419. }
  420. // 如果有公海id 需上传确定展示字段
  421. if (this.pool_id) {
  422. params.pool_id = this.pool_id
  423. }
  424. filedGetInformationAPI(params)
  425. .then(res => {
  426. const baseList = []
  427. const systemList = []
  428. // 编辑用信息
  429. const editFieldData = []
  430. const editRules = {}
  431. res.data.forEach(item => {
  432. if (item.form_type === 'floatnumber') {
  433. item.value = separator(item.value)
  434. } else if (item.form_type === 'date') {
  435. item.value = getWkDateTime(item.value)
  436. }
  437. if (item.system == 1) {
  438. systemList.push(item)
  439. } else if (item.form_type !== 'product') {
  440. baseList.push(item)
  441. }
  442. })
  443. // 逻辑表单逻辑
  444. const assistIds = this.getFormAssistIds([baseList])
  445. baseList.forEach(item => {
  446. this.getFormItemDefaultProperty(item, false)
  447. item.show = !assistIds.includes(item.formAssistId)
  448. if (this.ignoreFields.includes(item.field)) {
  449. // 防止影响普通单选的验证方式 该方法必须在获取值之上
  450. delete item.optionsData
  451. }
  452. const canEdit = this.getItemIsCanEdit(item, 'update')
  453. // 是否能编辑权限
  454. const copyItem = objDeepCopy(item)
  455. if (item.show && canEdit) {
  456. editRules[item.field] = this.getRules(copyItem)
  457. }
  458. // 是否可编辑
  459. item.disabled = !canEdit
  460. // 特殊字段允许多选
  461. this.getItemRadio(item, item)
  462. // 表格为了展示,提前处理为编辑数据
  463. if (item.form_type === 'detail_table') {
  464. if (!isEmpty(item.value)) {
  465. item.value = this.getItemValue(item, null, 'update')
  466. }
  467. this.allForm[item.field] = item.value || null
  468. } else {
  469. // copyItem 避免修改原始item.value
  470. this.allForm[item.field] = this.getItemValue(copyItem, null, 'update')
  471. }
  472. editFieldData.push(item)
  473. })
  474. // 编辑逻辑赋值
  475. this.editFieldData = editFieldData
  476. this.editRules = editRules
  477. if (this.otherList) {
  478. this.list = [
  479. {
  480. name: '基本信息',
  481. list: baseList
  482. },
  483. ...this.otherList,
  484. {
  485. name: '系统信息',
  486. list: systemList
  487. }
  488. ]
  489. } else {
  490. this.list = [
  491. {
  492. name: '基本信息',
  493. list: baseList
  494. },
  495. {
  496. name: '系统信息',
  497. list: systemList
  498. }
  499. ]
  500. }
  501. this.editCancel()
  502. this.loading = false
  503. })
  504. .catch(() => {
  505. this.loading = false
  506. })
  507. }
  508. },
  509. /**
  510. * change
  511. */
  512. formChange(field, index, value, valueList) {
  513. if ([
  514. 'select',
  515. 'checkbox'
  516. ].includes(field.form_type) &&
  517. field.remark === 'options_type' &&
  518. field.optionsData) {
  519. const { fieldForm, fieldRules } = this.getFormContentByOptionsChange([this.editFieldData], { ...this.allForm, ...this.editForm }, this.editRules, null, 'update')
  520. const editForm = {}
  521. const currentEditRules = {}
  522. this.editFieldData.forEach(item => {
  523. // 重新获取当前可编辑字段的值和规则
  524. if (item.show && item.isEdit) {
  525. editForm[item.field] = fieldForm[item.field]
  526. currentEditRules[item.field] = fieldRules[item.field]
  527. }
  528. // 不展示的字段,但处在可编辑状态,置为不能编辑
  529. if (!item.show && item.isEdit) {
  530. item.isEdit = false
  531. }
  532. })
  533. this.editForm = editForm
  534. this.currentEditRules = currentEditRules
  535. }
  536. },
  537. /**
  538. * 查看地图详情
  539. */
  540. checkMapView(item) {
  541. if (item.value && item.value !== '') {
  542. this.mapViewInfo = {
  543. title: item.value.location,
  544. lat: item.value.lat,
  545. lng: item.value.lng
  546. }
  547. this.showMapView = true
  548. }
  549. },
  550. getArrayKey(type) {
  551. if (type === 'structure') {
  552. return 'name'
  553. } else if (type === 'user') {
  554. return 'realname'
  555. }
  556. return ''
  557. },
  558. arrayValue(array, field) {
  559. if (
  560. !array ||
  561. Object.prototype.toString.call(array) !== '[object Array]'
  562. ) {
  563. return ''
  564. }
  565. return array
  566. .map(item => {
  567. return field ? item[field] : item
  568. })
  569. .join(',')
  570. },
  571. /**
  572. * 客户等模块类型
  573. */
  574. isModule(item) {
  575. return [
  576. 'customer',
  577. 'business',
  578. 'contract',
  579. 'contacts'].includes(item.form_type)
  580. },
  581. /**
  582. * 特殊字段
  583. */
  584. isSpecialField(item) {
  585. return [
  586. 'category',
  587. 'statusName',
  588. 'typeName'].includes(item.form_type)
  589. },
  590. /**
  591. * 是整行展示字段
  592. */
  593. isBlockShowField(item) {
  594. return [
  595. 'map_address',
  596. 'file',
  597. 'detail_table'].includes(item.form_type)
  598. },
  599. getShowBlock(type) {
  600. return ['map_address', 'file'].includes(type)
  601. },
  602. getModuleName(item) {
  603. const field = {
  604. customer: 'name',
  605. business: 'name',
  606. contract: 'num',
  607. contacts: 'name',
  608. category: 'name',
  609. statusName: 'name',
  610. typeName: 'name'
  611. }[item.form_type]
  612. return item.value ? item.value.length == 0 ? '' : item.value[0][field] || item.value : ''
  613. },
  614. getFieldOption(item) {
  615. const editData = this.editOptions[item.field]
  616. let setting = []
  617. if (editData) {
  618. if (item.form_type === 'select' || item.form_type === 'checkbox') {
  619. if (editData.setting.length > 0 && typeof editData.setting[0] == 'string') {
  620. setting = editData.setting.map(element => {
  621. return { name: element, value: element }
  622. })
  623. } else {
  624. setting = editData.setting
  625. }
  626. } else if (item.form_type === 'business_status') {
  627. setting = editData.setting.map(element => {
  628. element.value = element.statusId
  629. return element
  630. })
  631. }
  632. }
  633. return setting
  634. },
  635. /**
  636. * 获取非附件类型的展示值
  637. */
  638. getCommonShowValue(item) {
  639. if (this.isModule(item)) {
  640. return this.getModuleName(item)
  641. } else {
  642. const field = item.props
  643. if (field.fieldName === 'invoice_type') {
  644. const dataItem = this.invoiceTypeOptions.find(o => o.value == item.value)
  645. return dataItem ? dataItem.name : ''
  646. }
  647. return getFormFieldShowName(item.form_type, item.value, '', item)
  648. }
  649. },
  650. /**
  651. * 查看详情
  652. */
  653. checkModuleDetail(data) {
  654. const dataValue = data.value
  655. if (this.isModule(data)) {
  656. let id = ''
  657. if (isObject(dataValue)) {
  658. id = dataValue[`${data.form_type}_id`]
  659. } else if (isArray(dataValue) && dataValue.length > 0) {
  660. id = dataValue[0][`${data.form_type}_id`]
  661. }
  662. if (id) {
  663. this.fullDetailType = data.form_type
  664. this.fullDetailId = id
  665. this.showFullDetail = true
  666. }
  667. }
  668. },
  669. /**
  670. * 编辑逻辑
  671. */
  672. getEditAuth(item) {
  673. if (this.isSeas) {
  674. return false
  675. }
  676. if (this.crmType == 'business' && ['business_type', 'business_status'].includes(item.form_type)) {
  677. return false
  678. } else if (this.crmType == 'contract' && ['business', 'contacts', 'customer'].includes(item.form_type)) {
  679. return false
  680. } else if (this.crmType == 'receivables' && ['contract', 'customer'].includes(item.form_type)) {
  681. return false
  682. } else if (this.crmType == 'visit' && ['business', 'contacts', 'customer'].includes(item.form_type)) {
  683. return false
  684. }
  685. // authLevel 1 不能查看不能编辑 2可查看 3 可编辑可查看
  686. return item.writeStatus === 1 && this.crm && this.crm[this.crmType] && this.crm[this.crmType].update // 不能编辑 disabled true
  687. },
  688. /**
  689. * 点击编辑按钮
  690. */
  691. editClick(item) {
  692. let dataValue = objDeepCopy(this.allForm[item.fieldName])
  693. // 明细表格是空时,需要填充一条空数据,展示时未处理。这里增加
  694. if (item.form_type === 'detail_table' && isEmpty(dataValue)) {
  695. dataValue = this.getItemValue(objDeepCopy(item), null, 'update')
  696. }
  697. this.$set(this.editForm, item.fieldName, dataValue)
  698. this.$set(item, 'isEdit', true)
  699. this.$set(this.editOptions, item.fieldName, item)
  700. this.$set(this.currentEditRules, item.fieldName, this.editRules[item.fieldName] || [])
  701. this.showSaveButton = true
  702. },
  703. editCancel() {
  704. if (this.$refs.editForm0[0].clearValidate) {
  705. this.$refs.editForm0[0].clearValidate()
  706. }
  707. this.$nextTick(() => {
  708. // this.list.forEach(bItem => {
  709. // bItem.list.forEach(item => {
  710. // item.isEdit = false
  711. // })
  712. // })
  713. this.editFieldData.forEach(item => {
  714. item.isEdit = false
  715. })
  716. this.editForm = {}
  717. this.editOptions = {}
  718. this.showSaveButton = false
  719. })
  720. },
  721. editConfirm() {
  722. // customerId fieldId fieldType field form_type value
  723. // this.editCancel()
  724. this.$refs.editForm0[0].validate(valid => {
  725. if (valid) {
  726. this.submiteInfo()
  727. }
  728. })
  729. },
  730. /**
  731. * 发请求提交数据
  732. */
  733. submiteInfo() {
  734. // 仅第一块可编辑 ,直接取第一块的数据
  735. this.loading = true
  736. const list = []
  737. for (let index = 0; index < this.editFieldData.length; index++) {
  738. const field = this.editFieldData[index]
  739. // 获取当前编辑 和 隐藏的字段
  740. if (field.form_type !== 'desc_text' && (field.isEdit || !field.show)) {
  741. list.push({
  742. fieldName: field.fieldName,
  743. field: field.field,
  744. field_type: field.field_type,
  745. name: field.name,
  746. type: field.type,
  747. field_id: field.field_id,
  748. value: field.show ? this.getRealParams(field, this.editForm[field.fieldName]) : null
  749. })
  750. }
  751. }
  752. filedUpdateTableFieldAPI({
  753. types: 'crm_' + this.crmType,
  754. action_id: this.id,
  755. list: list.map(item => {
  756. return {
  757. [item.field]: item.value
  758. }
  759. })
  760. }).then(res => {
  761. this.loading = false
  762. this.editCancel()
  763. this.$emit('handle', { type: 'save-success' }) // 刷新数据
  764. // this.refreshData(true)
  765. }).catch(() => {
  766. this.loading = false
  767. })
  768. },
  769. /**
  770. * 员工编辑
  771. * 关联模块编辑
  772. * 附件选择
  773. * 产品类别
  774. */
  775. arrayValueChange(data, item) {
  776. this.editForm[item.field] = data.value || []
  777. },
  778. /**
  779. * 判断展示
  780. */
  781. getShowValue(item) {
  782. if (item.hasOwnProperty('show')) {
  783. return item.show
  784. }
  785. return true
  786. },
  787. /**
  788. * 获取单选值
  789. */
  790. getSelectShowValue(data) {
  791. const field = data.props
  792. const value = data.value
  793. if (value !== null) {
  794. const dataValue = field.setting.find(o => o.value === value)
  795. return dataValue ? dataValue.name : ''
  796. }
  797. return ''
  798. }
  799. }
  800. }
  801. </script>
  802. <style lang="scss" scoped>
  803. .b-cont {
  804. position: relative;
  805. padding: 15px;
  806. height: 100%;
  807. overflow-y: auto;
  808. overflow-y: overlay;
  809. &__handle {
  810. position: absolute;
  811. text-align: right;
  812. right: 20px;
  813. width: 100%;
  814. z-index: 3;
  815. }
  816. }
  817. .section {
  818. margin-top: 0;
  819. /deep/ .content {
  820. overflow: hidden;
  821. }
  822. }
  823. .b-cells + .b-cells {
  824. margin-top: 25px;
  825. }
  826. .b-cell {
  827. padding: 0 10px;
  828. }
  829. .el-form--flex {
  830. margin: 20px 10px 0;
  831. /deep/ .el-form-item {
  832. padding: 0 40px 0 15px;
  833. margin-bottom: 10px;
  834. max-width: 100%;
  835. .el-form-item__content {
  836. position: relative;
  837. min-height: 40px;
  838. }
  839. .el-form-item__label {
  840. color: #777;
  841. font-size: 13px;
  842. line-height: 30px;
  843. }
  844. &:hover {
  845. .form-item__edit{
  846. display: inline;
  847. }
  848. }
  849. &.is-desc_text {
  850. .el-form-item__content {
  851. margin-left: 0 !important;
  852. }
  853. }
  854. }
  855. }
  856. .form-item__value {
  857. font-size: 13px;
  858. color: #333;
  859. line-height: 30px;
  860. white-space: pre-wrap;
  861. word-wrap: break-word;
  862. word-break: break-all;
  863. .wk-field-view {
  864. width: 0;
  865. flex: 1;
  866. }
  867. }
  868. .form-item__edit {
  869. margin-left: 5px;
  870. font-size: 14px;
  871. color: #999;
  872. cursor: pointer;
  873. display: none;
  874. flex-shrink: 0;
  875. &:hover {
  876. color: $xr-color-primary;
  877. }
  878. }
  879. .can-check {
  880. color: $xr-color-primary !important;
  881. cursor: pointer;
  882. }
  883. .is-block {
  884. flex-basis: 100% !important;
  885. }
  886. .b-cell-b {
  887. width: auto;
  888. .b-cell-name {
  889. width: 100px;
  890. margin-right: 10px;
  891. font-size: 13px;
  892. flex-shrink: 0;
  893. color: #777;
  894. }
  895. .b-cell-value {
  896. font-size: 13px;
  897. color: #333;
  898. line-height: 30px;
  899. white-space: pre-wrap;
  900. word-wrap: break-word;
  901. word-break: break-all;
  902. }
  903. }
  904. </style>