recycleAdd.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 style="flex:1" border="surround" v-model="form.recycleDeptName">
  17. </u--input>
  18. </view>
  19. </u-cell>
  20. <u-cell title="回收人" arrow-direction="down">
  21. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  22. <u--input disabled style="flex:1" border="surround" v-model="form.recycleName">
  23. </u--input>
  24. </view>
  25. </u-cell>
  26. <u-cell title="工单名称" arrow-direction="down">
  27. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  28. <u--input placeholder="请选择" :disabled="!isDisable" @click.native="selectWorkOrder" style="flex:1"
  29. border="surround" v-model="form.orderWorkName">
  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 disabled style="flex:1" border="surround" v-model="form.orderWorkCode">
  36. </u--input>
  37. </view>
  38. </u-cell>
  39. <u-cell title="客户名称" arrow-direction="down">
  40. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  41. <u--input disabled style="flex:1" border="surround" v-model="form.contactName">
  42. </u--input>
  43. </view>
  44. </u-cell>
  45. <u-cell title="客户编码" arrow-direction="down">
  46. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  47. <u--input disabled style="flex:1" border="surround" v-model="form.contactCode">
  48. </u--input>
  49. </view>
  50. </u-cell>
  51. <u-cell title="设备名称" arrow-direction="down">
  52. <uni-data-picker ellipsis :readonly="!isDisable" v-model="form.demandDetailId" slot="value"
  53. placeholder="请选择" :localdata="deviceList" @change="sourceCodeOnchange">
  54. </uni-data-picker>
  55. </u-cell>
  56. <u-cell title="设备编码" arrow-direction="down">
  57. <view slot="value" style="display: flex;align-items: center;width: 90%;">
  58. <u--input disabled style="flex:1" border="surround" v-model="form.categoryCode">
  59. </u--input>
  60. </view>
  61. </u-cell>
  62. <u-cell title="回收时间" arrow-direction="down">
  63. <uni-datetime-picker :disabled="!isDisable" type="date" slot="value" v-model="form.usageTime">
  64. </uni-datetime-picker>
  65. </u-cell>
  66. <u-cell title="原因" arrow-direction="down">
  67. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  68. <u--textarea style="flex:1; min-height: 160rpx;" border="surround" placeholder="请输入内容"
  69. v-model="form.reason"></u--textarea>
  70. </view>
  71. </u-cell>
  72. </u-cell-group>
  73. <accessoryList :itemList="itemList" ref="accessoryRef" :type="type" v-show="current == 1" />
  74. <view class="footerButton" v-if="isDisable">
  75. <u-button type="default" text="返回" @click="back"></u-button>
  76. <u-button type="primary" @click="save" text="保存"></u-button>
  77. </view>
  78. <u-toast ref="uToast"></u-toast>
  79. </view>
  80. </template>
  81. <script>
  82. import accessoryList from '@/pages/salesServiceManagement/workOrder/components/accessoryList.vue';
  83. import {
  84. recycleDetails,
  85. recycleSave,
  86. recycleUpdate,
  87. getSalesWorkOrderById
  88. } from '@/api/salesServiceManagement/workOrder/index.js'
  89. export default {
  90. components: {
  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. orderWorkName: '', // 工单名称
  108. recycleName: '', // 回收人名称
  109. recycleId: '', // 回收人id
  110. receivingDeptId: '', // 回收人部门Id
  111. recycleDeptName: '', // 回收人部门名称
  112. usageTime: '', // 使用时间
  113. reason: '' ,// 原因
  114. demandDetailId:'', // 设备id
  115. categoryCode:'' ,// 设备编码
  116. categoryName:'', // 设备名称
  117. },
  118. selectedData: [], // 使用部门绑定值
  119. classificationList: [], // 使用部门数据
  120. itemList: [], // 配件信息
  121. deviceList: [], // 设备信息
  122. }
  123. },
  124. onLoad(params) {
  125. this.title = params.type == 'view' ? '配件回收详情' : params.type == 'edit' ? '配件回收修改' : '配件回收新增';
  126. this.type = params.type;
  127. if (params.id) {
  128. this.getDetails(params.id);
  129. } else {
  130. this.getData();
  131. }
  132. },
  133. created() {
  134. uni.$off('updateWorkData')
  135. uni.$on('updateWorkData', ({
  136. data
  137. }) => {
  138. this.changeSelect(data, '')
  139. })
  140. },
  141. methods: {
  142. sectionChange(index) {
  143. this.current = index;
  144. },
  145. async getDetails(id) {
  146. const res = await recycleDetails(id);
  147. for (let key in this.form) {
  148. this.form[key] = res[key];
  149. }
  150. this.form.id = res.id;
  151. this.form.code = res.code;
  152. this.itemList = res.detailList;
  153. this.changeSelect({
  154. id: res.repairId,
  155. name: res.orderWorkName,
  156. code: res.orderWorkCode
  157. },
  158. 1
  159. );
  160. },
  161. getData() {
  162. let userInfo = uni.getStorageSync('userInfo');
  163. this.form.recycleDeptName = userInfo.groupName;
  164. this.form.recycleDeptId = userInfo.groupId;
  165. this.form.recycleName = userInfo.name;
  166. this.form.recycleId = userInfo.roleId[0];
  167. },
  168. sourceCodeOnchange(e) {
  169. const value = e.detail.value;
  170. if (value.length === 0) {
  171. return this.deviceSelect({
  172. text: '',
  173. categoryCode: '',
  174. value: ''
  175. });
  176. }
  177. let id = value[0].value;
  178. let item = this.deviceList.find(item => item.value == id);
  179. this.deviceSelect(item);
  180. },
  181. // 设备名称选择
  182. deviceSelect(item) {
  183. this.form.categoryName = item.text;
  184. this.form.categoryCode = item.categoryCode;
  185. this.form.demandDetailId = item.value;
  186. },
  187. // 确认选择工单
  188. async changeSelect(row, type) {
  189. this.$set(this.form, 'orderWorkName', row.name);
  190. this.$set(this.form, 'orderWorkCode', row.code);
  191. this.form.repairId = row.id; // 工单id
  192. const res = await getSalesWorkOrderById(row.id);
  193. this.$set(this.form, 'contactName', res.afterSalesDemandVO.contactName);
  194. this.$set(this.form, 'contactCode', res.afterSalesDemandVO.contactCode);
  195. let list = res.afterSalesDemandVO.productDetail.map((el) => {
  196. return {
  197. text: el.categoryName,
  198. categoryCode: el.categoryCode,
  199. value: el.id,
  200. };
  201. });
  202. this.deviceList = list;
  203. // type 判断是不是修改/详情进来 是的话不需要初始赋值
  204. if (!type) {
  205. this.$set(this.form, 'categoryName', list[0].text);
  206. this.$set(this.form, 'categoryCode', list[0].categoryCode);
  207. this.$set(this.form, 'demandDetailId', list[0].value);
  208. }
  209. },
  210. // 使用人选择
  211. onClose(item) {
  212. this.form.userName = item.text;
  213. },
  214. save() {
  215. if (!this.form.orderWorkName) {
  216. this.$refs.uToast.show({
  217. type: "warning",
  218. message: "请选择工单",
  219. })
  220. };
  221. if (!this.form.demandDetailId) {
  222. this.$refs.uToast.show({
  223. type: "warning",
  224. message: "请选择设备",
  225. })
  226. };
  227. console.log(this.form, 'this.form 123456')
  228. let detailList = this.$refs.accessoryRef.getTabData() || [];
  229. if (detailList.length == 0) {
  230. this.$refs.uToast.show({
  231. type: "warning",
  232. message: "请添加一条配件信息",
  233. })
  234. this.current = 1;
  235. return
  236. }
  237. let data = {
  238. ...this.form,
  239. detailList
  240. };
  241. if (data.usageTime) {
  242. data.usageTime = data.usageTime + ' 00:00:00'
  243. }
  244. let api = this.type == 'edit' ? recycleUpdate : recycleSave;
  245. api(data).then((res) => {
  246. this.$refs.uToast.show({
  247. type: "success",
  248. message: "操作成功",
  249. })
  250. this.back();
  251. }).catch((err) => {})
  252. },
  253. selectWorkOrder() {
  254. uni.navigateTo({
  255. url: `/pages/salesServiceManagement/accessory/components/selectWork`
  256. })
  257. }
  258. }
  259. }
  260. </script>
  261. <style scoped lang="scss">
  262. /deep/.u-subsection__item__text {
  263. font-size: 28rpx !important;
  264. }
  265. /deep/.u-cell__body__content {
  266. flex: none;
  267. margin-right: 16rpx;
  268. }
  269. .footerButton {
  270. width: 100%;
  271. height: 84rpx;
  272. display: flex;
  273. position: fixed;
  274. bottom: 0;
  275. z-index: 10;
  276. /deep/.u-button {
  277. height: 100%;
  278. }
  279. >view {
  280. flex: 1;
  281. }
  282. }
  283. /deep/ .u-textarea__field {
  284. height: 160rpx !important;
  285. }
  286. .selected-value {
  287. height: 80rpx;
  288. line-height: 80rpx;
  289. padding: 0 20rpx;
  290. border: 1rpx solid #e5e5e5;
  291. border-radius: 8rpx;
  292. font-size: 28rpx;
  293. color: #333;
  294. display: flex;
  295. justify-content: space-between;
  296. align-items: center;
  297. background-color: #fff;
  298. }
  299. // .mainBox {
  300. /deep/.uni-data-tree {
  301. width: calc(100% - 150rpx);
  302. .selected-list {
  303. white-space: nowrap;
  304. /* 禁止文本换行 */
  305. overflow: hidden;
  306. /* 超出部分隐藏 */
  307. text-overflow: ellipsis;
  308. /* 显示省略号 */
  309. }
  310. }
  311. // }
  312. </style>