accessoryAdd.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back"
  4. :title="title" @clickLeft="back">
  5. </uni-nav-bar>
  6. <u-subsection :list="list" :current="current" @change="sectionChange"></u-subsection>
  7. <u-cell-group v-show="current == 0">
  8. <u-cell title="编码" arrow-direction="down">
  9. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  10. <u--input disabled style="flex:1" border="surround" v-model="form.code">
  11. </u--input>
  12. </view>
  13. </u-cell>
  14. <u-cell title="工单名称" arrow-direction="down">
  15. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  16. <u--input :disabled="!isDisable" @click.native="selectWorkOrder" style="flex:1" border="surround"
  17. v-model="form.name">
  18. </u--input>
  19. </view>
  20. </u-cell>
  21. <u-cell title="领用部门" arrow-direction="down">
  22. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  23. <u--input disabled style="flex:1" border="surround" v-model="form.receivingDeptName">
  24. </u--input>
  25. </view>
  26. </u-cell>
  27. <u-cell title="领用人" arrow-direction="down">
  28. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  29. <u--input disabled style="flex:1" border="surround" v-model="form.recipientName">
  30. </u--input>
  31. </view>
  32. </u-cell>
  33. <u-cell title="使用部门" arrow-direction="down">
  34. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  35. <u--input @click.native="classification" :disabled="!isDisable" style="flex:1" border="surround"
  36. placeholder="请选择使用部门" v-model="form.useDeptName">
  37. </u--input>
  38. </view>
  39. </u-cell>
  40. <u-cell title="使用人" arrow-direction="down">
  41. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  42. <u--input :disabled="!isDisable" style="flex:1" border="surround" v-model="form.userName"
  43. placeholder="请选择使用人" @click.native="openSelector">
  44. </u--input>
  45. </view>
  46. </u-cell>
  47. <u-cell title="使用时间" arrow-direction="down">
  48. <uni-datetime-picker :disabled="!isDisable" type="date" slot="value" v-model="form.usageTime">
  49. </uni-datetime-picker>
  50. </u-cell>
  51. <u-cell title="用途" arrow-direction="down">
  52. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  53. <u--textarea style="flex:1" border="surround" placeholder="请输入内容"
  54. v-model="form.purpose"></u--textarea>
  55. </view>
  56. </u-cell>
  57. </u-cell-group>
  58. <accessoryList ref="accessoryRef" v-show="current == 1" />
  59. <view class="footerButton" v-if="isDisable">
  60. <u-button type="default" text="返回" @click="back"></u-button>
  61. <u-button type="primary" @click="save" text="保存"></u-button>
  62. </view>
  63. <ba-tree-picker ref="treePicker" key="verify" :multiple="false" @select-change="confirm" title="选择部门"
  64. :selectedData="selectedData" :localdata="classificationList" valueKey="id" textKey="name"
  65. childrenKey="children" />
  66. <search-select ref="selector" v-model="form.userId" :data-list="executorList" title="选择使用人"
  67. @change="onClose"></search-select>
  68. <u-toast ref="uToast"></u-toast>
  69. </view>
  70. </template>
  71. <script>
  72. import accessoryList from '@/pages/salesServiceManagement/workOrder/components/accessoryList.vue';
  73. import searchSelect from '../accessory/components/searchSelect.vue';
  74. import {
  75. listOrganizations
  76. } from '@/api/salesServiceManagement/workOrder/index.js';
  77. import {
  78. getUserPage
  79. } from '@/api/common.js';
  80. import {
  81. toTreeData
  82. } from '@/utils/utils.js';
  83. import {
  84. accessorySave,
  85. accessoryUpdate
  86. } from '@/api/salesServiceManagement/accessory/index.js'
  87. export default {
  88. components: {
  89. searchSelect,
  90. accessoryList
  91. },
  92. computed: {
  93. isDisable() {
  94. let flag = this.type != 'view'
  95. return flag;
  96. }
  97. },
  98. data() {
  99. return {
  100. current: 0,
  101. list: ['基本信息', '配件信息'],
  102. title: '',
  103. type: '',
  104. form: {
  105. repairId: '', // 工单Id
  106. name: '', // 工单名称
  107. recipientName: '', // 领用人名称
  108. recipientId: '', // 领用人id
  109. receivingDeptId: '', // 领用人部门Id
  110. receivingDeptName: '', // 领用人部门名称
  111. useDeptId: '', // 使用部门Id
  112. useDeptName: '', // 使用部门名称
  113. userId: '', // 使用人Id
  114. userName: '', // 使用人名称
  115. usageTime: '', // 使用时间
  116. purpose: '' // 用途
  117. },
  118. selectedData: [], // 使用部门绑定值
  119. classificationList: [], // 使用部门数据
  120. executorList: [], // 选择人数据
  121. }
  122. },
  123. onLoad(params) {
  124. this.title = params.type == 'view' ? '配件申请详情' : params.type == 'edit' ? '配件申请修改' : '配件申请新增';
  125. this.type = params.type;
  126. this.getData();
  127. },
  128. created() {
  129. uni.$off('updateWorkData')
  130. uni.$on('updateWorkData', ({
  131. data
  132. }) => {
  133. this.form.name = data.name;
  134. this.form.repairId = data.id;
  135. })
  136. },
  137. methods: {
  138. sectionChange(index) {
  139. this.current = index;
  140. },
  141. getData() {
  142. let userInfo = uni.getStorageSync('userInfo');
  143. this.form.receivingDeptName = userInfo.groupName;
  144. this.form.receivingDeptId = userInfo.groupId;
  145. this.form.recipientName = userInfo.name;
  146. this.form.recipientId = userInfo.roleId[0];
  147. this.getTreeList();
  148. },
  149. // 获取使用部门数据
  150. async getTreeList() {
  151. const data = await listOrganizations({});
  152. let treeList = toTreeData({
  153. data: data || [],
  154. idField: 'id',
  155. parentIdField: 'parentId'
  156. });
  157. this.classificationList = treeList;
  158. },
  159. // 打开部门弹窗
  160. classification() {
  161. this.$refs.treePicker._show();
  162. },
  163. // 使用部门选择
  164. confirm(id, name) {
  165. this.form.useDeptName = name;
  166. this.form.useDeptId = id[0];
  167. this.getUserList(id[0])
  168. },
  169. // 打开使用人弹窗
  170. openSelector() {
  171. this.$refs.selector.open();
  172. },
  173. // 获取使用人数据
  174. async getUserList(id) {
  175. let params = {
  176. pageNum: 1,
  177. size: -1,
  178. groupId: id
  179. }
  180. try {
  181. const res = await getUserPage(params);
  182. let list = res.list && res.list.map((el) => {
  183. return {
  184. text: el.name,
  185. value: el.id
  186. }
  187. })
  188. this.executorList = list;
  189. } catch (error) {
  190. }
  191. },
  192. // 使用人选择
  193. onClose(item) {
  194. this.form.userName = item.text;
  195. console.log(item, 'item')
  196. console.log(this.form, 'form')
  197. },
  198. save() {
  199. uni.redirectTo({
  200. url: '/pages/salesServiceManagement/accessory/index'
  201. });
  202. return
  203. if (!this.form.name) {
  204. this.$refs.uToast.show({
  205. type: "warning",
  206. message: "请选择工单",
  207. })
  208. };
  209. if (!this.form.useDeptName) {
  210. this.$refs.uToast.show({
  211. type: "warning",
  212. message: "请选择使用部门",
  213. })
  214. };
  215. if (!this.form.userName) {
  216. this.$refs.uToast.show({
  217. type: "warning",
  218. message: "请选择使用人",
  219. })
  220. };
  221. let details = this.$refs.accessoryRef.getTabData() || [];
  222. if (details.length == 0) {
  223. this.$refs.uToast.show({
  224. type: "warning",
  225. message: "请添加一条配件信息",
  226. })
  227. this.current = 1;
  228. return
  229. }
  230. let data = {
  231. ...this.form,
  232. details
  233. };
  234. if (data.usageTime) {
  235. data.usageTime = data.usageTime + ' 00:00:00'
  236. }
  237. let api = this.type == 'edit' ? accessoryUpdate : accessorySave;
  238. api(data).then((res) => {
  239. this.$refs.uToast.show({
  240. type: "success",
  241. message: "操作成功",
  242. })
  243. }).catch((err) => {
  244. console.log(err, 'err --')
  245. })
  246. },
  247. selectWorkOrder() {
  248. uni.navigateTo({
  249. url: `/pages/salesServiceManagement/accessory/components/selectWork`
  250. })
  251. console.log('打开工单数据');
  252. }
  253. }
  254. }
  255. </script>
  256. <style scoped lang="scss">
  257. /deep/.u-subsection__item__text {
  258. font-size: 28rpx !important;
  259. }
  260. /deep/.u-cell__body__content {
  261. flex: none;
  262. margin-right: 16rpx;
  263. }
  264. .footerButton {
  265. width: 100%;
  266. height: 84rpx;
  267. display: flex;
  268. position: fixed;
  269. bottom: 0;
  270. z-index: 10;
  271. /deep/.u-button {
  272. height: 100%;
  273. }
  274. >view {
  275. flex: 1;
  276. }
  277. }
  278. .selected-value {
  279. height: 80rpx;
  280. line-height: 80rpx;
  281. padding: 0 20rpx;
  282. border: 1rpx solid #e5e5e5;
  283. border-radius: 8rpx;
  284. font-size: 28rpx;
  285. color: #333;
  286. display: flex;
  287. justify-content: space-between;
  288. align-items: center;
  289. background-color: #fff;
  290. }
  291. </style>