add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar :title="navTitle">
  6. <!-- #ifndef MP-WEIXIN -->
  7. <button
  8. class="button white-btn"
  9. @click="handleSave">
  10. 保存
  11. </button>
  12. <!-- #endif -->
  13. </wk-nav-bar>
  14. <view class="container">
  15. <view class="scroll-content">
  16. <wk-form ref="form" :fields="fieldArr" />
  17. <view class="cell-box">
  18. <view class="cell">
  19. <view class="cell-left">
  20. 关联销售简报
  21. </view>
  22. <view class="cell-right">
  23. <switch
  24. :checked="concatSale"
  25. color="#007AFF"
  26. class="switch-core"
  27. @change="concatSale = !concatSale" />
  28. </view>
  29. </view>
  30. </view>
  31. <view class="cell-box">
  32. <view class="cell" @click="handleAddFile()">
  33. <view class="cell-left">
  34. <image :src="$static('images/icon/clip.png')" class="pic-icon" />
  35. 附件
  36. </view>
  37. <view class="cell-right add-icon">
  38. <text class="wk wk-plus" />
  39. </view>
  40. </view>
  41. <wk-file-content
  42. v-if="fileList.length > 0"
  43. :list="fileList"
  44. show-delete
  45. @delete="deleteFile" />
  46. </view>
  47. <view class="cell-box">
  48. <view class="cell" @click="handleAddFile('img')">
  49. <view class="cell-left">
  50. <image :src="$static('images/icon/image.png')" class="pic-icon" />
  51. 图片
  52. </view>
  53. <view class="cell-right add-icon">
  54. <text class="wk wk-plus" />
  55. </view>
  56. </view>
  57. <wk-image-content
  58. v-if="imgList.length > 0"
  59. :list="imgList"
  60. show-delete
  61. @delete="deleteImg" />
  62. </view>
  63. <view class="cell-box">
  64. <view class="cell" @click="getRelevancePopOptions">
  65. <view class="cell-left">
  66. <image :src="$static('images/icon/relate.png')" class="pic-icon" />
  67. 关联业务
  68. </view>
  69. <view class="cell-right add-icon">
  70. <text class="wk wk-plus" />
  71. </view>
  72. </view>
  73. <relevance-section
  74. v-if="showRelevance"
  75. :is-add="true"
  76. :relevance-data="relevanceData"
  77. @delete="handleDeleteRelevance" />
  78. </view>
  79. </view>
  80. </view>
  81. <!-- #ifdef MP-WEIXIN -->
  82. <view class="footer-btn-group">
  83. <button class="button" @click="handleSave">
  84. 保存
  85. </button>
  86. </view>
  87. <!-- #endif -->
  88. </view>
  89. <uni-popup ref="popup">
  90. <view class="pop-wrapper">
  91. <view
  92. v-for="(item, index) in popOptions"
  93. :key="index"
  94. class="pop-item"
  95. @click.stop="handleSelectOptions(item)">
  96. {{ item.label }}
  97. </view>
  98. </view>
  99. </uni-popup>
  100. </view>
  101. </template>
  102. <script>
  103. import { AddOrUpdate, QueryById } from 'API/oa/journal'
  104. import { FileDeleteById } from 'API/file'
  105. import RelevanceSection from '@/components/base/relevance-section.vue'
  106. import Fields from '@/utils/fields.js'
  107. import WkFile from '@/utils/file.js'
  108. import { guid } from '@/utils/lib.js'
  109. export default {
  110. name: 'AddLog',
  111. components: {
  112. RelevanceSection
  113. },
  114. data() {
  115. return {
  116. id: null,
  117. categoryId: null,
  118. guid: null,
  119. routerQuery: {},
  120. batchId: guid(),
  121. concatSale: true,
  122. popOptions: [],
  123. fileList: [],
  124. imgList: [],
  125. customerList: [],
  126. contactsList: [],
  127. businessList: [],
  128. contractList: [],
  129. }
  130. },
  131. computed: {
  132. navTitle() {
  133. const str1 = this.id ? '编辑' : '写'
  134. const str2 = {
  135. 1: '日报',
  136. 2: '周报',
  137. 3: '月报'
  138. }[this.categoryId] || '日志'
  139. return str1 + str2
  140. },
  141. fieldArr() {
  142. const arr = {
  143. 1: ['今日', '明日'],
  144. 2: ['本周', '下周'],
  145. 3: ['本月', '下月']
  146. }[this.categoryId]
  147. return [
  148. new Fields({
  149. name: arr[0] + '工作内容',
  150. formType: 'textarea',
  151. fieldName: 'content',
  152. value: '',
  153. }),
  154. new Fields({
  155. name: arr[1] + '工作内容',
  156. formType: 'textarea',
  157. fieldName: 'tomorrow',
  158. value: '',
  159. }),
  160. new Fields({
  161. name: '遇到的问题',
  162. formType: 'textarea',
  163. fieldName: 'question',
  164. value: '',
  165. }),
  166. new Fields({
  167. name: '发送给谁',
  168. formType: 'user',
  169. fieldName: 'sendUserIds',
  170. value: '',
  171. })
  172. ]
  173. },
  174. showRelevance() {
  175. return this.customerList.length > 0 ||
  176. this.contactsList.length > 0 ||
  177. this.businessList.length > 0 ||
  178. this.contractList.length > 0
  179. },
  180. relevanceData() {
  181. return {
  182. customerList: this.customerList || [],
  183. contactsList: this.contactsList || [],
  184. businessList: this.businessList || [],
  185. contractList: this.contractList || [],
  186. }
  187. }
  188. },
  189. created() {
  190. this.guid = this.$guid()
  191. },
  192. onUnload() {
  193. getApp().globalData.selectedValBridge = {}
  194. },
  195. onLoad(options) {
  196. this.routerQuery = options || {}
  197. this.id = this.routerQuery.id || null
  198. this.categoryId = Number(this.routerQuery.type) || null
  199. if (![1, 2, 3].includes(this.categoryId)) {
  200. this.categoryId = 1
  201. }
  202. if (this.id) {
  203. this.getDetail()
  204. }
  205. },
  206. methods: {
  207. getDetail() {
  208. QueryById({logId: this.id}).then(response => {
  209. let detailData = response || {}
  210. this.imgList = detailData.img || []
  211. this.fileList = detailData.file || []
  212. this.batchId = detailData.batchId
  213. let keys = ['customerList', 'contactsList', 'businessList', 'contractList']
  214. keys.forEach(key => {
  215. this[key] = detailData[key] || []
  216. })
  217. this.$nextTick(() => {
  218. this.$refs.form.setForm({
  219. content: detailData.content,
  220. tomorrow: detailData.tomorrow,
  221. question: detailData.question,
  222. sendUserIds: detailData.sendUserList || []
  223. })
  224. })
  225. }).catch()
  226. },
  227. /**
  228. * 添加附件/图片
  229. * @param {Object} type
  230. */
  231. handleAddFile(type) {
  232. const params = {}
  233. if (type === 'img') {
  234. params.type = type
  235. }
  236. if (this.batchId) {
  237. params.batchId = this.batchId
  238. }
  239. const fileUpload = new WkFile(params)
  240. fileUpload.choose().then(data => {
  241. console.log('upload res: ', data)
  242. if (type === 'img') {
  243. this.imgList = this.imgList.concat(data)
  244. } else {
  245. this.fileList = this.fileList.concat(data)
  246. }
  247. })
  248. },
  249. /**
  250. * 删除图片
  251. * @param {Number} index
  252. */
  253. deleteImg(index) {
  254. const fileId = this.imgList[index].fileId
  255. this.imgList.splice(index, 1)
  256. FileDeleteById({id: fileId}).then().catch()
  257. },
  258. /**
  259. * 删除附件
  260. * @param {Number} index
  261. */
  262. deleteFile(index) {
  263. const fileId = this.fileList[index].fileId
  264. this.fileList.splice(index, 1)
  265. FileDeleteById({id: fileId}).then().catch()
  266. },
  267. /**
  268. * 弹出选择关联业务
  269. */
  270. getRelevancePopOptions() {
  271. const map = [
  272. { label: '客户', value: 'customer', auth: 'crm.customer.index' },
  273. { label: '联系人', value: 'contacts', auth: 'crm.contacts.index' },
  274. { label: '商机', value: 'business', auth: 'crm.business.index' },
  275. { label: '合同', value: 'contract', auth: 'crm.contract.index' }
  276. ]
  277. this.popOptions = map.filter(o => {
  278. return this.$auth(o.auth)
  279. })
  280. this.$refs.popup.open()
  281. },
  282. /**
  283. * 去选择关联项
  284. * @param {Object} opt
  285. */
  286. handleSelectOptions(opt) {
  287. this.$refs.popup.close()
  288. console.log(opt)
  289. const bridge = getApp().globalData.selectedValBridge
  290. bridge[opt.value] = {
  291. guid: this.guid,
  292. defaultVal: this[`${opt.value}List`] || []
  293. }
  294. if (opt.value !== 'user') {
  295. uni.$on('selected-relevance', this.selectedRelevance)
  296. this.$Router.navigateTo({
  297. url: '/pages_common/selectList/relevance',
  298. query: {
  299. type: opt.value
  300. }
  301. })
  302. } else {
  303. uni.$on('selected-user', this.selectedUser)
  304. this.$Router.navigateTo('/pages_common/selectList/user')
  305. }
  306. },
  307. /**
  308. * 选中关联项
  309. * @param {Object} data
  310. */
  311. selectedRelevance(data) {
  312. if (this.guid === data.guid) {
  313. this[`${data.type}List`] = data.data
  314. }
  315. uni.$off('selected-relevance')
  316. },
  317. /**
  318. * 删除关联项
  319. * @param {string} type
  320. * @param {number} index
  321. */
  322. handleDeleteRelevance(type, index) {
  323. this[`${type}List`].splice(index, 1)
  324. },
  325. handleSave() {
  326. this.$refs.form.getForm().then(form => {
  327. form = form.entity
  328. if (
  329. this.$isEmpty(form.content) &&
  330. this.$isEmpty(form.tomorrow) &&
  331. this.$isEmpty(form.question)
  332. ) {
  333. this.$toast('请填写日志内容')
  334. return
  335. }
  336. form = {
  337. ...form,
  338. categoryId: this.categoryId,
  339. batchId: this.batchId
  340. }
  341. form.customerIds = this.customerList.map(o => o.customerId).join(',') || ''
  342. form.contactsIds = this.contactsList.map(o => o.contactsId).join(',') || ''
  343. form.contractIds = this.contractList.map(o => o.contractId).join(',') || ''
  344. form.businessIds = this.businessList.map(o => o.businessId).join(',') || ''
  345. if (this.concatSale) {
  346. form.getBulletin = 1
  347. }
  348. if (this.id) {
  349. form.logId = this.id
  350. }
  351. console.log('save: ', form)
  352. AddOrUpdate(form).then(() => {
  353. this.$toast(this.id ? '修改成功' : '添加成功')
  354. this.$refreshAndToPrev(this)
  355. }).catch(() => {})
  356. }).catch(() => {})
  357. }
  358. }
  359. }
  360. </script>
  361. <style scoped lang="scss">
  362. .main-container {
  363. .container {
  364. flex: 1;
  365. overflow: hidden;
  366. background-color: white;
  367. padding-bottom: 30rpx;
  368. .scroll-content {
  369. width: 100%;
  370. height: 100%;
  371. overflow: auto;
  372. }
  373. .cell-box {
  374. padding: 15rpx 32rpx;
  375. .cell {
  376. width: 100%;
  377. font-size: 30rpx;
  378. @include left;
  379. .cell-left {
  380. flex: 1;
  381. @include left;
  382. .pic-icon {
  383. width: 38rpx;
  384. height: 38rpx;
  385. margin-right: 15rpx;
  386. }
  387. }
  388. .switch-core {
  389. transform: translateX(10%) scale(0.8);
  390. }
  391. .add-icon {
  392. width: 38rpx;
  393. height: 38rpx;
  394. background-color: #E1E1E1;
  395. border-radius: 50%;
  396. @include center;
  397. .wk {
  398. font-size: $wk-font-mini;
  399. line-height: normal;
  400. color: white;
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
  407. </style>