accessoryAdd.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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; min-height: 160rpx;" border="surround" placeholder="请输入内容"
  54. v-model="form.purpose"></u--textarea>
  55. </view>
  56. </u-cell>
  57. </u-cell-group>
  58. <accessoryList :itemList="itemList" ref="accessoryRef" :type="type" 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. accessoryInfo
  87. } from '@/api/salesServiceManagement/accessory/index.js'
  88. export default {
  89. components: {
  90. searchSelect,
  91. accessoryList
  92. },
  93. computed: {
  94. isDisable() {
  95. let flag = this.type != 'view'
  96. return flag;
  97. }
  98. },
  99. data() {
  100. return {
  101. current: 0,
  102. list: ['基本信息', '配件信息'],
  103. title: '',
  104. type: '',
  105. form: {
  106. repairId: '', // 工单Id
  107. name: '', // 工单名称
  108. recipientName: '', // 领用人名称
  109. recipientId: '', // 领用人id
  110. receivingDeptId: '', // 领用人部门Id
  111. receivingDeptName: '', // 领用人部门名称
  112. useDeptId: '', // 使用部门Id
  113. useDeptName: '', // 使用部门名称
  114. userId: '', // 使用人Id
  115. userName: '', // 使用人名称
  116. usageTime: '', // 使用时间
  117. purpose: '' // 用途
  118. },
  119. selectedData: [], // 使用部门绑定值
  120. classificationList: [], // 使用部门数据
  121. executorList: [], // 选择人数据
  122. itemList:[], // 配件信息
  123. }
  124. },
  125. onLoad(params) {
  126. this.title = params.type == 'view' ? '配件申请详情' : params.type == 'edit' ? '配件申请修改' : '配件申请新增';
  127. this.type = params.type;
  128. console.log(params, 'params 参数');
  129. if (params.id) {
  130. console.log(typeof params.id);
  131. this.getDetails(params.id);
  132. } else {
  133. this.getData();
  134. }
  135. },
  136. created() {
  137. uni.$off('updateWorkData')
  138. uni.$on('updateWorkData', ({
  139. data
  140. }) => {
  141. this.form.name = data.name;
  142. this.form.repairId = data.id;
  143. })
  144. },
  145. methods: {
  146. sectionChange(index) {
  147. this.current = index;
  148. },
  149. async getDetails(id) {
  150. const res = await accessoryInfo(id);
  151. for (let key in this.form) {
  152. this.form[key] = res[key];
  153. }
  154. this.form.id = res.id;
  155. this.form.code = res.code;
  156. this.itemList = res.details;
  157. this.getTreeList();
  158. },
  159. getData() {
  160. let userInfo = uni.getStorageSync('userInfo');
  161. this.form.receivingDeptName = userInfo.groupName;
  162. this.form.receivingDeptId = userInfo.groupId;
  163. this.form.recipientName = userInfo.name;
  164. this.form.recipientId = userInfo.roleId[0];
  165. this.getTreeList();
  166. },
  167. // 获取使用部门数据
  168. async getTreeList() {
  169. const data = await listOrganizations({});
  170. let treeList = toTreeData({
  171. data: data || [],
  172. idField: 'id',
  173. parentIdField: 'parentId'
  174. });
  175. this.classificationList = treeList;
  176. },
  177. // 打开部门弹窗
  178. classification() {
  179. this.$refs.treePicker._show();
  180. },
  181. // 使用部门选择
  182. confirm(id, name) {
  183. this.form.useDeptName = name;
  184. this.form.useDeptId = id[0];
  185. this.form.userId = '';
  186. this.form.userName = '';
  187. this.executorList = [];
  188. this.getUserList(id[0]);
  189. this.$refs.selector.clearSearchText();
  190. },
  191. // 打开使用人弹窗
  192. openSelector() {
  193. this.$refs.selector.open();
  194. },
  195. // 获取使用人数据
  196. async getUserList(id) {
  197. let params = {
  198. pageNum: 1,
  199. size: -1,
  200. groupId: id
  201. }
  202. try {
  203. const res = await getUserPage(params);
  204. let list = res.list && res.list.map((el) => {
  205. return {
  206. text: el.name,
  207. value: el.id
  208. }
  209. })
  210. this.executorList = list;
  211. } catch (error) {
  212. this.executorList = [];
  213. }
  214. },
  215. // 使用人选择
  216. onClose(item) {
  217. this.form.userName = item.text;
  218. },
  219. save() {
  220. if (!this.form.name) {
  221. this.$refs.uToast.show({
  222. type: "warning",
  223. message: "请选择工单",
  224. })
  225. };
  226. if (!this.form.useDeptName) {
  227. this.$refs.uToast.show({
  228. type: "warning",
  229. message: "请选择使用部门",
  230. })
  231. };
  232. if (!this.form.userName) {
  233. this.$refs.uToast.show({
  234. type: "warning",
  235. message: "请选择使用人",
  236. })
  237. };
  238. let details = this.$refs.accessoryRef.getTabData() || [];
  239. if (details.length == 0) {
  240. this.$refs.uToast.show({
  241. type: "warning",
  242. message: "请添加一条配件信息",
  243. })
  244. this.current = 1;
  245. return
  246. }
  247. let data = {
  248. ...this.form,
  249. details
  250. };
  251. if (data.usageTime) {
  252. data.usageTime = data.usageTime + ' 00:00:00'
  253. }
  254. let api = this.type == 'edit' ? accessoryUpdate : accessorySave;
  255. api(data).then((res) => {
  256. this.$refs.uToast.show({
  257. type: "success",
  258. message: "操作成功",
  259. })
  260. this.back();
  261. }).catch((err) => {
  262. })
  263. },
  264. selectWorkOrder() {
  265. uni.navigateTo({
  266. url: `/pages/salesServiceManagement/accessory/components/selectWork`
  267. })
  268. }
  269. }
  270. }
  271. </script>
  272. <style scoped lang="scss">
  273. /deep/.u-subsection__item__text {
  274. font-size: 28rpx !important;
  275. }
  276. /deep/.u-cell__body__content {
  277. flex: none;
  278. margin-right: 16rpx;
  279. }
  280. .footerButton {
  281. width: 100%;
  282. height: 84rpx;
  283. display: flex;
  284. position: fixed;
  285. bottom: 0;
  286. z-index: 10;
  287. /deep/.u-button {
  288. height: 100%;
  289. }
  290. >view {
  291. flex: 1;
  292. }
  293. }
  294. /deep/ .u-textarea__field {
  295. height: 160rpx !important;
  296. }
  297. .selected-value {
  298. height: 80rpx;
  299. line-height: 80rpx;
  300. padding: 0 20rpx;
  301. border: 1rpx solid #e5e5e5;
  302. border-radius: 8rpx;
  303. font-size: 28rpx;
  304. color: #333;
  305. display: flex;
  306. justify-content: space-between;
  307. align-items: center;
  308. background-color: #fff;
  309. }
  310. </style>