recycleAdd.vue 9.4 KB

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